Skip to content

[De]Serialize FieldValue map_values ("Objects") #878

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 10 commits into from
Mar 8, 2018
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