From 66fd4ce2f76251c5c67bfadc2056f0d65476f268 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Tue, 8 Dec 2015 12:37:38 -0800 Subject: [PATCH] use gcc --- impl/transact_log_handler.cpp | 2 ++ index_set.hpp | 1 + list.cpp | 2 +- object_store.cpp | 4 ++-- object_store.hpp | 9 +++++++++ parser/query_builder.cpp | 35 +++++++++++++++++++++++------------ parser/query_builder.hpp | 12 +++++++----- results.hpp | 4 ++-- schema.hpp | 1 + shared_realm.cpp | 10 +++++----- shared_realm.hpp | 1 + 11 files changed, 54 insertions(+), 27 deletions(-) diff --git a/impl/transact_log_handler.cpp b/impl/transact_log_handler.cpp index ed1630ca..bd678668 100644 --- a/impl/transact_log_handler.cpp +++ b/impl/transact_log_handler.cpp @@ -293,10 +293,12 @@ public: // Things that just mark the field as modified bool set_int(size_t col, size_t row, int_fast64_t) { return mark_dirty(row, col); } + bool set_int_unique(size_t col, size_t row, int_fast64_t) { return mark_dirty(row, col); } bool set_bool(size_t col, size_t row, bool) { return mark_dirty(row, col); } bool set_float(size_t col, size_t row, float) { return mark_dirty(row, col); } bool set_double(size_t col, size_t row, double) { return mark_dirty(row, col); } bool set_string(size_t col, size_t row, StringData) { return mark_dirty(row, col); } + bool set_string_unique(size_t col, size_t row, StringData) { return mark_dirty(row, col); } bool set_binary(size_t col, size_t row, BinaryData) { return mark_dirty(row, col); } bool set_date_time(size_t col, size_t row, DateTime) { return mark_dirty(row, col); } bool set_table(size_t col, size_t row) { return mark_dirty(row, col); } diff --git a/index_set.hpp b/index_set.hpp index 9cd9257d..9988b10f 100644 --- a/index_set.hpp +++ b/index_set.hpp @@ -21,6 +21,7 @@ #include #include +#include namespace realm { class IndexSet { diff --git a/list.cpp b/list.cpp index fdad3bac..a1229153 100644 --- a/list.cpp +++ b/list.cpp @@ -63,7 +63,7 @@ void List::remove(std::size_t row_ndx) { void List::verify_valid_row(std::size_t row_ndx, bool insertion) { size_t size = m_link_view->size(); if (row_ndx > size || (!insertion && row_ndx == size)) { - throw std::out_of_range(std::string("Index ") + std::to_string(row_ndx) + " is outside of range 0..." + std::to_string(size) + "."); + throw std::out_of_range(std::string("Index ") + to_string(row_ndx) + " is outside of range 0..." + to_string(size) + "."); } } diff --git a/object_store.cpp b/object_store.cpp index 3aed85c5..4eb96930 100644 --- a/object_store.cpp +++ b/object_store.cpp @@ -520,7 +520,7 @@ bool ObjectStore::is_empty(const Group *group) { InvalidSchemaVersionException::InvalidSchemaVersionException(uint64_t old_version, uint64_t new_version) : m_old_version(old_version), m_new_version(new_version) { - m_what = "Provided schema version " + std::to_string(old_version) + " is less than last set version " + std::to_string(new_version) + "."; + m_what = "Provided schema version " + to_string(old_version) + " is less than last set version " + to_string(new_version) + "."; } DuplicatePrimaryKeyValueException::DuplicatePrimaryKeyValueException(std::string const& object_type, Property const& property) : @@ -589,7 +589,7 @@ MismatchedPropertiesException::MismatchedPropertiesException(std::string const& m_what = "Target object type for property '" + old_property.name + "' do not match. Old type '" + old_property.object_type + "', new type '" + new_property.object_type + "'"; } else if (new_property.is_nullable != old_property.is_nullable) { - m_what = "Nullability for property '" + old_property.name + "' has changed from '" + std::to_string(old_property.is_nullable) + "' to '" + std::to_string(new_property.is_nullable) + "'."; + m_what = "Nullability for property '" + old_property.name + "' has changed from '" + to_string(old_property.is_nullable) + "' to '" + to_string(new_property.is_nullable) + "'."; } } diff --git a/object_store.hpp b/object_store.hpp index d41ec3fd..ef9265cd 100644 --- a/object_store.hpp +++ b/object_store.hpp @@ -27,6 +27,8 @@ #include #include +#include + namespace realm { class ObjectSchemaValidationException; class Schema; @@ -233,6 +235,13 @@ namespace realm { private: std::string m_primary_key; }; + + template + std::string to_string(T value) { + std::ostringstream oss; + oss << value; + return oss.str(); + } } #endif /* defined(REALM_OBJECT_STORE_HPP) */ diff --git a/parser/query_builder.cpp b/parser/query_builder.cpp index e3834ee1..9a14bd4e 100644 --- a/parser/query_builder.cpp +++ b/parser/query_builder.cpp @@ -29,6 +29,17 @@ namespace realm { namespace query_builder { using namespace parser; +template +T stot(const std::string s) { + std::istringstream iss(s); + T value; + iss >> value; + if (iss.fail()) { + throw std::invalid_argument("Cannot convert string '" + s + "'"); + } + return value; +} + // check a precondition and throw an exception if it is not met // this should be used iff the condition being false indicates a bug in the caller // of the function checking its preconditions @@ -262,12 +273,12 @@ void add_link_constraint_to_query(realm::Query &query, auto link_argument(const PropertyExpression &propExpr, const parser::Expression &argExpr, Arguments &args) { - return args.object_index_for_argument(std::stoi(argExpr.s)); + return args.object_index_for_argument(stot(argExpr.s)); } auto link_argument(const parser::Expression &argExpr, const PropertyExpression &propExpr, Arguments &args) { - return args.object_index_for_argument(std::stoi(argExpr.s)); + return args.object_index_for_argument(stot(argExpr.s)); } @@ -289,7 +300,7 @@ struct ValueGetter { if (value.type != parser::Expression::Type::Argument) { throw std::runtime_error("You must pass in a date argument to compare"); } - DateTime dt = args.datetime_for_argument(std::stoi(value.s)); + DateTime dt = args.datetime_for_argument(stot(value.s)); return dt.get_datetime(); } }; @@ -299,7 +310,7 @@ struct ValueGetter { static bool convert(TableGetter&&, const parser::Expression & value, Arguments &args) { if (value.type == parser::Expression::Type::Argument) { - return args.bool_for_argument(std::stoi(value.s)); + return args.bool_for_argument(stot(value.s)); } if (value.type != parser::Expression::Type::True && value.type != parser::Expression::Type::False) { throw std::runtime_error("Attempting to compare bool property to a non-bool value"); @@ -313,9 +324,9 @@ struct ValueGetter { static Double convert(TableGetter&&, const parser::Expression & value, Arguments &args) { if (value.type == parser::Expression::Type::Argument) { - return args.double_for_argument(std::stoi(value.s)); + return args.double_for_argument(stot(value.s)); } - return std::stod(value.s); + return stot(value.s); } }; @@ -324,9 +335,9 @@ struct ValueGetter { static Float convert(TableGetter&&, const parser::Expression & value, Arguments &args) { if (value.type == parser::Expression::Type::Argument) { - return args.float_for_argument(std::stoi(value.s)); + return args.float_for_argument(stot(value.s)); } - return std::stof(value.s); + return stot(value.s); } }; @@ -335,9 +346,9 @@ struct ValueGetter { static Int convert(TableGetter&&, const parser::Expression & value, Arguments &args) { if (value.type == parser::Expression::Type::Argument) { - return args.long_for_argument(std::stoi(value.s)); + return args.long_for_argument(stot(value.s)); } - return std::stoll(value.s); + return stot(value.s); } }; @@ -346,7 +357,7 @@ struct ValueGetter { static std::string convert(TableGetter&&, const parser::Expression & value, Arguments &args) { if (value.type == parser::Expression::Type::Argument) { - return args.string_for_argument(std::stoi(value.s)); + return args.string_for_argument(stot(value.s)); } if (value.type != parser::Expression::Type::String) { throw std::runtime_error("Attempting to compare String property to a non-String value"); @@ -360,7 +371,7 @@ struct ValueGetter { static std::string convert(TableGetter&&, const parser::Expression & value, Arguments &args) { if (value.type == parser::Expression::Type::Argument) { - return args.binary_for_argument(std::stoi(value.s)); + return args.binary_for_argument(stot(value.s)); } throw std::runtime_error("Binary properties must be compared against a binary argument."); } diff --git a/parser/query_builder.hpp b/parser/query_builder.hpp index e5f519dc..eac61312 100644 --- a/parser/query_builder.hpp +++ b/parser/query_builder.hpp @@ -67,11 +67,13 @@ class ArgumentConverter : public Arguments 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 " + to_string(index) + " out of range 0.." + to_string(m_arguments.size()-1)); + } + return m_arguments[index]; + } + }; } }; } diff --git a/results.hpp b/results.hpp index ec6b7bee..6b017df1 100644 --- a/results.hpp +++ b/results.hpp @@ -133,8 +133,8 @@ public: struct OutOfBoundsIndexException : public std::out_of_range { OutOfBoundsIndexException(size_t r, size_t c) : requested(r), valid_count(c), - std::out_of_range((std::string)"Requested index " + std::to_string(r) + - " greater than max " + std::to_string(c)) {} + std::out_of_range((std::string)"Requested index " + to_string(r) + + " greater than max " + to_string(c)) {} const size_t requested; const size_t valid_count; }; diff --git a/schema.hpp b/schema.hpp index b8d50777..f03a3668 100644 --- a/schema.hpp +++ b/schema.hpp @@ -21,6 +21,7 @@ #include #include +#include namespace realm { class ObjectSchema; diff --git a/shared_realm.cpp b/shared_realm.cpp index 7806dd2f..380553a9 100644 --- a/shared_realm.cpp +++ b/shared_realm.cpp @@ -47,7 +47,7 @@ Realm::Config::Config(const Config& c) , migration_function(c.migration_function) { if (c.schema) { - schema = std::make_unique(*c.schema); + schema.reset(new Schema(*c.schema)); } } @@ -68,14 +68,14 @@ Realm::Realm(Config config) { try { if (m_config.read_only) { - m_read_only_group = std::make_unique(m_config.path, m_config.encryption_key.data(), Group::mode_ReadOnly); + m_read_only_group.reset(new Group(m_config.path, m_config.encryption_key.data(), Group::mode_ReadOnly)); m_group = m_read_only_group.get(); } else { m_history = realm::make_client_history(m_config.path, m_config.encryption_key.data()); SharedGroup::DurabilityLevel durability = m_config.in_memory ? SharedGroup::durability_MemOnly : SharedGroup::durability_Full; - m_shared_group = std::make_unique(*m_history, durability, m_config.encryption_key.data(), !m_config.disable_format_upgrade); + m_shared_group.reset(new SharedGroup(*m_history, durability, m_config.encryption_key.data())); } } catch (util::File::PermissionDenied const& ex) { @@ -157,7 +157,7 @@ SharedRealm Realm::get_shared_realm(Config config) if (auto existing = s_global_cache.get_any_realm(realm->config().path)) { // if there is an existing realm at the current path steal its schema/column mapping // FIXME - need to validate that schemas match - realm->m_config.schema = std::make_unique(*existing->m_config.schema); + realm->m_config.schema.reset(new Schema(*existing->m_config.schema)); #if __APPLE__ realm->m_notifier = existing->m_notifier; @@ -170,7 +170,7 @@ SharedRealm Realm::get_shared_realm(Config config) #endif // otherwise get the schema from the group - realm->m_config.schema = std::make_unique(ObjectStore::schema_from_group(realm->read_group())); + realm->m_config.schema.reset(new Schema(ObjectStore::schema_from_group(realm->read_group()))); // if a target schema is supplied, verify that it matches or migrate to // it, as neeeded diff --git a/shared_realm.hpp b/shared_realm.hpp index e20f6fbd..394686ce 100644 --- a/shared_realm.hpp +++ b/shared_realm.hpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace realm { class ClientHistory;