C++: Add default value handling to mutation/SetField code (#4230)

* Add default value handling to mutation/SetField code

* Shorten reflection SetField impl

* Modify impl to work with C++03

* Add more mutation tests

* Fail SetField if non-scalar

* Add IsScalar/IsInteger/IsFloat for reflection::BaseType

* Use new IsScalar/IsInteger/IsFloat in reflection SetField

* Assume scalar is either int or float
This commit is contained in:
Lawrence Chan
2017-03-20 19:36:27 -05:00
committed by Wouter van Oortmerssen
parent b8f5f84437
commit 1a27c7017a
9 changed files with 81 additions and 33 deletions

View File

@@ -40,7 +40,7 @@ struct TableInFirstNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
return static_cast<NamespaceA::NamespaceB::EnumInNestedNS>(GetField<int8_t>(VT_FOO_ENUM, 0));
}
bool mutate_foo_enum(NamespaceA::NamespaceB::EnumInNestedNS _foo_enum) {
return SetField(VT_FOO_ENUM, static_cast<int8_t>(_foo_enum));
return SetField<int8_t>(VT_FOO_ENUM, static_cast<int8_t>(_foo_enum), 0);
}
const NamespaceA::NamespaceB::StructInNestedNS *foo_struct() const {
return GetStruct<const NamespaceA::NamespaceB::StructInNestedNS *>(VT_FOO_STRUCT);