From 920cfbfa998ca9d04cce5f7731aced7e950a3477 Mon Sep 17 00:00:00 2001 From: rsgowman Date: Fri, 13 Jul 2018 16:22:07 -0400 Subject: Initial (incomplete) implementation of f:f:core::Filter (#1495) And RelationFilter subclass. Used to implement the next step in core::Query. --- Firestore/core/src/firebase/firestore/core/query.h | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'Firestore/core/src/firebase/firestore/core/query.h') diff --git a/Firestore/core/src/firebase/firestore/core/query.h b/Firestore/core/src/firebase/firestore/core/query.h index 84d645d..3df1d25 100644 --- a/Firestore/core/src/firebase/firestore/core/query.h +++ b/Firestore/core/src/firebase/firestore/core/query.h @@ -17,8 +17,11 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_CORE_QUERY_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_CORE_QUERY_H_ +#include #include +#include +#include "Firestore/core/src/firebase/firestore/core/filter.h" #include "Firestore/core/src/firebase/firestore/model/document.h" #include "Firestore/core/src/firebase/firestore/model/resource_path.h" @@ -26,7 +29,10 @@ namespace firebase { namespace firestore { namespace core { -/** Represents the internal structure of a Firestore Query. */ +/** + * Represents the internal structure of a Firestore Query. Query instances are + * immutable. + */ class Query { public: /** @@ -36,14 +42,17 @@ class Query { * @return A new instance of Query. */ static Query AtPath(model::ResourcePath path) { - return Query(std::move(path)); + return Query(std::move(path), {}); } /** Initializes a query with all of its components directly. */ - explicit Query(model::ResourcePath path /* TODO(rsgowman): other params */) - : path_(std::move(path)) { + Query(model::ResourcePath path, + std::vector> + filters /* TODO(rsgowman): other params */) + : path_(std::move(path)), filters_(std::move(filters)) { } + /** The base path of the query. */ const model::ResourcePath& path() const { return path_; } @@ -51,6 +60,11 @@ class Query { /** Returns true if the document matches the constraints of this query. */ bool Matches(const model::Document& doc) const; + /** + * Returns a copy of this Query object with the additional specified filter. + */ + Query Filter(std::shared_ptr filter) const; + private: bool MatchesPath(const model::Document& doc) const; bool MatchesFilters(const model::Document& doc) const; @@ -58,6 +72,12 @@ class Query { bool MatchesBounds(const model::Document& doc) const; const model::ResourcePath path_; + + // Filters are shared across related Query instance. i.e. when you call + // Query::Filter(f), a new Query instance is created that contains all of the + // existing filters, plus the new one. (Both Query and Filter objects are + // immutable.) Filters are not shared across unrelated Query instances. + const std::vector> filters_; }; } // namespace core -- cgit v1.2.3