document_reference.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright 2019 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef FIRESTORE_CORE_SRC_API_DOCUMENT_REFERENCE_H_
  17. #define FIRESTORE_CORE_SRC_API_DOCUMENT_REFERENCE_H_
  18. #include <memory>
  19. #include <string>
  20. #include <utility>
  21. #include "Firestore/core/src/api/api_fwd.h"
  22. #include "Firestore/core/src/core/core_fwd.h"
  23. #include "Firestore/core/src/model/document_key.h"
  24. #include "Firestore/core/src/util/status_fwd.h"
  25. namespace firebase {
  26. namespace firestore {
  27. namespace model {
  28. class ResourcePath;
  29. } // namespace model
  30. namespace api {
  31. class DocumentReference {
  32. public:
  33. DocumentReference() = default;
  34. DocumentReference(model::ResourcePath path,
  35. std::shared_ptr<Firestore> firestore);
  36. DocumentReference(model::DocumentKey document_key,
  37. std::shared_ptr<Firestore> firestore)
  38. : firestore_{std::move(firestore)}, key_{std::move(document_key)} {
  39. }
  40. size_t Hash() const;
  41. const std::shared_ptr<Firestore>& firestore() const {
  42. return firestore_;
  43. }
  44. const model::DocumentKey& key() const {
  45. return key_;
  46. }
  47. const std::string& document_id() const;
  48. CollectionReference Parent() const;
  49. std::string Path() const;
  50. CollectionReference GetCollectionReference(
  51. const std::string& collection_path) const;
  52. void SetData(core::ParsedSetData&& set_data, util::StatusCallback callback);
  53. void UpdateData(core::ParsedUpdateData&& update_data,
  54. util::StatusCallback callback);
  55. void DeleteDocument(util::StatusCallback callback);
  56. void GetDocument(Source source, DocumentSnapshotListener&& callback);
  57. std::unique_ptr<ListenerRegistration> AddSnapshotListener(
  58. core::ListenOptions options, DocumentSnapshotListener&& listener);
  59. private:
  60. std::shared_ptr<Firestore> firestore_;
  61. model::DocumentKey key_;
  62. };
  63. bool operator==(const DocumentReference& lhs, const DocumentReference& rhs);
  64. } // namespace api
  65. } // namespace firestore
  66. } // namespace firebase
  67. #endif // FIRESTORE_CORE_SRC_API_DOCUMENT_REFERENCE_H_