From 68f0e2dafbc99df0789be5fd0aa847ae69940363 Mon Sep 17 00:00:00 2001 From: zxu Date: Fri, 25 May 2018 15:06:19 -0400 Subject: Firestore project: Import of API interfaces. (#1337) - 198063502 Address comment upstream. by zxu - 197942352 Fix style upstream and fix destination depot in copybara. by zxu - 197925542 Fix headers with change from GitHub, see the current diff... by zxu - 197922012 Implement ListenerRegistration::Remove(). by zxu - 197713382 Implement more on listener class and implement ListenerRe... by zxu - 196551381 Implement more on listener class and implement the Docume... by zxu - 196276752 Implement the SnapshotMetadata with inline methods and (n... by zxu - 195841793 Implement the wrapper class for callback (EventListener). by zxu - 194112388 Add Android-Wrapper for DocumentReference's non-callback ... by zxu - 192445183 Add Android-Wrapper for Firestore's remaining methods. by zxu - 190986604 Manually import the public portion of by mcg - 189013767 Add Android-Wrapper for Firestore's method that does not ... by zxu - 188809445 Import of firebase-ios-sdk from Github. by mcg - 187049498 Import of firebase-ios-sdk from Github. by mcg - 184568931 Import of firebase-ios-sdk from Github. by mcg ORIGINAL_AUTHOR=Firebase PiperOrigin-RevId: 198063502 --- .../core/include/firebase/firestore/CMakeLists.txt | 2 +- .../firebase/firestore/collection_reference.h | 98 ++++++++++++++++++++ .../include/firebase/firestore/document_change.h | 34 +++++++ .../firebase/firestore/document_reference.h | 101 ++++++++------------- .../include/firebase/firestore/document_snapshot.h | 38 ++++++++ .../include/firebase/firestore/event_listener.h | 10 +- .../core/include/firebase/firestore/field_path.h | 34 +++++++ .../core/include/firebase/firestore/field_value.h | 33 +++++++ .../core/include/firebase/firestore/firestore.h | 26 ++++-- .../include/firebase/firestore/firestore_errors.h | 4 + .../firebase/firestore/listener_registration.h | 92 +++++++++++++++++++ Firestore/core/include/firebase/firestore/query.h | 33 +++++++ .../include/firebase/firestore/query_snapshot.h | 34 +++++++ .../core/include/firebase/firestore/set_options.h | 39 ++++++++ .../core/include/firebase/firestore/settings.h | 32 +++++++ .../include/firebase/firestore/snapshot_metadata.h | 46 ++++++++++ .../core/include/firebase/firestore/transaction.h | 32 +++++++ .../core/include/firebase/firestore/write_batch.h | 39 ++++++++ 18 files changed, 650 insertions(+), 77 deletions(-) create mode 100644 Firestore/core/include/firebase/firestore/collection_reference.h create mode 100644 Firestore/core/include/firebase/firestore/document_change.h create mode 100644 Firestore/core/include/firebase/firestore/document_snapshot.h create mode 100644 Firestore/core/include/firebase/firestore/field_path.h create mode 100644 Firestore/core/include/firebase/firestore/field_value.h create mode 100644 Firestore/core/include/firebase/firestore/listener_registration.h create mode 100644 Firestore/core/include/firebase/firestore/query.h create mode 100644 Firestore/core/include/firebase/firestore/query_snapshot.h create mode 100644 Firestore/core/include/firebase/firestore/set_options.h create mode 100644 Firestore/core/include/firebase/firestore/settings.h create mode 100644 Firestore/core/include/firebase/firestore/snapshot_metadata.h create mode 100644 Firestore/core/include/firebase/firestore/transaction.h create mode 100644 Firestore/core/include/firebase/firestore/write_batch.h (limited to 'Firestore/core/include') diff --git a/Firestore/core/include/firebase/firestore/CMakeLists.txt b/Firestore/core/include/firebase/firestore/CMakeLists.txt index e4e7acd..0c7fd48 100644 --- a/Firestore/core/include/firebase/firestore/CMakeLists.txt +++ b/Firestore/core/include/firebase/firestore/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Hack to make the headers show up in IDEs +# Workaround 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 diff --git a/Firestore/core/include/firebase/firestore/collection_reference.h b/Firestore/core/include/firebase/firestore/collection_reference.h new file mode 100644 index 0000000..4d47248 --- /dev/null +++ b/Firestore/core/include/firebase/firestore/collection_reference.h @@ -0,0 +1,98 @@ +/* + * 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_COLLECTION_REFERENCE_H_ +#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_COLLECTION_REFERENCE_H_ + +namespace firebase { +namespace firestore { + +class CollectionReferenceInternal; +class FirestoreInternal; + +/** + * A CollectionReference refers to a collection of documents location in a + * Firestore database and can be used for adding documents, getting document + * references, and querying for documents. + */ +// TODO(zxu123): add more methods to complete the class and make it useful. +class CollectionReference { + public: + /** + * @brief Default constructor. This creates an invalid CollectionReference. + * Attempting to perform any operations on this reference will fail unless a + * valid CollectionReference has been assigned to it. + */ + CollectionReference(); + + /** + * @brief Copy constructor. It's totally okay (and efficient) to copy + * CollectionReference instances, as they simply point to the same location in + * the database. + * + * @param[in] reference CollectionReference to copy from. + */ + CollectionReference(const CollectionReference& reference); + + /** + * @brief Move constructor. Moving is an efficient operation for + * CollectionReference instances. + * + * @param[in] reference CollectionReference to move data from. + */ + CollectionReference(CollectionReference&& reference); + + /** @brief Required virtual destructor. */ + virtual ~CollectionReference(); + + /** + * @brief Copy assignment operator. It's totally okay (and efficient) to copy + * CollectionReference instances, as they simply point to the same location in + * the database. + * + * @param[in] reference CollectionReference to copy from. + * + * @returns Reference to the destination CollectionReference. + */ + CollectionReference& operator=(const CollectionReference& reference); + + /** + * @brief Move assignment operator. Moving is an efficient operation for + * CollectionReference instances. + * + * @param[in] reference CollectionReference to move data from. + * + * @returns Reference to the destination CollectionReference. + */ + CollectionReference& operator=(CollectionReference&& reference); + + protected: + explicit CollectionReference(CollectionReferenceInternal* internal); + + private: + friend class DocumentReference; + friend class DocumentReferenceInternal; + friend class FirestoreInternal; + + // TODO(zxu123): investigate possibility to use std::unique_ptr or + // firebase::UniquePtr. + CollectionReferenceInternal* internal_ = nullptr; +}; + +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_COLLECTION_REFERENCE_H_ diff --git a/Firestore/core/include/firebase/firestore/document_change.h b/Firestore/core/include/firebase/firestore/document_change.h new file mode 100644 index 0000000..4812290 --- /dev/null +++ b/Firestore/core/include/firebase/firestore/document_change.h @@ -0,0 +1,34 @@ +/* + * 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_DOCUMENT_CHANGE_H_ +#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_DOCUMENT_CHANGE_H_ + +namespace firebase { +namespace firestore { + +/** + * A DocumentChange represents a change to the documents matching a query. It + * contains the document affected and the type of change that occurred (added, + * modified, or removed). + */ +// TODO(zxu123): add more methods to complete the class and make it useful. +class DocumentChange {}; + +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_DOCUMENT_CHANGE_H_ diff --git a/Firestore/core/include/firebase/firestore/document_reference.h b/Firestore/core/include/firebase/firestore/document_reference.h index d295188..9385ed3 100644 --- a/Firestore/core/include/firebase/firestore/document_reference.h +++ b/Firestore/core/include/firebase/firestore/document_reference.h @@ -29,6 +29,17 @@ #include #endif +#include "firebase/app.h" +#include "firebase/firestore/collection_reference.h" +#include "firebase/firestore/document_snapshot.h" +#include "firebase/firestore/event_listener.h" +#include "firebase/firestore/field_value.h" +#include "firebase/firestore/firestore.h" +#include "firebase/firestore/firestore_errors.h" +#include "firebase/firestore/listener_registration.h" +#include "firebase/firestore/set_options.h" +#include "firebase/future.h" + // 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 @@ -36,34 +47,12 @@ // 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 DocumentReferenceInternal; 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(); -}; +class FirestoreInternal; // TODO(rsgowman): move this into the FieldValue header #ifdef STLPORT @@ -80,12 +69,19 @@ using MapFieldValue = std::unordered_map; * * Create a DocumentReference via Firebase::Document(const string& path). * + * NOT thread-safe: an instance should not be used from multiple threads + * * 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: + enum class MetadataChanges { + kExclude, + kInclude, + }; + /** * @brief Default constructor. This creates an invalid DocumentReference. * Attempting to perform any operations on this reference will fail (and cause @@ -269,28 +265,15 @@ class DocumentReference { * 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.) + * @param[in] metadata_changes Indicates whether metadata-only changes (i.e. + * only DocumentSnapshot.getMetadata() changed) should trigger snapshot + * events. * * @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); + EventListener* listener, + MetadataChanges metadata_changes = MetadataChanges::kExclude); #if defined(FIREBASE_USE_STD_FUNCTION) || defined(DOXYGEN) /** @@ -299,6 +282,9 @@ class DocumentReference { * * @param[in] callback function or lambda to call. When this function is * called, exactly one of the parameters will be non-null. + * @param[in] metadata_changes Indicates whether metadata-only changes (i.e. + * only DocumentSnapshot.getMetadata() changed) should trigger snapshot + * events. * * @return A registration object that can be used to remove the listener. * @@ -306,28 +292,21 @@ class DocumentReference { * 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); + std::function callback, + MetadataChanges metadata_changes = MetadataChanges::kExclude); #endif // defined(FIREBASE_USE_STD_FUNCTION) || defined(DOXYGEN) + + protected: + explicit DocumentReference(DocumentReferenceInternal* internal); + + private: + friend class FirestoreInternal; + + // TODO(zxu123): investigate possibility to use std::unique_ptr or + // firebase::UniquePtr. + DocumentReferenceInternal* internal_ = nullptr; }; -// TODO(rsgowman): probably define and inline here. bool operator==(const DocumentReference& lhs, const DocumentReference& rhs); inline bool operator!=(const DocumentReference& lhs, diff --git a/Firestore/core/include/firebase/firestore/document_snapshot.h b/Firestore/core/include/firebase/firestore/document_snapshot.h new file mode 100644 index 0000000..3be72b5 --- /dev/null +++ b/Firestore/core/include/firebase/firestore/document_snapshot.h @@ -0,0 +1,38 @@ +/* + * 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_DOCUMENT_SNAPSHOT_H_ +#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_DOCUMENT_SNAPSHOT_H_ + +namespace firebase { +namespace firestore { + +/** + * A DocumentSnapshot contains data read from a document in your Firestore + * database. The data can be extracted with the data() method or by using + * FooValue() to access a specific field, where Foo is the type of that field. + * + * For a DocumentSnapshot that points to a non-existing document, any data + * access will cause a failed assertion. You can use the exists() method to + * explicitly verify a documents existence. + */ +// TODO(zxu123): add more methods to complete the class and make it useful. +class DocumentSnapshot {}; + +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_DOCUMENT_SNAPSHOT_H_ diff --git a/Firestore/core/include/firebase/firestore/event_listener.h b/Firestore/core/include/firebase/firestore/event_listener.h index 6c94428..cbe8a28 100644 --- a/Firestore/core/include/firebase/firestore/event_listener.h +++ b/Firestore/core/include/firebase/firestore/event_listener.h @@ -22,19 +22,19 @@ #ifndef FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_EVENT_LISTENER_H_ #define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_EVENT_LISTENER_H_ +#include "firebase/firestore/firestore_errors.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: + virtual ~EventListener() { + } /** * @brief OnEvent will be called with the new value or the error if an error * occurred. @@ -44,7 +44,7 @@ class EventListener { * @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); + virtual void OnEvent(const T* value, const Error* error) = 0; }; } // namespace firestore diff --git a/Firestore/core/include/firebase/firestore/field_path.h b/Firestore/core/include/firebase/firestore/field_path.h new file mode 100644 index 0000000..29e1dea --- /dev/null +++ b/Firestore/core/include/firebase/firestore/field_path.h @@ -0,0 +1,34 @@ +/* + * 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_FIELD_PATH_H_ +#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIELD_PATH_H_ + +namespace firebase { +namespace firestore { + +/** + * A FieldPath refers to a field in a document. The path may consist of a single + * field name (referring to a top level field in the document), or a list of + * field names (referring to a nested field in the document). + */ +// TODO(zxu123): add more methods to complete the class and make it useful. +class FieldPath {}; + +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIELD_PATH_H_ diff --git a/Firestore/core/include/firebase/firestore/field_value.h b/Firestore/core/include/firebase/firestore/field_value.h new file mode 100644 index 0000000..d919de4 --- /dev/null +++ b/Firestore/core/include/firebase/firestore/field_value.h @@ -0,0 +1,33 @@ +/* + * 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_FIELD_VALUE_H_ +#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIELD_VALUE_H_ + +namespace firebase { +namespace firestore { + +/** + * Sentinel values that can be used when writing document fields with setData() + * or updateData(). + */ +// TODO(zxu123): add more methods to complete the class and make it useful. +class FieldValue {}; + +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIELD_VALUE_H_ diff --git a/Firestore/core/include/firebase/firestore/firestore.h b/Firestore/core/include/firebase/firestore/firestore.h index 793fdd0..6591a72 100644 --- a/Firestore/core/include/firebase/firestore/firestore.h +++ b/Firestore/core/include/firebase/firestore/firestore.h @@ -22,23 +22,19 @@ #ifndef FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIRESTORE_H_ #define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_FIRESTORE_H_ +#include #include -// TODO(rsgowman): replace these forward decl's with appropriate includes (once -// they exist) -namespace firebase { -class App; -class InitResult; -} // namespace firebase +#include "firebase/app.h" +#include "firebase/firestore/collection_reference.h" +#include "firebase/firestore/document_reference.h" +#include "firebase/firestore/settings.h" namespace firebase { namespace firestore { -// TODO(rsgowman): replace these forward decl's with appropriate includes (once -// they exist) class DocumentReference; -class CollectionReference; -class Settings; +class FirestoreInternal; /** * @brief Entry point for the Firebase Firestore C++ SDK. @@ -152,6 +148,16 @@ class Firestore { /** Globally enables / disables Firestore logging for the SDK. */ static void set_logging_enabled(bool logging_enabled); + + Firestore(const Firestore& src) = delete; + Firestore& operator=(const Firestore& src) = delete; + + private: + explicit Firestore(::firebase::App* app); + + // TODO(zxu123): investigate possibility to use std::unique_ptr or + // firebase::UniquePtr. + FirestoreInternal* internal_ = nullptr; }; } // namespace firestore diff --git a/Firestore/core/include/firebase/firestore/firestore_errors.h b/Firestore/core/include/firebase/firestore/firestore_errors.h index 7a0ff7c..92c0c92 100644 --- a/Firestore/core/include/firebase/firestore/firestore_errors.h +++ b/Firestore/core/include/firebase/firestore/firestore_errors.h @@ -109,6 +109,10 @@ enum FirestoreErrorCode { Unauthenticated = 16 }; +// TODO(zxu123): decide whether we actually want an Error class or just use +// enum. +using Error = FirestoreErrorCode; + } // namespace firestore } // namespace firebase diff --git a/Firestore/core/include/firebase/firestore/listener_registration.h b/Firestore/core/include/firebase/firestore/listener_registration.h new file mode 100644 index 0000000..a37c2aa --- /dev/null +++ b/Firestore/core/include/firebase/firestore/listener_registration.h @@ -0,0 +1,92 @@ +/* + * 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_LISTENER_REGISTRATION_H_ +#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_LISTENER_REGISTRATION_H_ + +namespace firebase { +namespace firestore { + +class FirestoreInternal; +class ListenerRegistrationInternal; + +/** Represents a listener that can be removed by calling remove. */ +class ListenerRegistration { + public: + /** + * @brief Default constructor. This creates a no-op instance. + */ + ListenerRegistration(); + + /** + * @brief Copy constructor. It's totally okay to copy ListenerRegistration + * instances. + * + * @param[in] registration ListenerRegistration to copy from. + */ + ListenerRegistration(const ListenerRegistration& registration); + + /** + * @brief Move constructor. Moving is an efficient operation for + * ListenerRegistration instances. + * + * @param[in] registration ListenerRegistration to move data from. + */ + ListenerRegistration(ListenerRegistration&& registration); + + ~ListenerRegistration(); + + /** + * @brief Copy assignment operator. It's totally okay to copy + * ListenerRegistration instances. + * + * @param[in] registration ListenerRegistration to copy from. + * + * @returns Reference to the destination ListenerRegistration. + */ + ListenerRegistration& operator=(const ListenerRegistration& registration); + + /** + * @brief Move assignment operator. Moving is an efficient operation for + * ListenerRegistration instances. + * + * @param[in] registration ListenerRegistration to move data from. + * + * @returns Reference to the destination ListenerRegistration. + */ + ListenerRegistration& operator=(ListenerRegistration&& registration); + + /** + * Removes the listener being tracked by this ListenerRegistration. After the + * initial call, subsequent calls have no effect. + */ + void Remove(); + + private: + friend class DocumentReferenceInternal; + friend class ListenerRegistrationInternal; + friend class FirestoreInternal; + + explicit ListenerRegistration(ListenerRegistrationInternal* internal); + + FirestoreInternal* firestore_ = nullptr; + ListenerRegistrationInternal* internal_ = nullptr; +}; + +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_LISTENER_REGISTRATION_H_ diff --git a/Firestore/core/include/firebase/firestore/query.h b/Firestore/core/include/firebase/firestore/query.h new file mode 100644 index 0000000..da6dfdd --- /dev/null +++ b/Firestore/core/include/firebase/firestore/query.h @@ -0,0 +1,33 @@ +/* + * 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_QUERY_H_ +#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_QUERY_H_ + +namespace firebase { +namespace firestore { + +/** + * A Query which you can read or listen to. You can also construct refined + * Query objects by adding filters and ordering. + */ +// TODO(zxu123): add more methods to complete the class and make it useful. +class Query {}; + +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_QUERY_H_ diff --git a/Firestore/core/include/firebase/firestore/query_snapshot.h b/Firestore/core/include/firebase/firestore/query_snapshot.h new file mode 100644 index 0000000..ffa2bd6 --- /dev/null +++ b/Firestore/core/include/firebase/firestore/query_snapshot.h @@ -0,0 +1,34 @@ +/* + * 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_QUERY_SNAPSHOT_H_ +#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_QUERY_SNAPSHOT_H_ + +namespace firebase { +namespace firestore { + +/** + * A QuerySnapshot contains zero or more DocumentSnapshot objects. It can be + * iterated using a range-based for loop and its size can be inspected with + * empty() and count(). + */ +// TODO(zxu123): add more methods to complete the class and make it useful. +class QuerySnapshot {}; + +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_QUERY_SNAPSHOT_H_ diff --git a/Firestore/core/include/firebase/firestore/set_options.h b/Firestore/core/include/firebase/firestore/set_options.h new file mode 100644 index 0000000..802f3b5 --- /dev/null +++ b/Firestore/core/include/firebase/firestore/set_options.h @@ -0,0 +1,39 @@ +/* + * 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_SET_OPTIONS_H_ +#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_SET_OPTIONS_H_ + +namespace firebase { +namespace firestore { + +/** + * An options object that configures the behavior of Set() calls. By providing + * the SetOptions objects returned by Merge(), the Set() methods in + * DocumentReference, WriteBatch and Transaction can be configured to perform + * granular merges instead of overwriting the target documents in their + * entirety. + */ +// TODO(zxu123): add more methods to complete the class and make it useful. +class SetOptions { + public: + SetOptions(); +}; + +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_SET_OPTIONS_H_ diff --git a/Firestore/core/include/firebase/firestore/settings.h b/Firestore/core/include/firebase/firestore/settings.h new file mode 100644 index 0000000..9356b26 --- /dev/null +++ b/Firestore/core/include/firebase/firestore/settings.h @@ -0,0 +1,32 @@ +/* + * 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_SETTINGS_H_ +#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_SETTINGS_H_ + +namespace firebase { +namespace firestore { + +class SettingsInternal; + +/** Settings used to configure a Firestore instance. */ +// TODO(zxu123): add more methods to complete the class and make it useful. +class Settings {}; + +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_SETTINGS_H_ diff --git a/Firestore/core/include/firebase/firestore/snapshot_metadata.h b/Firestore/core/include/firebase/firestore/snapshot_metadata.h new file mode 100644 index 0000000..9bcc54c --- /dev/null +++ b/Firestore/core/include/firebase/firestore/snapshot_metadata.h @@ -0,0 +1,46 @@ +/* + * 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_SNAPSHOT_METADATA_H_ +#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_SNAPSHOT_METADATA_H_ + +namespace firebase { +namespace firestore { + +/** Metadata about a snapshot, describing the state of the snapshot. */ +class SnapshotMetadata { + public: + SnapshotMetadata(bool has_pending_writes, bool is_from_cache) + : has_pending_writes_(has_pending_writes), is_from_cache_(is_from_cache) { + } + + bool has_pending_writes() const { + return has_pending_writes_; + } + + bool is_from_cache() const { + return is_from_cache_; + } + + private: + const bool has_pending_writes_; + const bool is_from_cache_; +}; + +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_SNAPSHOT_METADATA_H_ diff --git a/Firestore/core/include/firebase/firestore/transaction.h b/Firestore/core/include/firebase/firestore/transaction.h new file mode 100644 index 0000000..be043b8 --- /dev/null +++ b/Firestore/core/include/firebase/firestore/transaction.h @@ -0,0 +1,32 @@ +/* + * 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_TRANSACTION_H_ +#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_TRANSACTION_H_ + +namespace firebase { +namespace firestore { + +/** + * Transaction provides methods to read and write data within a transaction. + */ +// TODO(zxu123): add more methods to complete the class and make it useful. +class Transaction {}; + +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_TRANSACTION_H_ diff --git a/Firestore/core/include/firebase/firestore/write_batch.h b/Firestore/core/include/firebase/firestore/write_batch.h new file mode 100644 index 0000000..bd2c12f --- /dev/null +++ b/Firestore/core/include/firebase/firestore/write_batch.h @@ -0,0 +1,39 @@ +/* + * 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_WRITE_BATCH_H_ +#define FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_WRITE_BATCH_H_ + +namespace firebase { +namespace firestore { + +/** + * A write batch is used to perform multiple writes as a single atomic unit. + * + * A WriteBatch object provides methods for adding writes to the write batch. + * None of the writes will be committed (or visible locally) until commit() is + * called. + * + * Unlike transactions, write batches are persisted offline and therefore are + * preferable when you don't need to condition your writes on read data. + */ +// TODO(zxu123): add more methods to complete the class and make it useful. +class WriteBatch {}; + +} // namespace firestore +} // namespace firebase + +#endif // FIRESTORE_CORE_INCLUDE_FIREBASE_FIRESTORE_WRITE_BATCH_H_ -- cgit v1.2.3