Skip to content

Commit

Permalink
[De]Serialize FieldValue map_values ("Objects") (firebase#878)
Browse files Browse the repository at this point in the history
These can (recursively) contain other FieldValues.
  • Loading branch information
rsgowman committed Mar 8, 2018
1 parent b7750b5 commit 2ae36f1
Show file tree
Hide file tree
Showing 5 changed files with 421 additions and 75 deletions.
11 changes: 5 additions & 6 deletions Firestore/core/src/firebase/firestore/model/field_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ FieldValue& FieldValue::operator=(const FieldValue& value) {
}
case Type::Object: {
// copy-and-swap
std::map<const std::string, const FieldValue> tmp = value.object_value_;
std::map<std::string, FieldValue> tmp = value.object_value_;
std::swap(object_value_, tmp);
break;
}
Expand Down Expand Up @@ -281,13 +281,12 @@ FieldValue FieldValue::ArrayValue(std::vector<FieldValue>&& value) {
}

FieldValue FieldValue::ObjectValue(
const std::map<const std::string, const FieldValue>& value) {
std::map<const std::string, const FieldValue> copy(value);
const std::map<std::string, FieldValue>& value) {
std::map<std::string, FieldValue> copy(value);
return ObjectValue(std::move(copy));
}

FieldValue FieldValue::ObjectValue(
std::map<const std::string, const FieldValue>&& value) {
FieldValue FieldValue::ObjectValue(std::map<std::string, FieldValue>&& value) {
FieldValue result;
result.SwitchTo(Type::Object);
std::swap(result.object_value_, value);
Expand Down Expand Up @@ -418,7 +417,7 @@ void FieldValue::SwitchTo(const Type type) {
new (&array_value_) std::vector<FieldValue>();
break;
case Type::Object:
new (&object_value_) std::map<const std::string, const FieldValue>();
new (&object_value_) std::map<std::string, FieldValue>();
break;
default: {} // The other types where there is nothing to worry about.
}
Expand Down
13 changes: 8 additions & 5 deletions Firestore/core/src/firebase/firestore/model/field_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ class FieldValue {
return string_value_;
}

const std::map<std::string, FieldValue>& object_value() const {
FIREBASE_ASSERT(tag_ == Type::Object);
return object_value_;
}

/** factory methods. */
static const FieldValue& NullValue();
static const FieldValue& TrueValue();
Expand All @@ -134,10 +139,8 @@ class FieldValue {
static FieldValue GeoPointValue(const GeoPoint& value);
static FieldValue ArrayValue(const std::vector<FieldValue>& value);
static FieldValue ArrayValue(std::vector<FieldValue>&& value);
static FieldValue ObjectValue(
const std::map<const std::string, const FieldValue>& value);
static FieldValue ObjectValue(
std::map<const std::string, const FieldValue>&& value);
static FieldValue ObjectValue(const std::map<std::string, FieldValue>& value);
static FieldValue ObjectValue(std::map<std::string, FieldValue>&& value);

friend bool operator<(const FieldValue& lhs, const FieldValue& rhs);

Expand All @@ -164,7 +167,7 @@ class FieldValue {
firebase::firestore::model::ReferenceValue reference_value_;
GeoPoint geo_point_value_;
std::vector<FieldValue> array_value_;
std::map<const std::string, const FieldValue> object_value_;
std::map<std::string, FieldValue> object_value_;
};
};

Expand Down
Loading

0 comments on commit 2ae36f1

Please sign in to comment.