aggregate_field.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2023 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_MODEL_AGGREGATE_FIELD_H_
  17. #define FIRESTORE_CORE_SRC_MODEL_AGGREGATE_FIELD_H_
  18. #include <string>
  19. #include <utility>
  20. #include "Firestore/core/src/model/aggregate_alias.h"
  21. #include "Firestore/core/src/model/aggregate_field.h"
  22. #include "Firestore/core/src/model/field_path.h"
  23. namespace firebase {
  24. namespace firestore {
  25. namespace model {
  26. class AggregateField {
  27. public:
  28. enum class OpKind { Sum, Avg, Count };
  29. const OpKind op;
  30. const model::AggregateAlias alias;
  31. const model::FieldPath fieldPath;
  32. AggregateField(OpKind op, model::AggregateAlias&& alias)
  33. : op(op), alias(std::move(alias)) {
  34. }
  35. AggregateField(OpKind op,
  36. model::AggregateAlias&& alias,
  37. const model::FieldPath& fieldPath)
  38. : op(op), alias(std::move(alias)), fieldPath(fieldPath) {
  39. }
  40. friend bool operator==(const AggregateField& lhs, const AggregateField& rhs);
  41. size_t Hash() const;
  42. };
  43. inline bool operator==(const AggregateField& lhs, const AggregateField& rhs) {
  44. return lhs.op == rhs.op && lhs.alias == rhs.alias &&
  45. lhs.fieldPath.CanonicalString() == rhs.fieldPath.CanonicalString();
  46. }
  47. } // namespace model
  48. } // namespace firestore
  49. } // namespace firebase
  50. #endif // FIRESTORE_CORE_SRC_MODEL_AGGREGATE_FIELD_H_