From babf911c56cbaff82d8b0f5f91c6aa8505f8e67d Mon Sep 17 00:00:00 2001 From: Gil Date: Mon, 5 Feb 2018 15:30:07 -0500 Subject: [PATCH] Firestore project: Import of API interfaces. Import of firebase-ios-sdk from Github. - 32266c5d1cf700b37900911860888bb106088220 Make sure Firestore/core/include is in the podspec (#748) by Gil - 070c0ea92fa8bf37bc9e5479aa2e769f796d5de4 Merge pull request #746 from morganchen12/unguarded-block by Morgan Chen - 13f572ea2c57e2cd4c9c2c7c1a7c3b7f338f9fdc Increase expectation timeout to 25 seconds. (#744) by Michael Lehenbauer - 47d81fdf658cc404aeccf0b408d463b8c3538a91 fix (#739) by Chen Liang - 515625c47fab947f82d7f8fc8daef885e56a7df6 Remove predecessorKey,Object,Document, etc (#735) by Gil - ac3052223465ce654457fec17b34f27de1706e57 Start on ArraySortedMap in C++ (#721) by Gil - 729b8d176c75ecc0cbbd137cc6811116a64e310a Move all Firestore Objective-C to Objective-C++ (#734) by Gil - 693d0649bfcc9c32201e2431ae08ea85fdbdb617 Merge pull request #732 from OleksiyA/FCM-subscribe-compl... by Oleksiy Ivanov - 3cbdbf2652202a3473271ed298ff50e5797cce68 Schema migrations for LevelDB (#728) by Greg Soltis - 6474a82fd6e0e10b2cf97c4dc531e837ec97792b Firestore DatabaseId in C++ (#727) by zxu - 05ef5aea13fdc60a6df74212c1bf7976f11b49de Add absl_strings to firebase_firestore_util_test dependen... by rsgowman - 03a006920f8744811358f702102e5685bbe6321b Add changelog entry for my last PR (oops) and also add a ... by Michael Lehenbauer - 5a280ca1d62ac3750bf590328e3d08e0e3342cfc Import iterator_adaptors from google3 (#718) by Gil - 63a380ba33b59b571d7abd7b4565b5e63eb4680d Use fixed-sized types (#719) by Gil - 6dc13731f6510ccb476a95f3af52c3f62763ef6a Version updates to 4.8.2 (#722) by Paul Beusterien - a74d39f02b93c2e7bf121b33ab2164a9ac34e66b Fix a number of c++ build errors (#715) by rsgowman - cceeec3e7b2995d633deda6852cf3b40d07f9247 travis: check for copyright in sources (#717) by Paul Beusterien - 4d7c9733691396503d9abc413cb6c8547ab938c5 Fix b/72502745: OnlineState changes cause limbo document ... by Michael Lehenbauer - af6976a907b0d2a9fadbb14d7258bab44f075364 normalize and port the rest of Firebase/Port code (#713) by zxu - 7226b4adf38e4732dfb9a840d25f86d3e5533bdb port TargetIdGenerator to iOS (#709) by zxu - 53064743963d7e5cc12f7a42bb036814f5a6df17 adding unit test for auto init enable function (#710) by Chen Liang - 821fb909a3007f697ad96d83c6b8e8cc70df0b6b implement `TargetIdGenerator` in C++ for Firestore (#701) by zxu - 5fdda3fa837f3138973d754f05aec7f541f806ce normalize string_util (#708) by zxu - 15a2926dcb986a84cf9969d7d20439d4ac2e46af Update CHANGELOG for M21.1 release (#679) by Ryan Wilson - f0272149c5e74c3e67aa3fb82b096179aa9284d2 Fix incorrect deprecation message (#688) by Iulian Onofrei <6d0847b9@opayq.com> - bfa0e40795ba676fd02d616794cce1c9b2d6a95f Implement the rest of FieldValue types for C++ (#687) by zxu - 1f772120365641eb66f0cc9db9975721c8285d6e Properly publish Abseil sources as a part of the podspec ... by Gil ORIGINAL_AUTHOR=Gil PiperOrigin-RevId: 184568931 --- .../include/firebase/firestore/CMakeLists.txt | 25 -- .../firebase/firestore/document_reference.h | 375 ------------------ .../firebase/firestore/event_listener.h | 53 --- .../include/firebase/firestore/firestore.h | 160 -------- .../firebase/firestore/firestore_errors.h | 115 ------ .../include/firebase/firestore/timestamp.h | 221 ----------- 6 files changed, 949 deletions(-) delete mode 100644 Firestore/core/include/firebase/firestore/CMakeLists.txt delete mode 100644 Firestore/core/include/firebase/firestore/document_reference.h delete mode 100644 Firestore/core/include/firebase/firestore/event_listener.h delete mode 100644 Firestore/core/include/firebase/firestore/firestore.h delete mode 100644 Firestore/core/include/firebase/firestore/firestore_errors.h delete mode 100644 Firestore/core/include/firebase/firestore/timestamp.h diff --git a/Firestore/core/include/firebase/firestore/CMakeLists.txt b/Firestore/core/include/firebase/firestore/CMakeLists.txt deleted file mode 100644 index e4e7acdc5ba5..000000000000 --- a/Firestore/core/include/firebase/firestore/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2018 Google -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Hack to make the headers show up in IDEs -# (see https://stackoverflow.com/questions/27039019/ and open issue on CMake -# issue tracker: https://gitlab.kitware.com/cmake/cmake/issues/15234) -add_custom_target(firebase_firestore_types_ide SOURCES - document_reference.h - event_listener.h - firestore.h - firestore_errors.h - geo_point.h - timestamp.h -) diff --git a/Firestore/core/include/firebase/firestore/document_reference.h b/Firestore/core/include/firebase/firestore/document_reference.h deleted file mode 100644 index d295188b5f6b..000000000000 --- a/Firestore/core/include/firebase/firestore/document_reference.h +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Copyright 2018 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(rsgowman): This file isn't intended to be used just yet. It's just an -// outline of what the API might eventually look like. Most of this was -// shamelessly stolen and modified from RTDB's header file, melded with the -// (java) firestore api. - -#ifndef FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_DOCUMENT_REFERENCE_H_ -#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_DOCUMENT_REFERENCE_H_ - -#include -#include - -#if defined(FIREBASE_USE_STD_FUNCTION) -#include -#endif - -// TODO(rsgowman): Note that RTDB uses: -// #if defined(FIREBASE_USE_MOVE_OPERATORS) || defined(DOXYGEN -// to protect move operators from older compilers. But all our supported -// compilers support this, so we've skipped the #if guard. This TODO comment is -// here so we don't forget to mention this during the API review, and should be -// removed once this note has migrated to the API review doc. - -// TODO(rsgowman): replace these forward decls with appropriate includes (once -// they exist) -namespace firebase { -class App; -template -class Future; -} // namespace firebase - -namespace firebase { -namespace firestore { - -// TODO(rsgowman): replace these forward decls with appropriate includes (once -// they exist) -class FieldValue; -class DocumentSnapshot; -class Firestore; -class Error; -template -class EventListener; -class ListenerRegistration; -class CollectionReference; -class DocumentListenOptions; -// TODO(rsgowman): not quite a forward decl, but required to make the default -// parameter to Set() "compile". -class SetOptions { - public: - SetOptions(); -}; - -// TODO(rsgowman): move this into the FieldValue header -#ifdef STLPORT -using MapFieldValue = std::tr1::unordered_map; -#else -using MapFieldValue = std::unordered_map; -#endif - -/** - * A DocumentReference refers to a document location in a Firestore database and - * can be used to write, read, or listen to the location. There may or may not - * exist a document at the referenced location. A DocumentReference can also be - * used to create a CollectionReference to a subcollection. - * - * Create a DocumentReference via Firebase::Document(const string& path). - * - * Subclassing Note: Firestore classes are not meant to be subclassed except for - * use in test mocks. Subclassing is not supported in production code and new - * SDK releases may break code that does so. - */ -class DocumentReference { - public: - /** - * @brief Default constructor. This creates an invalid DocumentReference. - * Attempting to perform any operations on this reference will fail (and cause - * a crash) unless a valid DocumentReference has been assigned to it. - */ - DocumentReference(); - - /** - * @brief Copy constructor. It's totally okay (and efficient) to copy - * DocumentReference instances, as they simply point to the same location in - * the database. - * - * @param[in] reference DocumentReference to copy from. - */ - DocumentReference(const DocumentReference& reference); - - /** - * @brief Move constructor. Moving is an efficient operation for - * DocumentReference instances. - * - * @param[in] reference DocumentReference to move data from. - */ - DocumentReference(DocumentReference&& reference); - - virtual ~DocumentReference(); - - /** - * @brief Copy assignment operator. It's totally okay (and efficient) to copy - * DocumentReference instances, as they simply point to the same location in - * the database. - * - * @param[in] reference DocumentReference to copy from. - * - * @returns Reference to the destination DocumentReference. - */ - DocumentReference& operator=(const DocumentReference& reference); - - /** - * @brief Move assignment operator. Moving is an efficient operation for - * DocumentReference instances. - * - * @param[in] reference DocumentReference to move data from. - * - * @returns Reference to the destination DocumentReference. - */ - DocumentReference& operator=(DocumentReference&& reference); - - /** - * @brief Returns the Firestore instance associated with this document - * reference. - * - * The pointer will remain valid indefinitely. - * - * @returns Firebase Firestore instance that this DocumentReference refers to. - */ - virtual const Firestore* firestore() const; - - /** - * @brief Returns the Firestore instance associated with this document - * reference. - * - * The pointer will remain valid indefinitely. - * - * @returns Firebase Firestore instance that this DocumentReference refers to. - */ - virtual Firestore* firestore(); - - /** - * @brief Returns the string id of this document location. - * - * The pointer is only valid while the DocumentReference remains in memory. - * - * @returns String id of this document location, which will remain valid in - * memory until the DocumentReference itself goes away. - */ - virtual const char* id() const; - - /** - * @brief Returns the string id of this document location. - * - * @returns String id of this document location. - */ - virtual std::string id_string() const; - - /** - * @brief Returns the path of this document (relative to the root of the - * database) as a slash-separated string. - * - * The pointer is only valid while the DocumentReference remains in memory. - * - * @returns String path of this document location, which will remain valid in - * memory until the DocumentReference itself goes away. - */ - virtual const char* path() const; - - /** - * @brief Returns the path of this document (relative to the root of the - * database) as a slash-separated string. - * - * @returns String path of this document location. - */ - virtual std::string path_string() const; - - /** - * @brief Returns a CollectionReference to the collection that contains this - * document. - */ - virtual CollectionReference get_parent() const; - - /** - * @brief Returns a CollectionReference instance that refers to the - * subcollection at the specified path relative to this document. - * - * @param[in] collection_path A slash-separated relative path to a - * subcollection. The pointer only needs to be valid during this call. - * - * @return The CollectionReference instance. - */ - virtual CollectionReference Collection(const char* collection_path) const; - - /** - * @brief Returns a CollectionReference instance that refers to the - * subcollection at the specified path relative to this document. - * - * @param[in] collection_path A slash-separated relative path to a - * subcollection. - * - * @return The CollectionReference instance. - */ - virtual CollectionReference Collection( - const std::string& collection_path) const; - - /** - * @brief Reads the document referenced by this DocumentReference. - * - * @return A Future that will be resolved with the contents of the Document at - * this DocumentReference. - */ - virtual Future Get() const; - - /** - * @brief Writes to the document referred to by this DocumentReference. - * - * If the document does not yet exist, it will be created. If you pass - * SetOptions, the provided data can be merged into an existing document. - * - * @param[in] data A map of the fields and values for the document. - * @param[in] options An object to configure the set behavior. - * - * @return A Future that will be resolved when the write finishes. - */ - virtual Future Set(const MapFieldValue& data, - const SetOptions& options = SetOptions()); - - /** - * @brief Updates fields in the document referred to by this - * DocumentReference. - * - * If no document exists yet, the update will fail. - * - * @param[in] data A map of field / value pairs to update. Fields can contain - * dots to reference nested fields within the document. - * - * @return A Future that will be resolved when the write finishes. - */ - virtual Future Update(const MapFieldValue& data); - - /** - * @brief Removes the document referred to by this DocumentReference. - * - * @return A Task that will be resolved when the delete completes. - */ - virtual Future Delete(); - - /** - * @brief Starts listening to the document referenced by this - * DocumentReference. - * - * @param[in] listener The event listener that will be called with the - * snapshots, which must remain in memory until you remove the listener from - * this DocumentReference. (Ownership is not transferred; you are responsible - * for making sure that listener is valid as long as this DocumentReference is - * valid and the listener is registered.) - * - * @return A registration object that can be used to remove the listener. - */ - virtual ListenerRegistration AddSnapshotListener( - EventListener* listener); - - /** - * @brief Starts listening to the document referenced by this - * DocumentReference. - * - * @param[in] options The options to use for this listen. - * @param[in] listener The event listener that will be called with the - * snapshots, which must remain in memory until you remove the listener from - * this DocumentReference. (Ownership is not transferred; you are responsible - * for making sure that listener is valid as long as this DocumentReference is - * valid and the listener is registered.) - * - * @return A registration object that can be used to remove the listener. - */ - virtual ListenerRegistration AddSnapshotListener( - const DocumentListenOptions& options, - EventListener* listener); - -#if defined(FIREBASE_USE_STD_FUNCTION) || defined(DOXYGEN) - /** - * @brief Starts listening to the document referenced by this - * DocumentReference. - * - * @param[in] callback function or lambda to call. When this function is - * called, exactly one of the parameters will be non-null. - * - * @return A registration object that can be used to remove the listener. - * - * @note This method is not available when using STLPort on Android, as - * std::function is not supported on STLPort. - */ - virtual ListenerRegistration AddSnapshotListener( - std::function callback); - - /** - * @brief Starts listening to the document referenced by this - * DocumentReference. - * - * @param[in] options The options to use for this listen. - * @param[in] callback function or lambda to call. When this function is - * called, exactly one of the parameters will be non-null. - * - * @return A registration object that can be used to remove the listener. - * - * @note This method is not available when using STLPort on Android, as - * std::function is not supported on STLPort. - */ - virtual ListenerRegistration AddSnapshotListener( - const DocumentListenOptions& options, - std::function callback); -#endif // defined(FIREBASE_USE_STD_FUNCTION) || defined(DOXYGEN) -}; - -// TODO(rsgowman): probably define and inline here. -bool operator==(const DocumentReference& lhs, const DocumentReference& rhs); - -inline bool operator!=(const DocumentReference& lhs, - const DocumentReference& rhs) { - return !(lhs == rhs); -} - -// TODO(rsgowman): probably define and inline here. -bool operator<(const DocumentReference& lhs, const DocumentReference& rhs); - -inline bool operator>(const DocumentReference& lhs, - const DocumentReference& rhs) { - return rhs < lhs; -} - -inline bool operator<=(const DocumentReference& lhs, - const DocumentReference& rhs) { - return !(lhs > rhs); -} - -inline bool operator>=(const DocumentReference& lhs, - const DocumentReference& rhs) { - return !(lhs < rhs); -} - -} // namespace firestore -} // namespace firebase - -namespace std { -// TODO(rsgowman): NB that specialization of std::hash deviates from the Google -// C++ style guide. But we think this is probably ok in this case since: -// a) It's the standard way of doing this outside of Google (as the style guide -// itself points out), and -// b) This has a straightforward hash function anyway (just hash the path) so I -// don't think the concerns in the style guide are going to bite us. -// -// Raise this concern during the API review. -template <> -struct hash { - std::size_t operator()( - const firebase::firestore::DocumentReference& doc_ref) const; -}; -} // namespace std - -#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_DOCUMENT_REFERENCE_H_ diff --git a/Firestore/core/include/firebase/firestore/event_listener.h b/Firestore/core/include/firebase/firestore/event_listener.h deleted file mode 100644 index 6c9442879fa4..000000000000 --- a/Firestore/core/include/firebase/firestore/event_listener.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2018 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(rsgowman): This file isn't intended to be used just yet. It's just an -// outline of what the API might eventually look like. Most of this was -// shamelessly stolen and modified from rtdb's header file, melded with the -// (java) firestore api. - -#ifndef FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_EVENT_LISTENER_H_ -#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_EVENT_LISTENER_H_ - -namespace firebase { -namespace firestore { - -// TODO(rsgowman): replace these forward decl's with appropriate includes (once -// they exist) -class Error; - -/** - * @brief An interface for event listeners. - */ -template -class EventListener { - public: - /** - * @brief OnEvent will be called with the new value or the error if an error - * occurred. - * - * It's guaranteed that exactly one of value or error will be non-null. - * - * @param value The value of the event. null if there was an error. - * @param error The error if there was error. null otherwise. - */ - void OnEvent(const T* value, const Error* error); -}; - -} // namespace firestore -} // namespace firebase - -#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_EVENT_LISTENER_H_ diff --git a/Firestore/core/include/firebase/firestore/firestore.h b/Firestore/core/include/firebase/firestore/firestore.h deleted file mode 100644 index 793fdd038f21..000000000000 --- a/Firestore/core/include/firebase/firestore/firestore.h +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2018 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(rsgowman): This file isn't intended to be used just yet. It's just an -// outline of what the API might eventually look like. Most of this was -// shamelessly stolen and modified from rtdb's header file, melded with the -// firestore api. - -#ifndef FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIRESTORE_H_ -#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIRESTORE_H_ - -#include - -// TODO(rsgowman): replace these forward decl's with appropriate includes (once -// they exist) -namespace firebase { -class App; -class InitResult; -} // namespace firebase - -namespace firebase { -namespace firestore { - -// TODO(rsgowman): replace these forward decl's with appropriate includes (once -// they exist) -class DocumentReference; -class CollectionReference; -class Settings; - -/** - * @brief Entry point for the Firebase Firestore C++ SDK. - * - * To use the SDK, call firebase::firestore::Firestore::GetInstance() to obtain - * an instance of Firestore, then use Collection() or Document() to obtain - * references to child paths within the database. From there you can set data - * via CollectionReference::Add() and DocumentReference::Set(), or get data via - * CollectionReference::Get() and DocumentReference::Get(), attach listeners, - * and more. - * - * Subclassing Note: Firestore classes are not meant to be subclassed except for - * use in test mocks. Subclassing is not supported in production code and new - * SDK releases may break code that does so. - */ -class Firestore { - public: - /** - * @brief Returns an instance of Firestore corresponding to the given App. - * - * Firebase Firestore uses firebase::App to communicate with Firebase - * Authentication to authenticate users to the Firestore server backend. - * - * If you call GetInstance() multiple times with the same App, you will get - * the same instance of App. - * - * @param[in] app Your instance of firebase::App. Firebase Firestore will use - * this to communicate with Firebase Authentication. - * @param[out] init_result_out Optional: If provided, write the init result - * here. Will be set to kInitResultSuccess if initialization succeeded, or - * kInitResultFailedMissingDependency on Android if Google Play services is - * not available on the current device. - * - * @returns An instance of Firestore corresponding to the given App. - */ - static Firestore* GetInstance(::firebase::App* app, - InitResult* init_result_out = nullptr); - - static Firestore* GetInstance(InitResult* init_result_out = nullptr); - - /** - * @brief Destructor for the Firestore object. - * - * When deleted, this instance will be removed from the cache of Firestore - * objects. If you call GetInstance() in the future with the same App, a new - * Firestore instance will be created. - */ - virtual ~Firestore(); - - /** - * @brief Returns the firebase::App that this Firestore was created with. - * - * @returns The firebase::App this Firestore was created with. - */ - virtual const App* app() const; - - /** - * @brief Returns the firebase::App that this Firestore was created with. - * - * @returns The firebase::App this Firestore was created with. - */ - virtual App* app(); - - /** - * @brief Returns a CollectionReference instance that refers to the - * collection at the specified path within the database. - * - * @param[in] collection_path A slash-separated path to a collection. - * - * @return The CollectionReference instance. - */ - virtual CollectionReference Collection(const char* collection_path) const; - - /** - * @brief Returns a CollectionReference instance that refers to the - * collection at the specified path within the database. - * - * @param[in] collection_path A slash-separated path to a collection. - * - * @return The CollectionReference instance. - */ - virtual CollectionReference Collection( - const std::string& collection_path) const; - - /** - * @brief Returns a DocumentReference instance that refers to the document at - * the specified path within the database. - * - * @param[in] document_path A slash-separated path to a document. - * @return The DocumentReference instance. - */ - virtual DocumentReference Document(const char* document_path) const; - - /** - * @brief Returns a DocumentReference instance that refers to the document at - * the specified path within the database. - * - * @param[in] document_path A slash-separated path to a document. - * - * @return The DocumentReference instance. - */ - virtual DocumentReference Document(const std::string& document_path) const; - - /** Returns the settings used by this Firestore object. */ - virtual Settings settings() const; - - /** Sets any custom settings used to configure this Firestore object. */ - virtual void set_settings(const Settings& settings); - - // TODO(rsgowman): batch(), runTransaction() - - /** Globally enables / disables Firestore logging for the SDK. */ - static void set_logging_enabled(bool logging_enabled); -}; - -} // namespace firestore -} // namespace firebase - -#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIRESTORE_H_ diff --git a/Firestore/core/include/firebase/firestore/firestore_errors.h b/Firestore/core/include/firebase/firestore/firestore_errors.h deleted file mode 100644 index 7a0ff7c3c79d..000000000000 --- a/Firestore/core/include/firebase/firestore/firestore_errors.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2018 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIRESTORE_ERRORS_H_ -#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIRESTORE_ERRORS_H_ - -namespace firebase { -namespace firestore { - -/** - * Error codes used by Cloud Firestore. - * - * The codes are in sync with the Firestore iOS client SDK header file - * FIRFirestoreErrors.h. - */ -enum FirestoreErrorCode { - /** - * The operation completed successfully. NSError objects will never have a - * code with this value. - */ - Ok = 0, - - /** The operation was cancelled (typically by the caller). */ - Cancelled = 1, - - /** Unknown error or an error from a different error domain. */ - Unknown = 2, - - /** - * Client specified an invalid argument. Note that this differs from - * FailedPrecondition. InvalidArgument indicates arguments that are - * problematic regardless of the state of the system (e.g., an invalid field - * name). - */ - InvalidArgument = 3, - - /** - * Deadline expired before operation could complete. For operations that - * change the state of the system, this error may be returned even if the - * operation has completed successfully. For example, a successful response - * from a server could have been delayed long enough for the deadline to - * expire. - */ - DeadlineExceeded = 4, - - /** Some requested document was not found. */ - NotFound = 5, - - /** Some document that we attempted to create already exists. */ - AlreadyExists = 6, - - /** The caller does not have permission to execute the specified operation. */ - PermissionDenied = 7, - - /** - * Some resource has been exhausted, perhaps a per-user quota, or perhaps the - * entire file system is out of space. - */ - ResourceExhausted = 8, - - /** - * Operation was rejected because the system is not in a state required for - * the operation's execution. - */ - FailedPrecondition = 9, - - /** - * The operation was aborted, typically due to a concurrency issue like - * transaction aborts, etc. - */ - Aborted = 10, - - /** Operation was attempted past the valid range. */ - OutOfRange = 11, - - /** Operation is not implemented or not supported/enabled. */ - Unimplemented = 12, - - /** - * Internal errors. Means some invariants expected by underlying system has - * been broken. If you see one of these errors, something is very broken. - */ - Internal = 13, - - /** - * The service is currently unavailable. This is a most likely a transient - * condition and may be corrected by retrying with a backoff. - */ - Unavailable = 14, - - /** Unrecoverable data loss or corruption. */ - DataLoss = 15, - - /** The request does not have valid authentication credentials for the - operation. */ - Unauthenticated = 16 -}; - -} // namespace firestore -} // namespace firebase - -#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIRESTORE_ERRORS_H_ diff --git a/Firestore/core/include/firebase/firestore/timestamp.h b/Firestore/core/include/firebase/firestore/timestamp.h deleted file mode 100644 index 1736981ed34c..000000000000 --- a/Firestore/core/include/firebase/firestore/timestamp.h +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright 2018 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_TIMESTAMP_H_ -#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_TIMESTAMP_H_ - -#include -#include -#include - -#if !defined(_STLPORT_VERSION) -#include // NOLINT(build/c++11) -#endif // !defined(_STLPORT_VERSION) - -namespace firebase { - -/** - * A Timestamp represents a point in time independent of any time zone or - * calendar, represented as seconds and fractions of seconds at nanosecond - * resolution in UTC Epoch time. It is encoded using the Proleptic Gregorian - * Calendar which extends the Gregorian calendar backwards to year one. It is - * encoded assuming all minutes are 60 seconds long, i.e. leap seconds are - * "smeared" so that no leap second table is needed for interpretation. Range is - * from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. - * - * @see - * https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto - */ -class Timestamp { - public: - /** - * Creates a new timestamp representing the epoch (with seconds and - * nanoseconds set to 0). - */ - Timestamp(); - - /** - * Creates a new timestamp. - * - * @param seconds The number of seconds of UTC time since Unix epoch - * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to - * 9999-12-31T23:59:59Z inclusive; otherwise, assertion failure will be - * triggered. - * @param nanoseconds The non-negative fractions of a second at nanosecond - * resolution. Negative second values with fractions must still have - * non-negative nanoseconds values that count forward in time. Must be - * from 0 to 999,999,999 inclusive; otherwise, assertion failure will be - * triggered. - */ - Timestamp(int64_t seconds, int32_t nanoseconds); - - /** - * Creates a new timestamp with the current date. - * - * The precision is up to nanoseconds, depending on the system clock. - * - * @return a new timestamp representing the current date. - */ - static Timestamp Now(); - - /** - * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. - */ - int64_t seconds() const { - return seconds_; - } - - /** - * The non-negative fractions of a second at nanosecond resolution. Negative - * second values with fractions still have non-negative nanoseconds values - * that count forward in time. - */ - int32_t nanoseconds() const { - return nanoseconds_; - } - - /** - * Converts `time_t` to a `Timestamp`. - * - * @param seconds_since_unix_epoch - * @parblock - * The number of seconds of UTC time since Unix epoch - * 1970-01-01T00:00:00Z. Can be negative to represent dates before the - * epoch. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z - * inclusive; otherwise, assertion failure will be triggered. - * - * Note that while the epoch of `time_t` is unspecified, it's usually Unix - * epoch. If this assumption is broken, this function will produce - * incorrect results. - * @endparblock - * - * @return a new timestamp with the given number of seconds and zero - * nanoseconds. - */ - static Timestamp FromTimeT(time_t seconds_since_unix_epoch); - -#if !defined(_STLPORT_VERSION) - /** - * Converts `std::chrono::time_point` to a `Timestamp`. - * - * @param time_point - * @parblock - * The time point with system clock's epoch, which is - * presumed to be Unix epoch 1970-01-01T00:00:00Z. Can be negative to - * represent dates before the epoch. Must be from 0001-01-01T00:00:00Z to - * 9999-12-31T23:59:59Z inclusive; otherwise, assertion failure will be - * triggered. - * - * Note that while the epoch of `std::chrono::system_clock` is - * unspecified, it's usually Unix epoch. If this assumption is broken, - * this constructor will produce incorrect results. - * @endparblock - */ - static Timestamp FromTimePoint( - std::chrono::time_point time_point); - - /** - * Converts this `Timestamp` to a `time_point`. - * - * Important: if overflow would occur, the returned value will be the maximum - * or minimum value that `Duration` can hold. Note in particular that `long - * long` is insufficient to hold the full range of `Timestamp` values with - * nanosecond precision (which is why `Duration` defaults to `microseconds`). - */ - template - std::chrono::time_point ToTimePoint() const; -#endif // !defined(_STLPORT_VERSION) - - /** - * Returns a string representation of this `Timestamp` for logging/debugging - * purposes. - * - * Note: the exact string representation is unspecified and subject to change; - * don't rely on the format of the string. - */ - std::string ToString() const; - - private: - // Checks that the number of seconds is within the supported date range, and - // that nanoseconds satisfy 0 <= ns <= 1second. - void ValidateBounds() const; - - int64_t seconds_ = 0; - int32_t nanoseconds_ = 0; -}; - -inline bool operator<(const Timestamp& lhs, const Timestamp& rhs) { - return lhs.seconds() < rhs.seconds() || - (lhs.seconds() == rhs.seconds() && - lhs.nanoseconds() < rhs.nanoseconds()); -} - -inline bool operator>(const Timestamp& lhs, const Timestamp& rhs) { - return rhs < lhs; -} - -inline bool operator>=(const Timestamp& lhs, const Timestamp& rhs) { - return !(lhs < rhs); -} - -inline bool operator<=(const Timestamp& lhs, const Timestamp& rhs) { - return !(lhs > rhs); -} - -inline bool operator!=(const Timestamp& lhs, const Timestamp& rhs) { - return lhs < rhs || lhs > rhs; -} - -inline bool operator==(const Timestamp& lhs, const Timestamp& rhs) { - return !(lhs != rhs); -} - -#if !defined(_STLPORT_VERSION) -template -std::chrono::time_point Timestamp::ToTimePoint() const { - namespace chr = std::chrono; - using TimePoint = chr::time_point; - - // Saturate on overflow - const auto max_seconds = chr::duration_cast(Duration::max()); - if (seconds_ > 0 && max_seconds.count() <= seconds_) { - return TimePoint{Duration::max()}; - } - const auto min_seconds = chr::duration_cast(Duration::min()); - if (seconds_ < 0 && min_seconds.count() >= seconds_) { - return TimePoint{Duration::min()}; - } - - const auto seconds = chr::duration_cast(chr::seconds(seconds_)); - const auto nanoseconds = - chr::duration_cast(chr::nanoseconds(nanoseconds_)); - return TimePoint{seconds + nanoseconds}; -} -#endif // !defined(_STLPORT_VERSION) - -} // namespace firebase - -namespace std { -template <> -struct hash { - // Note: specialization of `std::hash` is provided for convenience only. The - // implementation is subject to change. - size_t operator()(const firebase::Timestamp& timestamp) const; -}; -} // namespace std - -#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_TIMESTAMP_H_