Skip to content

Commit 09ca539

Browse files
committed
Add KeyFieldFilter
1 parent 84b0e7d commit 09ca539

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

Firestore/core/src/firebase/firestore/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ cc_library(
2525
field_filter.h
2626
filter.cc
2727
filter.h
28+
key_field_filter.cc
29+
key_field_filter.h
2830
listen_options.h
2931
nan_filter.cc
3032
nan_filter.h
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2019 Google
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+
17+
#include "Firestore/core/src/firebase/firestore/core/key_field_filter.h"
18+
19+
#include <utility>
20+
21+
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
22+
#include "absl/algorithm/container.h"
23+
24+
namespace firebase {
25+
namespace firestore {
26+
namespace core {
27+
28+
using model::Document;
29+
using model::DocumentKey;
30+
using model::FieldPath;
31+
using model::FieldValue;
32+
33+
using Operator = Filter::Operator;
34+
35+
KeyFieldFilter::KeyFieldFilter(FieldPath field, Operator op, FieldValue value)
36+
: FieldFilter(std::move(field), op, std::move(value)) {
37+
}
38+
39+
bool KeyFieldFilter::Matches(const Document& doc) const {
40+
const DocumentKey& lhs_key = doc.key();
41+
const DocumentKey& rhs_key = value().reference_value().key();
42+
43+
return MatchesComparison(lhs_key.CompareTo(rhs_key));
44+
}
45+
46+
} // namespace core
47+
} // namespace firestore
48+
} // namespace firebase
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2019 Google
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+
17+
#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_CORE_KEY_FIELD_FILTER_H_
18+
#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_CORE_KEY_FIELD_FILTER_H_
19+
20+
#include <string>
21+
22+
#include "Firestore/core/src/firebase/firestore/core/field_filter.h"
23+
24+
namespace firebase {
25+
namespace firestore {
26+
namespace core {
27+
28+
/**
29+
* A Filter that matches on key fields (i.e. '__name__').
30+
*/
31+
class KeyFieldFilter : public FieldFilter {
32+
public:
33+
KeyFieldFilter() = default;
34+
35+
KeyFieldFilter(model::FieldPath field,
36+
core::Filter::Operator op,
37+
model::FieldValue value);
38+
39+
bool Matches(const model::Document& doc) const override;
40+
};
41+
42+
} // namespace core
43+
} // namespace firestore
44+
} // namespace firebase
45+
46+
#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_CORE_KEY_FIELD_FILTER_H_

0 commit comments

Comments
 (0)