-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C++ port: add C++ equivalent of FSTDocumentKey. #762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 41 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
8004ad0
field path wip
var-const 2080f96
First iteration:
var-const 05cf106
very wip splitting into files
var-const 6c5a60e
split into files, using crtp, ready to port unit tests
var-const 880b115
add unit test file for base path
var-const 5076872
add new files to projects
var-const 0b49e35
add abseil files
var-const f387147
absl dependencies
var-const 286111e
compilation wip
var-const 6979f62
compiles and constructor test runs!
var-const e5a0776
constructor test
var-const 7b480b5
add and use shorter assert macro
var-const e8fa45f
indexing tests succeed
var-const 608bcf0
withoutfirst test works
var-const fa5aa94
withoutlast test works
var-const 42c106c
concatenation test works
var-const 0d89120
comparison test works
var-const 53e5564
isprefixof test works
var-const e58bb49
test for failures
var-const 7bb768e
replace base path tests with field path tests
var-const 60317fa
test parsing (found a few bugs)
var-const 3a7c97e
use raw string literals
var-const 62fdfcb
add todos, make vector in base const
var-const 822ef1d
parse test - expect round trip
var-const 4e8aab4
more parsing tests, and the escaped dot is probably a bug
var-const cf43ba0
start with resourcepath tests
var-const 7761737
remove helper functions with asserts in tests
var-const 6404f06
a weirder string to test parsing, update todo
var-const ef584ec
all comparison operators + tests
var-const 068e15c
keyfieldpath
var-const 1a071a4
fix wrong name
var-const 6c14417
comments
var-const 0505370
naming
var-const bb39ef9
style guide order of includes
var-const 355f506
remove reminder
var-const ad7582b
Merge branch 'master' into varconst-port-paths
var-const 62e45a1
Review feedback.
var-const b93f2f4
finish review comments
var-const 868254f
Merge branch 'master' into varconst-port-paths
var-const dfd73cb
Remove accidentally added files
var-const bb8006c
C++ port: add C++ equivalent of FSTDocumentKey.
var-const d672a0a
Review feedback
var-const f288779
Merge branch 'master' into varconst-port-document-key
var-const e106787
merge leftover
var-const 2ff6c49
Review feedback: make implementation of DocumentKey store a shared_pt…
var-const 6ae8395
style.sh
var-const 8414bb8
Merge branch 'master' into varconst-port-document-key
var-const fb710fd
Merge branch 'master' into varconst-port-document-key
wilhuff 4913889
review comments
var-const 2f52e1f
Merge branch 'varconst-port-document-key' of github.com:firebase/fire…
var-const 03163e5
add new files to cmakelists
var-const 0bd9898
remove leftover forward declaration
var-const d507494
fix style
var-const 6583dcc
assert_death -> assert_any_throw; fix incorrect expectation that crea…
var-const 12d37a5
Merge branch 'master' into varconst-port-document-key
var-const File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 180 additions & 0 deletions
180
Firestore/core/src/firebase/firestore/model/base_path.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| /* | ||
| * Copyright 2018 Google | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_BASE_PATH_H_ | ||
| #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_BASE_PATH_H_ | ||
|
|
||
| #include <algorithm> | ||
| #include <cctype> | ||
| #include <initializer_list> | ||
| #include <string> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "Firestore/core/src/firebase/firestore/util/firebase_assert.h" | ||
|
|
||
| namespace firebase { | ||
| namespace firestore { | ||
| namespace model { | ||
| namespace impl { | ||
|
|
||
| /** | ||
| * BasePath represents a path sequence in the Firestore database. It is composed | ||
| * of an ordered sequence of string segments. | ||
| * | ||
| * BasePath is reassignable and movable. Apart from those, all other mutating | ||
| * operations return new independent instances. | ||
| * | ||
| * ## Subclassing Notes | ||
| * | ||
| * BasePath is strictly meant as a base class for concrete implementations. It | ||
| * doesn't contain a single virtual method, can't be instantiated, and should | ||
| * never be used in any polymorphic way. BasePath is templated to allow static | ||
| * factory methods to return objects of the derived class (the expected | ||
| * inheritance would use CRTP: struct Derived : BasePath<Derived>). | ||
| */ | ||
| template <typename T> | ||
| class BasePath { | ||
| protected: | ||
| using SegmentsT = std::vector<std::string>; | ||
|
|
||
| public: | ||
| using const_iterator = SegmentsT::const_iterator; | ||
|
|
||
| /** Returns i-th segment of the path. */ | ||
| const std::string& operator[](const size_t i) const { | ||
| FIREBASE_ASSERT_MESSAGE(i < segments_.size(), "index %u out of range", i); | ||
| return segments_[i]; | ||
| } | ||
|
|
||
| /** Returns the first segment of the path. */ | ||
| const std::string& first_segment() const { | ||
| FIREBASE_ASSERT_MESSAGE(!empty(), "Cannot call first_segment on empty path"); | ||
| return segments_[0]; | ||
| } | ||
| /** Returns the last segment of the path. */ | ||
| const std::string& last_segment() const { | ||
| FIREBASE_ASSERT_MESSAGE(!empty(), "Cannot call last_segment on empty path"); | ||
| return segments_[size() - 1]; | ||
| } | ||
|
|
||
| size_t size() const { | ||
| return segments_.size(); | ||
| } | ||
| bool empty() const { | ||
| return segments_.empty(); | ||
| } | ||
|
|
||
| const_iterator begin() const { | ||
| return segments_.begin(); | ||
| } | ||
| const_iterator end() const { | ||
| return segments_.end(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a new path which is the result of concatenating this path with an | ||
| * additional segment. | ||
| */ | ||
| T Append(const std::string& segment) const { | ||
| auto appended = segments_; | ||
| appended.push_back(segment); | ||
| return T{std::move(appended)}; | ||
| } | ||
| T Append(std::string&& segment) const { | ||
| auto appended = segments_; | ||
| appended.push_back(std::move(segment)); | ||
| return T{std::move(appended)}; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a new path which is the result of concatenating this path with an | ||
| * another path. | ||
| */ | ||
| T Append(const T& path) const { | ||
| auto appended = segments_; | ||
| appended.insert(appended.end(), path.begin(), path.end()); | ||
| return T{std::move(appended)}; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a new path which is the result of omitting the first n segments of | ||
| * this path. | ||
| */ | ||
| T PopFirst(const size_t n = 1) const { | ||
| FIREBASE_ASSERT_MESSAGE(n <= size(), | ||
| "Cannot call PopFirst(%u) on path of length %u", n, | ||
| size()); | ||
| return T{begin() + n, end()}; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a new path which is the result of omitting the last segment of | ||
| * this path. | ||
| */ | ||
| T PopLast() const { | ||
| FIREBASE_ASSERT_MESSAGE(!empty(), "Cannot call PopLast() on empty path"); | ||
| return T{begin(), end() - 1}; | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if this path is a prefix of the given path. | ||
| * | ||
| * Empty path is a prefix of any path. Any path is a prefix of itself. | ||
| */ | ||
| bool IsPrefixOf(const T& rhs) const { | ||
| return size() <= rhs.size() && std::equal(begin(), end(), rhs.begin()); | ||
| } | ||
|
|
||
| bool operator==(const BasePath& rhs) const { | ||
| return segments_ == rhs.segments_; | ||
| } | ||
| bool operator!=(const BasePath& rhs) const { | ||
| return segments_ != rhs.segments_; | ||
| } | ||
| bool operator<(const BasePath& rhs) const { | ||
| return segments_ < rhs.segments_; | ||
| } | ||
| bool operator>(const BasePath& rhs) const { | ||
| return segments_ > rhs.segments_; | ||
| } | ||
| bool operator<=(const BasePath& rhs) const { | ||
| return segments_ <= rhs.segments_; | ||
| } | ||
| bool operator>=(const BasePath& rhs) const { | ||
| return segments_ >= rhs.segments_; | ||
| } | ||
|
|
||
| protected: | ||
| BasePath() = default; | ||
| template <typename IterT> | ||
| BasePath(const IterT begin, const IterT end) : segments_{begin, end} { | ||
| } | ||
| BasePath(std::initializer_list<std::string> list) : segments_{list} { | ||
| } | ||
| BasePath(SegmentsT&& segments) : segments_{std::move(segments)} { | ||
| } | ||
|
|
||
| private: | ||
| SegmentsT segments_; | ||
| }; | ||
|
|
||
| } // namespace impl | ||
| } // namespace model | ||
| } // namespace firestore | ||
| } // namespace firebase | ||
|
|
||
| #endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_BASE_PATH_H_ |
52 changes: 52 additions & 0 deletions
52
Firestore/core/src/firebase/firestore/model/document_key.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright 2018 Google | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "Firestore/core/src/firebase/firestore/model/document_key.h" | ||
|
|
||
| #include <utility> | ||
|
|
||
| #include "Firestore/core/src/firebase/firestore/util/firebase_assert.h" | ||
|
|
||
| namespace firebase { | ||
| namespace firestore { | ||
| namespace model { | ||
|
|
||
| namespace { | ||
|
|
||
| void AssertValidPath(const ResourcePath& path) { | ||
| FIREBASE_ASSERT_MESSAGE(DocumentKey::IsDocumentKey(path), | ||
| "invalid document key path: %s", | ||
| path.CanonicalString().c_str()); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| DocumentKey::DocumentKey(const ResourcePath& path) : path_{path} { | ||
| AssertValidPath(path_); | ||
| } | ||
|
|
||
| DocumentKey::DocumentKey(ResourcePath&& path) : path_{std::move(path)} { | ||
| AssertValidPath(path_); | ||
| } | ||
|
|
||
| const DocumentKey& DocumentKey::Empty() { | ||
| static DocumentKey empty; | ||
| return empty; | ||
| } | ||
|
|
||
| } // namespace model | ||
| } // namespace firestore | ||
| } // namespace firebase | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
static const DocumentKey empty?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.