forked from BigfootDev/flatbuffers
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
@@ -1646,9 +1646,9 @@ class Table {
|
||||
return field_offset ? reinterpret_cast<P>(p) : nullptr;
|
||||
}
|
||||
|
||||
template<typename T> bool SetField(voffset_t field, T val) {
|
||||
template<typename T> bool SetField(voffset_t field, T val, T def) {
|
||||
auto field_offset = GetOptionalFieldOffset(field);
|
||||
if (!field_offset) return false;
|
||||
if (!field_offset) return val == def;
|
||||
WriteScalar(data_ + field_offset, val);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user