named_query.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2021 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_BUNDLE_NAMED_QUERY_H_
  17. #define FIRESTORE_CORE_SRC_BUNDLE_NAMED_QUERY_H_
  18. #include <string>
  19. #include <utility>
  20. #include "Firestore/core/src/bundle/bundle_element.h"
  21. #include "Firestore/core/src/bundle/bundled_query.h"
  22. #include "Firestore/core/src/model/snapshot_version.h"
  23. namespace firebase {
  24. namespace firestore {
  25. namespace bundle {
  26. /**
  27. * Represents a named query saved by the SDK in its local storage.
  28. */
  29. class NamedQuery : public BundleElement {
  30. public:
  31. NamedQuery() = default;
  32. NamedQuery(std::string query_name,
  33. BundledQuery bundled_query,
  34. model::SnapshotVersion read_time)
  35. : query_name_(std::move(query_name)),
  36. bundled_query_(std::move(bundled_query)),
  37. read_time_(read_time) {
  38. }
  39. Type element_type() const override {
  40. return Type::NamedQuery;
  41. }
  42. /**
  43. * @return The name of the query.
  44. */
  45. const std::string& query_name() const {
  46. return query_name_;
  47. }
  48. /**
  49. * @return The underlying query associated with the given name.
  50. */
  51. const BundledQuery& bundled_query() const {
  52. return bundled_query_;
  53. }
  54. /**
  55. * @return The time at which the results for this query were read.
  56. */
  57. model::SnapshotVersion read_time() const {
  58. return read_time_;
  59. }
  60. private:
  61. std::string query_name_;
  62. BundledQuery bundled_query_;
  63. model::SnapshotVersion read_time_;
  64. };
  65. inline bool operator==(const NamedQuery& lhs, const NamedQuery& rhs) {
  66. return lhs.query_name() == rhs.query_name() &&
  67. lhs.read_time() == rhs.read_time() &&
  68. lhs.bundled_query() == rhs.bundled_query();
  69. }
  70. inline bool operator!=(const NamedQuery& lhs, const NamedQuery& rhs) {
  71. return !(lhs == rhs);
  72. }
  73. } // namespace bundle
  74. } // namespace firestore
  75. } // namespace firebase
  76. #endif // FIRESTORE_CORE_SRC_BUNDLE_NAMED_QUERY_H_