Skip to content
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
8004ad0
field path wip
var-const Jan 31, 2018
2080f96
First iteration:
var-const Jan 31, 2018
05cf106
very wip splitting into files
var-const Jan 31, 2018
6c5a60e
split into files, using crtp, ready to port unit tests
var-const Feb 1, 2018
880b115
add unit test file for base path
var-const Feb 1, 2018
5076872
add new files to projects
var-const Feb 1, 2018
0b49e35
add abseil files
var-const Feb 1, 2018
f387147
absl dependencies
var-const Feb 1, 2018
286111e
compilation wip
var-const Feb 1, 2018
6979f62
compiles and constructor test runs!
var-const Feb 1, 2018
e5a0776
constructor test
var-const Feb 1, 2018
7b480b5
add and use shorter assert macro
var-const Feb 1, 2018
e8fa45f
indexing tests succeed
var-const Feb 1, 2018
608bcf0
withoutfirst test works
var-const Feb 1, 2018
fa5aa94
withoutlast test works
var-const Feb 1, 2018
42c106c
concatenation test works
var-const Feb 1, 2018
0d89120
comparison test works
var-const Feb 1, 2018
53e5564
isprefixof test works
var-const Feb 1, 2018
e58bb49
test for failures
var-const Feb 1, 2018
7bb768e
replace base path tests with field path tests
var-const Feb 1, 2018
60317fa
test parsing (found a few bugs)
var-const Feb 2, 2018
3a7c97e
use raw string literals
var-const Feb 2, 2018
62fdfcb
add todos, make vector in base const
var-const Feb 2, 2018
822ef1d
parse test - expect round trip
var-const Feb 2, 2018
4e8aab4
more parsing tests, and the escaped dot is probably a bug
var-const Feb 2, 2018
cf43ba0
start with resourcepath tests
var-const Feb 2, 2018
7761737
remove helper functions with asserts in tests
var-const Feb 2, 2018
6404f06
a weirder string to test parsing, update todo
var-const Feb 2, 2018
ef584ec
all comparison operators + tests
var-const Feb 2, 2018
068e15c
keyfieldpath
var-const Feb 2, 2018
1a071a4
fix wrong name
var-const Feb 2, 2018
6c14417
comments
var-const Feb 2, 2018
0505370
naming
var-const Feb 2, 2018
bb39ef9
style guide order of includes
var-const Feb 2, 2018
355f506
remove reminder
var-const Feb 2, 2018
ad7582b
Merge branch 'master' into varconst-port-paths
var-const Feb 2, 2018
62e45a1
Review feedback.
var-const Feb 5, 2018
b93f2f4
finish review comments
var-const Feb 5, 2018
868254f
Merge branch 'master' into varconst-port-paths
var-const Feb 6, 2018
dfd73cb
Remove accidentally added files
var-const Feb 6, 2018
bb8006c
C++ port: add C++ equivalent of FSTDocumentKey.
var-const Feb 6, 2018
d672a0a
Review feedback
var-const Feb 7, 2018
f288779
Merge branch 'master' into varconst-port-document-key
var-const Feb 7, 2018
e106787
merge leftover
var-const Feb 7, 2018
2ff6c49
Review feedback: make implementation of DocumentKey store a shared_pt…
var-const Feb 7, 2018
6ae8395
style.sh
var-const Feb 7, 2018
8414bb8
Merge branch 'master' into varconst-port-document-key
var-const Feb 8, 2018
fb710fd
Merge branch 'master' into varconst-port-document-key
wilhuff Feb 9, 2018
4913889
review comments
var-const Feb 9, 2018
2f52e1f
Merge branch 'varconst-port-document-key' of github.com:firebase/fire…
var-const Feb 9, 2018
03163e5
add new files to cmakelists
var-const Feb 9, 2018
0bd9898
remove leftover forward declaration
var-const Feb 9, 2018
d507494
fix style
var-const Feb 9, 2018
6583dcc
assert_death -> assert_any_throw; fix incorrect expectation that crea…
var-const Feb 9, 2018
12d37a5
Merge branch 'master' into varconst-port-document-key
var-const Feb 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
ABE6637A201FA81900ED349A /* database_id_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB71064B201FA60300344F18 /* database_id_test.cc */; };
ABF6506C201131F8005F2C74 /* timestamp_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = ABF6506B201131F8005F2C74 /* timestamp_test.cc */; };
AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; };
B6152AD7202A53CB000E5744 /* document_key_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6152AD5202A5385000E5744 /* document_key_test.cc */; };
B686F2AF2023DDEE0028D6BE /* field_path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B686F2AD2023DDB20028D6BE /* field_path_test.cc */; };
B686F2B22025000D0028D6BE /* resource_path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B686F2B02024FFD70028D6BE /* resource_path_test.cc */; };
C4E749275AD0FBDF9F4716A8 /* Pods_SwiftBuildTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32AD40BF6B0E849B07FFD05E /* Pods_SwiftBuildTest.framework */; };
DE03B2D41F2149D600A30B9C /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F5AF195388D20070C39A /* XCTest.framework */; };
DE03B2D51F2149D600A30B9C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; };
Expand Down Expand Up @@ -338,6 +341,9 @@
AB7BAB332012B519001E0872 /* geo_point_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = geo_point_test.cc; path = ../../core/test/firebase/firestore/geo_point_test.cc; sourceTree = "<group>"; };
ABF6506B201131F8005F2C74 /* timestamp_test.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = timestamp_test.cc; sourceTree = "<group>"; };
B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B6152AD5202A5385000E5744 /* document_key_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = document_key_test.cc; sourceTree = "<group>"; };
B686F2AD2023DDB20028D6BE /* field_path_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = field_path_test.cc; sourceTree = "<group>"; };
B686F2B02024FFD70028D6BE /* resource_path_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = resource_path_test.cc; sourceTree = "<group>"; };
CE00BABB5A3AAB44A4C209E2 /* Pods-Firestore_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests/Pods-Firestore_Tests.debug.xcconfig"; sourceTree = "<group>"; };
D3CC3DC5338DCAF43A211155 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
D5B259DAA9149B80D6245B57 /* FSTTestDispatchQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSTTestDispatchQueue.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -565,6 +571,9 @@
AB356EF5200E9D1A0089B766 /* model */ = {
isa = PBXGroup;
children = (
B6152AD5202A5385000E5744 /* document_key_test.cc */,
B686F2B02024FFD70028D6BE /* resource_path_test.cc */,
B686F2AD2023DDB20028D6BE /* field_path_test.cc */,
AB71064B201FA60300344F18 /* database_id_test.cc */,
AB356EF6200EA5EB0089B766 /* field_value_test.cc */,
ABF6506B201131F8005F2C74 /* timestamp_test.cc */,
Expand Down Expand Up @@ -1238,6 +1247,7 @@
5492E0A42021552D00B64F25 /* FSTMemoryQueryCacheTests.mm in Sources */,
5492E0A92021552D00B64F25 /* FSTRemoteDocumentChangeBufferTests.mm in Sources */,
54C2294F1FECABAE007D065B /* log_test.cc in Sources */,
B686F2B22025000D0028D6BE /* resource_path_test.cc in Sources */,
5492E0CA2021557E00B64F25 /* FSTWatchChangeTests.mm in Sources */,
5492E063202154B900B64F25 /* FSTViewSnapshotTest.mm in Sources */,
5492E0BC2021555100B64F25 /* FSTPathTests.mm in Sources */,
Expand All @@ -1247,6 +1257,7 @@
5492E0A82021552D00B64F25 /* FSTLevelDBLocalStoreTests.mm in Sources */,
5491BC721FB44593008B3588 /* FSTIntegrationTestCase.mm in Sources */,
DE2EF0861F3D0B6E003D0CDC /* FSTImmutableSortedDictionary+Testing.m in Sources */,
B686F2AF2023DDEE0028D6BE /* field_path_test.cc in Sources */,
5492E03120213FFC00B64F25 /* FSTLevelDBSpecTests.mm in Sources */,
5492E0B12021552D00B64F25 /* FSTRemoteDocumentCacheTests.mm in Sources */,
5492E0BA2021555100B64F25 /* FSTDocumentSetTests.mm in Sources */,
Expand Down Expand Up @@ -1282,6 +1293,7 @@
5492E0C82021557E00B64F25 /* FSTDatastoreTests.mm in Sources */,
5492E065202154B900B64F25 /* FSTViewTests.mm in Sources */,
5492E03C2021401F00B64F25 /* XCTestCase+Await.mm in Sources */,
B6152AD7202A53CB000E5744 /* document_key_test.cc in Sources */,
54764FAF1FAA21B90085E60A /* FSTGoogleTestTests.mm in Sources */,
AB380D04201BC6E400D97691 /* ordered_code_test.cc in Sources */,
5492E03F2021401F00B64F25 /* FSTHelpers.mm in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions Firestore/Example/Tests/Model/FSTPathTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ - (void)testCanonicalString {
ASSERT_ROUND_TRIP(@"`.foo\\\\`", 1);
ASSERT_ROUND_TRIP(@"`.foo\\\\`.`.foo`", 2);
ASSERT_ROUND_TRIP(@"foo.`\\``.bar", 3);

FSTFieldPath *path = [FSTFieldPath pathWithServerFormat:@"foo\\.bar"];
XCTAssertEqualObjects([path canonicalString], @"`foo.bar`");
XCTAssertEqual(path.length, 1);
}

#undef ASSERT_ROUND_TRIP
Expand Down
3 changes: 3 additions & 0 deletions Firestore/core/src/firebase/firestore/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
cc_library(
firebase_firestore_model
SOURCES
base_path.h
database_id.cc
database_id.h
field_path.cc
field_path.h
field_value.cc
field_value.h
timestamp.cc
Expand Down
180 changes: 180 additions & 0 deletions Firestore/core/src/firebase/firestore/model/base_path.h
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_
71 changes: 71 additions & 0 deletions Firestore/core/src/firebase/firestore/model/document_key.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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;
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return empty;
}

bool operator==(const DocumentKey& lhs, const DocumentKey& rhs) {
return lhs.path() == rhs.path();
}
bool operator!=(const DocumentKey& lhs, const DocumentKey& rhs) {
return lhs.path() != rhs.path();
}
bool operator<(const DocumentKey& lhs, const DocumentKey& rhs) {
return lhs.path() < rhs.path();
}
bool operator<=(const DocumentKey& lhs, const DocumentKey& rhs) {
return lhs.path() <= rhs.path();
}
bool operator>(const DocumentKey& lhs, const DocumentKey& rhs) {
return lhs.path() > rhs.path();
}
bool operator>=(const DocumentKey& lhs, const DocumentKey& rhs) {
return lhs.path() >= rhs.path();
}

} // namespace model
} // namespace firestore
} // namespace firebase
Loading