From eb2b079e2a138a48c8a9f021c95b01e6492263a0 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Mon, 20 Jul 2015 16:11:15 -0700 Subject: [PATCH] pr fixes --- object_schema.cpp | 3 +-- object_store.cpp | 19 +++++++++---------- object_store_exceptions.cpp | 23 +++++++++++------------ object_store_exceptions.hpp | 4 ++-- shared_realm.cpp | 31 +++++++++++++++---------------- 5 files changed, 38 insertions(+), 42 deletions(-) diff --git a/object_schema.cpp b/object_schema.cpp index d31c15a6..b7fe7991 100644 --- a/object_schema.cpp +++ b/object_schema.cpp @@ -23,7 +23,6 @@ #include using namespace realm; -using namespace std; ObjectSchema::ObjectSchema(Group *group, const std::string &name) : name(name) { TableRef tableRef = ObjectStore::table_for_object_type(group, name); @@ -48,7 +47,7 @@ ObjectSchema::ObjectSchema(Group *group, const std::string &name) : name(name) { realm::TableRef linkTable = table->get_link_target(col); property.object_type = ObjectStore::object_type_for_table_name(linkTable->get_name().data()); } - properties.push_back(move(property)); + properties.push_back(std::move(property)); } primary_key = realm::ObjectStore::get_primary_key_for_object(group, name); diff --git a/object_store.cpp b/object_store.cpp index b27748d3..9fda06e7 100644 --- a/object_store.cpp +++ b/object_store.cpp @@ -27,7 +27,6 @@ #include using namespace realm; -using namespace std; template static inline @@ -65,10 +64,10 @@ const size_t c_primaryKeyPropertyNameColumnIndex = 1; const size_t c_zeroRowIndex = 0; -const string c_object_table_prefix = "class_"; +const std::string c_object_table_prefix = "class_"; const size_t c_object_table_prefix_length = c_object_table_prefix.length(); -const uint64_t ObjectStore::NotVersioned = numeric_limits::max(); +const uint64_t ObjectStore::NotVersioned = std::numeric_limits::max(); bool ObjectStore::has_metadata_tables(Group *group) { return group->get_table(c_primaryKeyTableName) && group->get_table(c_metadataTableName); @@ -142,14 +141,14 @@ void ObjectStore::set_primary_key_for_object(Group *group, StringData object_typ } } -string ObjectStore::object_type_for_table_name(const string &table_name) { +std::string ObjectStore::object_type_for_table_name(const std::string &table_name) { if (table_name.size() >= c_object_table_prefix_length && table_name.compare(0, c_object_table_prefix_length, c_object_table_prefix) == 0) { return table_name.substr(c_object_table_prefix_length, table_name.length() - c_object_table_prefix_length); } - return string(); + return std::string(); } -string ObjectStore::table_name_for_object_type(const string &object_type) { +std::string ObjectStore::table_name_for_object_type(const std::string &object_type) { return c_object_table_prefix + object_type; } @@ -162,7 +161,7 @@ TableRef ObjectStore::table_for_object_type_create_if_needed(Group *group, const } std::vector ObjectStore::validate_object_schema(Group *group, ObjectSchema &target_schema) { - vector exceptions; + std::vector exceptions; ObjectSchema table_schema(group, target_schema.name); // check to see if properties are the same @@ -259,7 +258,7 @@ bool ObjectStore::create_tables(Group *group, ObjectStore::Schema &target_schema bool changed = false; // first pass to create missing tables - vector to_update; + std::vector to_update; for (auto& object_schema : target_schema) { bool created = false; ObjectStore::table_for_object_type_create_if_needed(group, object_schema.name, created); @@ -275,7 +274,7 @@ bool ObjectStore::create_tables(Group *group, ObjectStore::Schema &target_schema for (auto& target_object_schema : to_update) { TableRef table = table_for_object_type(group, target_object_schema->name); ObjectSchema current_schema(group, target_object_schema->name); - vector &target_props = target_object_schema->properties; + std::vector &target_props = target_object_schema->properties; // add missing columns for (auto& target_prop : target_props) { @@ -399,7 +398,7 @@ bool ObjectStore::update_realm_with_schema(Group *group, ObjectStore::Schema ObjectStore::schema_from_group(Group *group) { ObjectStore::Schema schema; for (size_t i = 0; i < group->size(); i++) { - string object_type = object_type_for_table_name(group->get_table_name(i)); + std::string object_type = object_type_for_table_name(group->get_table_name(i)); if (object_type.length()) { schema.emplace_back(group, move(object_type)); } diff --git a/object_store_exceptions.cpp b/object_store_exceptions.cpp index 1c46d341..5f980fb2 100644 --- a/object_store_exceptions.cpp +++ b/object_store_exceptions.cpp @@ -23,7 +23,6 @@ #include using namespace realm; -using namespace std; ObjectStoreException::ObjectStoreException(Kind kind, Info info) : m_kind(kind), m_info(info), m_what(generate_what()) {} @@ -53,18 +52,18 @@ ObjectStoreException::ObjectStoreException(Kind kind, const std::string &object_ } ObjectStoreException::ObjectStoreException(uint64_t old_version, uint64_t new_version) : m_kind(Kind::RealmVersionGreaterThanSchemaVersion) { - m_info[InfoKeyOldVersion] = to_string(old_version); - m_info[InfoKeyNewVersion] = to_string(new_version); + m_info[InfoKeyOldVersion] = std::to_string(old_version); + m_info[InfoKeyNewVersion] = std::to_string(new_version); m_what = generate_what(); } -ObjectStoreException::ObjectStoreException(vector validation_errors, const string &object_type) : +ObjectStoreException::ObjectStoreException(std::vector validation_errors, const std::string &object_type) : m_validation_errors(validation_errors), m_kind(Kind::ObjectStoreValidationFailure) { m_info[InfoKeyObjectType] = object_type; m_what = generate_what(); } -string ObjectStoreException::generate_what() const { +std::string ObjectStoreException::generate_what() const { auto format_string = s_custom_format_strings.find(m_kind); if (format_string != s_custom_format_strings.end()) { return populate_format_string(format_string->second); @@ -72,21 +71,21 @@ string ObjectStoreException::generate_what() const { return populate_format_string(s_default_format_strings.at(m_kind)); } -string ObjectStoreException::validation_errors_string() const { - string errors_string; +std::string ObjectStoreException::validation_errors_string() const { + std::string errors_string; for (auto error : m_validation_errors) { - errors_string += string("\n- ") + error.what(); + errors_string += std::string("\n- ") + error.what(); } return errors_string; } std::string ObjectStoreException::populate_format_string(const std::string & format_string) const { - string out_string, current(format_string); - smatch sm; - regex re("\\{(\\w+)\\}"); + std::string out_string, current(format_string); + std::smatch sm; + std::regex re("\\{(\\w+)\\}"); while(regex_search(current, sm, re)) { out_string += sm.prefix(); - const string &key = sm[1]; + const std::string &key = sm[1]; if (key == "ValidationErrors") { out_string += validation_errors_string(); } diff --git a/object_store_exceptions.hpp b/object_store_exceptions.hpp index b0236f8a..d9ec80c4 100644 --- a/object_store_exceptions.hpp +++ b/object_store_exceptions.hpp @@ -43,8 +43,8 @@ namespace realm { ObjectStoreValidationFailure, // ObjectType, vector }; - typedef const std::string InfoKey; - typedef std::map Info; + using InfoKey = std::string; + using Info = std::map; ObjectStoreException(Kind kind, const std::string &object_type, const Property &prop); diff --git a/shared_realm.cpp b/shared_realm.cpp index 5dd46bdc..d84b49cd 100644 --- a/shared_realm.cpp +++ b/shared_realm.cpp @@ -20,11 +20,10 @@ #include -using namespace std; using namespace realm; RealmCache Realm::s_global_cache; -mutex Realm::s_init_mutex; +std::mutex Realm::s_init_mutex; Realm::Config::Config(const Config& c) : path(c.path), read_only(c.read_only), in_memory(c.in_memory), schema_version(c.schema_version), encryption_key(c.encryption_key), migration_function(c.migration_function) { @@ -33,18 +32,18 @@ Realm::Config::Config(const Config& c) : path(c.path), read_only(c.read_only), i } } -Realm::Realm(Config &config) : m_config(config), m_thread_id(this_thread::get_id()), m_auto_refresh(true), m_in_transaction(false) +Realm::Realm(Config &config) : m_config(config), m_thread_id(std::this_thread::get_id()), m_auto_refresh(true), m_in_transaction(false) { try { if (config.read_only) { - m_read_only_group = make_unique(config.path, config.encryption_key.data(), Group::mode_ReadOnly); + m_read_only_group = std::make_unique(config.path, config.encryption_key.data(), Group::mode_ReadOnly); m_group = m_read_only_group.get(); } else { m_history = realm::make_client_history(config.path, config.encryption_key.data()); SharedGroup::DurabilityLevel durability = config.in_memory ? SharedGroup::durability_MemOnly : SharedGroup::durability_Full; - m_shared_group = make_unique(*m_history, durability, config.encryption_key.data()); + m_shared_group = std::make_unique(*m_history, durability, config.encryption_key.data()); m_group = nullptr; } } @@ -87,12 +86,12 @@ SharedRealm Realm::get_shared_realm(Config &config) realm = SharedRealm(new Realm(config)); // we want to ensure we are only initializing a single realm at a time - lock_guard lock(s_init_mutex); + std::lock_guard lock(s_init_mutex); if (!config.schema) { // get schema from group and skip validation realm->m_config.schema_version = ObjectStore::get_schema_version(realm->read_group()); - realm->m_config.schema = make_unique(ObjectStore::schema_from_group(realm->read_group())); + realm->m_config.schema = std::make_unique(ObjectStore::schema_from_group(realm->read_group())); } else if (config.read_only) { // for read-only validate all existing tables @@ -105,7 +104,7 @@ SharedRealm Realm::get_shared_realm(Config &config) else 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 = make_unique(*existing->m_config.schema); + realm->m_config.schema = std::make_unique(*existing->m_config.schema); } else { // its a non-cached realm so update/migrate if needed @@ -125,7 +124,7 @@ bool Realm::update_schema(ObjectStore::Schema &schema, uint64_t version) commit_transaction(); m_config.schema_version = version; if (m_config.schema.get() != &schema) { - m_config.schema = make_unique(schema); + m_config.schema = std::make_unique(schema); } } catch (...) { @@ -147,7 +146,7 @@ static void check_read_write(Realm *realm) void Realm::verify_thread() { - if (m_thread_id != this_thread::get_id()) { + if (m_thread_id != std::this_thread::get_id()) { throw RealmException(RealmException::Kind::IncorrectThread, "Realm accessed from incorrect thread."); } } @@ -259,7 +258,7 @@ void Realm::notify() } -void Realm::send_local_notifications(const string &type) +void Realm::send_local_notifications(const std::string &type) { verify_thread(); for (NotificationFunction notification : m_notifications) { @@ -297,7 +296,7 @@ bool Realm::refresh() SharedRealm RealmCache::get_realm(const std::string &path, std::thread::id thread_id) { - lock_guard lock(m_mutex); + std::lock_guard lock(m_mutex); auto path_iter = m_cache.find(path); if (path_iter == m_cache.end()) { @@ -314,7 +313,7 @@ SharedRealm RealmCache::get_realm(const std::string &path, std::thread::id threa SharedRealm RealmCache::get_any_realm(const std::string &path) { - lock_guard lock(m_mutex); + std::lock_guard lock(m_mutex); auto path_iter = m_cache.find(path); if (path_iter == m_cache.end()) { @@ -333,7 +332,7 @@ SharedRealm RealmCache::get_any_realm(const std::string &path) void RealmCache::remove(const std::string &path, std::thread::id thread_id) { - lock_guard lock(m_mutex); + std::lock_guard lock(m_mutex); auto path_iter = m_cache.find(path); if (path_iter == m_cache.end()) { @@ -352,11 +351,11 @@ void RealmCache::remove(const std::string &path, std::thread::id thread_id) void RealmCache::cache_realm(SharedRealm &realm, std::thread::id thread_id) { - lock_guard lock(m_mutex); + std::lock_guard lock(m_mutex); auto path_iter = m_cache.find(realm->config().path); if (path_iter == m_cache.end()) { - m_cache.emplace(realm->config().path, map{{thread_id, realm}}); + m_cache.emplace(realm->config().path, std::map{{thread_id, realm}}); } else { path_iter->second.emplace(thread_id, realm);