From a441190635d494f128cf02e07566ae2003af4e08 Mon Sep 17 00:00:00 2001 From: zxu Date: Tue, 6 Feb 2018 13:51:11 -0500 Subject: Implement Firestore DatabaseInfo and port both Database{Id,Info} C++ to the iOS code (#738) * implement Firestore DatabaseInfo in C++ * temporary stash changes; blocking on the massive renaming of .m to .mm * add database_info_test to project * finish port DatabaseId and fix style, modular fixing DatabaseInfo * port DatabaseInfo * remove FSTDatabase{ID,Info} and their tests from project * fix unit test * use namespace alias * use namespace alias, leftover * address more changes * refactoring to use raw pointer instead of value for property * address changes * remove self-> * fix style * remove the name suffix Alloc * fix a bug --- .../src/firebase/firestore/model/database_id.cc | 4 ---- .../src/firebase/firestore/model/database_id.h | 25 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) (limited to 'Firestore/core/src/firebase/firestore/model') diff --git a/Firestore/core/src/firebase/firestore/model/database_id.cc b/Firestore/core/src/firebase/firestore/model/database_id.cc index af12d30..d7e8a85 100644 --- a/Firestore/core/src/firebase/firestore/model/database_id.cc +++ b/Firestore/core/src/firebase/firestore/model/database_id.cc @@ -31,10 +31,6 @@ DatabaseId::DatabaseId(const absl::string_view project_id, FIREBASE_ASSERT(!database_id.empty()); } -bool DatabaseId::IsDefaultDatabase() { - return database_id_ == kDefaultDatabaseId; -} - } // namespace model } // namespace firestore } // namespace firebase diff --git a/Firestore/core/src/firebase/firestore/model/database_id.h b/Firestore/core/src/firebase/firestore/model/database_id.h index 48c547c..648f982 100644 --- a/Firestore/core/src/firebase/firestore/model/database_id.h +++ b/Firestore/core/src/firebase/firestore/model/database_id.h @@ -17,6 +17,8 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_DATABASE_ID_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_DATABASE_ID_H_ +#include + #include #include "absl/strings/string_view.h" @@ -31,6 +33,12 @@ class DatabaseId { /** The default name for "unset" database ID in resource names. */ static constexpr const char* kDefaultDatabaseId = "(default)"; +#if defined(__OBJC__) + // For objective-c++ initialization; to be removed after migration. + // Do NOT use in C++ code. + DatabaseId() = default; +#endif // defined(__OBJC__) + /** * Creates and returns a new DatabaseId. * @@ -49,13 +57,24 @@ class DatabaseId { } /** Whether this is the default database of the project. */ - bool IsDefaultDatabase(); + bool IsDefaultDatabase() const { + return database_id_ == kDefaultDatabaseId; + } + +#if defined(__OBJC__) + // For objective-c++ hash; to be removed after migration. + // Do NOT use in C++ code. + uint64_t Hash() const { + std::hash hash_fn; + return hash_fn(project_id_) * 31u + hash_fn(database_id_); + } +#endif // defined(__OBJC__) friend bool operator<(const DatabaseId& lhs, const DatabaseId& rhs); private: - const std::string project_id_; - const std::string database_id_; + std::string project_id_; + std::string database_id_; }; /** Compares against another DatabaseId. */ -- cgit v1.2.3