mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 03:38:06 +00:00
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:
committed by
Wouter van Oortmerssen
parent
b8f5f84437
commit
1a27c7017a
@@ -75,7 +75,7 @@ struct TableInNestedNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
return GetField<int32_t>(VT_FOO, 0);
|
||||
}
|
||||
bool mutate_foo(int32_t _foo) {
|
||||
return SetField(VT_FOO, _foo);
|
||||
return SetField<int32_t>(VT_FOO, _foo, 0);
|
||||
}
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user