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

@@ -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;
}