From ff532b47c4072fe43f29c3f4de3ba3cea9a4cd96 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Mon, 4 Jan 2016 18:13:09 -0800 Subject: [PATCH] bdash pr fixes --- list.hpp | 2 +- object_accessor.hpp | 8 ++-- parser/parser.hpp | 98 ++++++++++++++++++++-------------------- parser/query_builder.cpp | 16 +++---- parser/query_builder.hpp | 86 +++++++++++++++++------------------ results.cpp | 4 +- results.hpp | 8 ++-- 7 files changed, 111 insertions(+), 111 deletions(-) diff --git a/list.hpp b/list.hpp index e7c6465c..0440f003 100644 --- a/list.hpp +++ b/list.hpp @@ -27,7 +27,7 @@ namespace realm { public: List(SharedRealm &r, const ObjectSchema &s, LinkViewRef l) : m_realm(r), m_object_schema(&s), m_link_view(l) {} - const ObjectSchema &object_schema() const { return *m_object_schema; } + const ObjectSchema &get_object_schema() const { return *m_object_schema; } SharedRealm realm() { return m_realm; } size_t size(); diff --git a/object_accessor.hpp b/object_accessor.hpp index dc50240d..bad38f9e 100644 --- a/object_accessor.hpp +++ b/object_accessor.hpp @@ -28,7 +28,7 @@ namespace realm { static inline Object create(ContextType ctx, SharedRealm realm, const ObjectSchema &object_schema, ValueType value, bool try_update); SharedRealm realm() { return m_realm; } - const ObjectSchema &object_schema() { return *m_object_schema; } + const ObjectSchema &get_object_schema() { return *m_object_schema; } Row row() { return m_row; } private: @@ -309,19 +309,19 @@ namespace realm { template void List::add(ContextType ctx, ValueType value) { - add(NativeAccessor::to_object_index(ctx, m_realm, value, object_schema().name, false)); + add(NativeAccessor::to_object_index(ctx, m_realm, value, get_object_schema().name, false)); } template void List::insert(ContextType ctx, ValueType value, size_t list_ndx) { - insert(list_ndx, NativeAccessor::to_object_index(ctx, m_realm, value, object_schema().name, false)); + insert(list_ndx, NativeAccessor::to_object_index(ctx, m_realm, value, get_object_schema().name, false)); } template void List::set(ContextType ctx, ValueType value, size_t list_ndx) { - set(list_ndx, NativeAccessor::to_object_index(ctx, m_realm, value, object_schema().name, false)); + set(list_ndx, NativeAccessor::to_object_index(ctx, m_realm, value, get_object_schema().name, false)); } } diff --git a/parser/parser.hpp b/parser/parser.hpp index bad15381..681847f0 100644 --- a/parser/parser.hpp +++ b/parser/parser.hpp @@ -23,64 +23,64 @@ #include namespace realm { - class Schema; +class Schema; - namespace parser { - struct Expression - { - enum class Type { None, Number, String, KeyPath, Argument, True, False } type = Type::None; - std::string s; - }; +namespace parser { +struct Expression +{ + enum class Type { None, Number, String, KeyPath, Argument, True, False } type = Type::None; + std::string s; +}; - struct Predicate - { - enum class Type - { - Comparison, - Or, - And, - True, - False - } type = Type::And; +struct Predicate +{ + enum class Type + { + Comparison, + Or, + And, + True, + False + } type = Type::And; - enum class Operator - { - None, - Equal, - NotEqual, - LessThan, - LessThanOrEqual, - GreaterThan, - GreaterThanOrEqual, - BeginsWith, - EndsWith, - Contains - }; + enum class Operator + { + None, + Equal, + NotEqual, + LessThan, + LessThanOrEqual, + GreaterThan, + GreaterThanOrEqual, + BeginsWith, + EndsWith, + Contains + }; - struct Comparison - { - Operator op = Operator::None; - Expression expr[2]; - }; + struct Comparison + { + Operator op = Operator::None; + Expression expr[2]; + }; - struct Compound - { - std::vector sub_predicates; - }; + struct Compound + { + std::vector sub_predicates; + }; - Comparison cmpr; - Compound cpnd; + Comparison cmpr; + Compound cpnd; - bool negate = false; + bool negate = false; - Predicate(Type t, bool n = false) : type(t), negate(n) {} - }; + Predicate(Type t, bool n = false) : type(t), negate(n) {} +}; - Predicate parse(const std::string &query); - - void analyzeGrammar(); - bool testGrammar(); - } +Predicate parse(const std::string &query); + +void analyzeGrammar(); +bool testGrammar(); +} } #endif // REALM_PARSER_HPP diff --git a/parser/query_builder.cpp b/parser/query_builder.cpp index 6f74f3b2..e3834ee1 100644 --- a/parser/query_builder.cpp +++ b/parser/query_builder.cpp @@ -230,7 +230,7 @@ void add_binary_constraint_to_query(realm::Query &query, void add_link_constraint_to_query(realm::Query &query, Predicate::Operator op, - PropertyExpression &prop_expr, + const PropertyExpression &prop_expr, size_t row_index) { precondition(prop_expr.indexes.empty(), "KeyPath queries not supported for object comparisons."); switch (op) { @@ -260,12 +260,12 @@ void add_link_constraint_to_query(realm::Query &query, } } -auto link_argument(PropertyExpression &propExpr, parser::Expression &argExpr, Arguments &args) +auto link_argument(const PropertyExpression &propExpr, const parser::Expression &argExpr, Arguments &args) { return args.object_index_for_argument(std::stoi(argExpr.s)); } -auto link_argument(parser::Expression &argExpr, PropertyExpression &propExpr, Arguments &args) +auto link_argument(const parser::Expression &argExpr, const PropertyExpression &propExpr, Arguments &args) { return args.object_index_for_argument(std::stoi(argExpr.s)); } @@ -376,7 +376,7 @@ auto value_of_type_for_query(TableGetter&& tables, Value&& value, Arguments &arg template void do_add_comparison_to_query(Query &query, const Schema &schema, const ObjectSchema &object_schema, Predicate::Operator op, - PropertyExpression &expr, A &lhs, B &rhs, Arguments &args) + const PropertyExpression &expr, A &lhs, B &rhs, Arguments &args) { auto type = expr.prop->type; switch (type) { @@ -418,9 +418,9 @@ void do_add_comparison_to_query(Query &query, const Schema &schema, const Object } } -void add_comparison_to_query(Query &query, Predicate &pred, Arguments &args, const Schema &schema, const std::string &type) +void add_comparison_to_query(Query &query, const Predicate &pred, Arguments &args, const Schema &schema, const std::string &type) { - Predicate::Comparison &cmpr = pred.cmpr; + const Predicate::Comparison &cmpr = pred.cmpr; auto t0 = cmpr.expr[0].type, t1 = cmpr.expr[1].type; auto object_schema = schema.find(type); if (t0 == parser::Expression::Type::KeyPath && t1 != parser::Expression::Type::KeyPath) { @@ -436,7 +436,7 @@ void add_comparison_to_query(Query &query, Predicate &pred, Arguments &args, con } } -void update_query_with_predicate(Query &query, Predicate &pred, Arguments &arguments, const Schema &schema, const std::string &type) +void update_query_with_predicate(Query &query, const Predicate &pred, Arguments &arguments, const Schema &schema, const std::string &type) { if (pred.negate) { query.Not(); @@ -484,7 +484,7 @@ void update_query_with_predicate(Query &query, Predicate &pred, Arguments &argum } } -void apply_predicate(Query &query, Predicate &predicate, Arguments &arguments, const Schema &schema, std::string objectType) +void apply_predicate(Query &query, const Predicate &predicate, Arguments &arguments, const Schema &schema, const std::string &objectType) { update_query_with_predicate(query, predicate, arguments, schema, objectType); diff --git a/parser/query_builder.hpp b/parser/query_builder.hpp index 713ef6ac..e5f519dc 100644 --- a/parser/query_builder.hpp +++ b/parser/query_builder.hpp @@ -24,57 +24,57 @@ #include "object_accessor.hpp" namespace realm { - class Query; - class Schema; +class Query; +class Schema; - namespace query_builder { - class Arguments; +namespace query_builder { +class Arguments; - void apply_predicate(Query &query, parser::Predicate &predicate, Arguments &arguments, const Schema &schema, std::string objectType); +void apply_predicate(Query &query, const parser::Predicate &predicate, Arguments &arguments, const Schema &schema, const std::string &objectType); - class Arguments - { - public: - virtual bool bool_for_argument(size_t argument_index) = 0; - virtual long long long_for_argument(size_t argument_index) = 0; - virtual float float_for_argument(size_t argument_index) = 0; - virtual double double_for_argument(size_t argument_index) = 0; - virtual std::string string_for_argument(size_t argument_index) = 0; - virtual std::string binary_for_argument(size_t argument_index) = 0; - virtual DateTime datetime_for_argument(size_t argument_index) = 0; - virtual size_t object_index_for_argument(size_t argument_index) = 0; - virtual bool is_argument_null(size_t argument_index) = 0; - }; +class Arguments +{ + public: + virtual bool bool_for_argument(size_t argument_index) = 0; + virtual long long long_for_argument(size_t argument_index) = 0; + virtual float float_for_argument(size_t argument_index) = 0; + virtual double double_for_argument(size_t argument_index) = 0; + virtual std::string string_for_argument(size_t argument_index) = 0; + virtual std::string binary_for_argument(size_t argument_index) = 0; + virtual DateTime datetime_for_argument(size_t argument_index) = 0; + virtual size_t object_index_for_argument(size_t argument_index) = 0; + virtual bool is_argument_null(size_t argument_index) = 0; +}; - template - class ArgumentConverter : public Arguments - { - public: - ArgumentConverter(ContextType context, std::vector arguments) : m_arguments(arguments), m_ctx(context) {}; +template +class ArgumentConverter : public Arguments +{ + public: + ArgumentConverter(ContextType context, std::vector arguments) : m_arguments(arguments), m_ctx(context) {}; - using Accessor = realm::NativeAccessor; - virtual bool bool_for_argument(size_t argument_index) { return Accessor::to_bool(m_ctx, argument_at(argument_index)); } - virtual long long long_for_argument(size_t argument_index) { return Accessor::to_long(m_ctx, argument_at(argument_index)); } - virtual float float_for_argument(size_t argument_index) { return Accessor::to_float(m_ctx, argument_at(argument_index)); } - virtual double double_for_argument(size_t argument_index) { return Accessor::to_double(m_ctx, argument_at(argument_index)); } - virtual std::string string_for_argument(size_t argument_index) { return Accessor::to_string(m_ctx, argument_at(argument_index)); } - virtual std::string binary_for_argument(size_t argument_index) { return Accessor::to_binary(m_ctx, argument_at(argument_index)); } - virtual DateTime datetime_for_argument(size_t argument_index) { return Accessor::to_datetime(m_ctx, argument_at(argument_index)); } - virtual size_t object_index_for_argument(size_t argument_index) { return Accessor::to_existing_object_index(m_ctx, argument_at(argument_index)); } - virtual bool is_argument_null(size_t argument_index) { return Accessor::is_null(m_ctx, argument_at(argument_index)); } + using Accessor = realm::NativeAccessor; + virtual bool bool_for_argument(size_t argument_index) { return Accessor::to_bool(m_ctx, argument_at(argument_index)); } + virtual long long long_for_argument(size_t argument_index) { return Accessor::to_long(m_ctx, argument_at(argument_index)); } + virtual float float_for_argument(size_t argument_index) { return Accessor::to_float(m_ctx, argument_at(argument_index)); } + virtual double double_for_argument(size_t argument_index) { return Accessor::to_double(m_ctx, argument_at(argument_index)); } + virtual std::string string_for_argument(size_t argument_index) { return Accessor::to_string(m_ctx, argument_at(argument_index)); } + virtual std::string binary_for_argument(size_t argument_index) { return Accessor::to_binary(m_ctx, argument_at(argument_index)); } + virtual DateTime datetime_for_argument(size_t argument_index) { return Accessor::to_datetime(m_ctx, argument_at(argument_index)); } + virtual size_t object_index_for_argument(size_t argument_index) { return Accessor::to_existing_object_index(m_ctx, argument_at(argument_index)); } + virtual bool is_argument_null(size_t argument_index) { return Accessor::is_null(m_ctx, argument_at(argument_index)); } - private: - std::vector m_arguments; - ContextType m_ctx; + private: + std::vector m_arguments; + ContextType m_ctx; - ValueType &argument_at(size_t index) { - if (index >= m_arguments.size()) { - throw std::out_of_range((std::string)"Argument index " + std::to_string(index) + " out of range 0.." + std::to_string(m_arguments.size()-1)); - } - return m_arguments[index]; - } - }; + ValueType &argument_at(size_t index) { + if (index >= m_arguments.size()) { + throw std::out_of_range((std::string)"Argument index " + std::to_string(index) + " out of range 0.." + std::to_string(m_arguments.size()-1)); + } + return m_arguments[index]; } +}; +} } #endif // REALM_QUERY_BUILDER_HPP diff --git a/results.cpp b/results.cpp index 437cfff7..0839f1f5 100644 --- a/results.cpp +++ b/results.cpp @@ -315,12 +315,12 @@ TableView Results::get_tableview() Results Results::sort(realm::SortOrder&& sort) const { - return Results(m_realm, object_schema(), get_query(), std::move(sort)); + return Results(m_realm, get_object_schema(), get_query(), std::move(sort)); } Results Results::filter(Query&& q) const { - return Results(m_realm, object_schema(), get_query().and_query(std::move(q)), get_sort()); + return Results(m_realm, get_object_schema(), get_query().and_query(std::move(q)), get_sort()); } Results::UnsupportedColumnTypeException::UnsupportedColumnTypeException(size_t column, const Table* table) diff --git a/results.hpp b/results.hpp index 42dbda8f..ec6b7bee 100644 --- a/results.hpp +++ b/results.hpp @@ -46,8 +46,8 @@ public: // or a wrapper around a query and a sort order which creates and updates // the tableview as needed Results() = default; - Results(SharedRealm r, const ObjectSchema &o, Table& table); - Results(SharedRealm r, const ObjectSchema &o, Query q, SortOrder s = {}); + Results(SharedRealm r, const ObjectSchema& o, Table& table); + Results(SharedRealm r, const ObjectSchema& o, Query q, SortOrder s = {}); // Results is copyable and moveable Results(Results const&) = default; @@ -59,7 +59,7 @@ public: SharedRealm get_realm() const { return m_realm; } // Object schema describing the vendored object type - const ObjectSchema &object_schema() const { return *m_object_schema; } + const ObjectSchema &get_object_schema() const { return *m_object_schema; } // Get a query which will match the same rows as is contained in this Results // Returned query will not be valid if the current mode is Empty @@ -72,7 +72,7 @@ public: TableView get_tableview(); // Get the object type which will be returned by get() - StringData get_object_type() const noexcept { return object_schema().name; } + StringData get_object_type() const noexcept { return get_object_schema().name; } // Get the size of this results // Can be either O(1) or O(N) depending on the state of things