aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/core/src/firebase/firestore/model/field_value.h
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2018-04-23 10:51:52 -0400
committerGravatar GitHub <noreply@github.com>2018-04-23 10:51:52 -0400
commit12d9358c96d8de816254992b20d263e8ad9aac63 (patch)
tree4dde38730c95d6ec2582ccdbc1eba12a6f432619 /Firestore/core/src/firebase/firestore/model/field_value.h
parentb2cf8c6d3df3ebe792c4b3932f05ddfc7f477959 (diff)
Update `FieldValue` For Porting `Mutation`s to C++ (#1144)
* update FieldValue for Mutation implementation * address changes * address changes * address change
Diffstat (limited to 'Firestore/core/src/firebase/firestore/model/field_value.h')
-rw-r--r--Firestore/core/src/firebase/firestore/model/field_value.h41
1 files changed, 37 insertions, 4 deletions
diff --git a/Firestore/core/src/firebase/firestore/model/field_value.h b/Firestore/core/src/firebase/firestore/model/field_value.h
index 3c5af9c..0f7dfc4 100644
--- a/Firestore/core/src/firebase/firestore/model/field_value.h
+++ b/Firestore/core/src/firebase/firestore/model/field_value.h
@@ -27,7 +27,9 @@
#include "Firestore/core/include/firebase/firestore/timestamp.h"
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
+#include "Firestore/core/src/firebase/firestore/model/field_path.h"
#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h"
+#include "absl/types/optional.h"
namespace firebase {
namespace firestore {
@@ -35,9 +37,7 @@ namespace model {
struct ServerTimestamp {
Timestamp local_write_time;
- Timestamp previous_value;
- // TODO(zxu123): adopt absl::optional once abseil is ported.
- bool has_previous_value_;
+ absl::optional<Timestamp> previous_value;
};
struct ReferenceValue {
@@ -118,16 +118,49 @@ class FieldValue {
return integer_value_;
}
+ Timestamp timestamp_value() const {
+ FIREBASE_ASSERT(tag_ == Type::Timestamp);
+ return timestamp_value_;
+ }
+
const std::string& string_value() const {
FIREBASE_ASSERT(tag_ == Type::String);
return string_value_;
}
- const ObjectValue object_value() const {
+ ObjectValue object_value() const {
FIREBASE_ASSERT(tag_ == Type::Object);
return ObjectValue{object_value_};
}
+ /**
+ * Returns a FieldValue with the field at the named path set to value.
+ * Any absent parent of the field will also be created accordingly.
+ *
+ * @param field_path The field path to set. Cannot be empty.
+ * @param value The value to set.
+ * @return A new FieldValue with the field set.
+ */
+ FieldValue Set(const FieldPath& field_path, FieldValue value) const;
+
+ /**
+ * Returns a FieldValue with the field path deleted. If there is no field at
+ * the specified path, the returned value is an identical copy.
+ *
+ * @param field_path The field path to remove. Cannot be empty.
+ * @return A new FieldValue with the field path removed.
+ */
+ FieldValue Delete(const FieldPath& field_path) const;
+
+ /**
+ * Returns the value at the given path or absl::nullopt. If the path is empty,
+ * an identical copy of the FieldValue is returned.
+ *
+ * @param field_path the path to search.
+ * @return The value at the path or absl::nullopt if it doesn't exist.
+ */
+ absl::optional<FieldValue> Get(const FieldPath& field_path) const;
+
/** factory methods. */
static const FieldValue& NullValue();
static const FieldValue& TrueValue();