From bfa0e40795ba676fd02d616794cce1c9b2d6a95f Mon Sep 17 00:00:00 2001 From: zxu Date: Thu, 25 Jan 2018 09:14:19 -0500 Subject: Implement the rest of FieldValue types for C++ (#687) * implement FieldValue for null and boolean. * Implement number and string FieldValue. * Implement object FieldValue. * implement timestamp FieldValue. * Implement number and string FieldValue. * implement public type `Blob` and `GeoPoint` * implement Blob FieldValue * Implement GeoPoint FieldValue * refactoring `Blob` --- .../src/firebase/firestore/model/field_value.h | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'Firestore/core/src/firebase/firestore/model/field_value.h') diff --git a/Firestore/core/src/firebase/firestore/model/field_value.h b/Firestore/core/src/firebase/firestore/model/field_value.h index 781e34f..bb6594f 100644 --- a/Firestore/core/src/firebase/firestore/model/field_value.h +++ b/Firestore/core/src/firebase/firestore/model/field_value.h @@ -17,13 +17,27 @@ #ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_FIELD_VALUE_H_ #define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_MODEL_FIELD_VALUE_H_ +#include + +#include #include +#include #include +#include "Firestore/core/include/firebase/firestore/geo_point.h" +#include "Firestore/core/src/firebase/firestore/model/timestamp.h" + namespace firebase { namespace firestore { namespace model { +struct ServerTimestamp { + Timestamp local_write_time; + Timestamp previous_value; + // TODO(zxu123): adopt absl::optional once abseil is ported. + bool has_previous_value_; +}; + /** * tagged-union class representing an immutable data value as stored in * Firestore. FieldValue represents all the different kinds of values @@ -78,8 +92,25 @@ class FieldValue { static const FieldValue& TrueValue(); static const FieldValue& FalseValue(); static const FieldValue& BooleanValue(bool value); + static const FieldValue& NanValue(); + static FieldValue IntegerValue(int64_t value); + static FieldValue DoubleValue(double value); + static FieldValue TimestampValue(const Timestamp& value); + static FieldValue ServerTimestampValue(const Timestamp& local_write_time, + const Timestamp& previous_value); + static FieldValue ServerTimestampValue(const Timestamp& local_write_time); + static FieldValue StringValue(const char* value); + static FieldValue StringValue(const std::string& value); + static FieldValue StringValue(std::string&& value); + static FieldValue BlobValue(const uint8_t* source, size_t size); + // static FieldValue ReferenceValue(); + static FieldValue GeoPointValue(const GeoPoint& value); static FieldValue ArrayValue(const std::vector& value); static FieldValue ArrayValue(std::vector&& value); + static FieldValue ObjectValue( + const std::map& value); + static FieldValue ObjectValue( + std::map&& value); friend bool operator<(const FieldValue& lhs, const FieldValue& rhs); @@ -96,7 +127,15 @@ class FieldValue { union { // There is no null type as tag_ alone is enough for Null FieldValue. bool boolean_value_; + int64_t integer_value_; + double double_value_; + Timestamp timestamp_value_; + ServerTimestamp server_timestamp_value_; + std::string string_value_; + std::vector blob_value_; + GeoPoint geo_point_value_; std::vector array_value_; + std::map object_value_; }; }; -- cgit v1.2.3