Default Arguments for Mutators C++ [Updated] (#6872)

* CPP Default Value Generation in Mutators

If the mutator is for a value that is compatible with having a default value, then the single parameter becomes a default parameter. With this, a value can be mutated to it's default value without storing the default value, as that will be stored with the mutate function.
Fixed Casting When Generating Default for Enum Value

Added support for typecasting an int default value into the correct enum type in the default parameter. This fixed the issue of trying to use set a strongly typed enum parameter to an int which fails type checking.
Fixed Boolean Edge Case

Boolean types generate 0 != 0 when generating the underlying type which appears to be unique to the boolean type so it is now checked and the proper default value generated. It may be beneficial to check if it is instead an enum type, however the seeming edge case nature is why boolean was chosen to be checked.
Updated Generated Files

Regenerated the auto generated files to reflect the new changes.
Updated Remaining Files

Should fix auto generated header files that were not updated.

* Unified Repeated Code

Relocated identical append code to outside of conditional. Also changed 'casted' default value name from FIELD to INTERFACE to more accurately describe it.

* Moved Field Name Outside Conditional

Removed duplicate _{{FIELD_NAME}} and moved to unified append.
This commit is contained in:
T Sprecher
2021-09-30 19:44:39 -04:00
committed by GitHub
parent a592f4c89e
commit 45e5642e91
11 changed files with 141 additions and 133 deletions

View File

@@ -52,49 +52,49 @@ struct MonsterExtra FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
double d0() const {
return GetField<double>(VT_D0, std::numeric_limits<double>::quiet_NaN());
}
bool mutate_d0(double _d0) {
bool mutate_d0(double _d0 = std::numeric_limits<double>::quiet_NaN()) {
return SetField<double>(VT_D0, _d0, std::numeric_limits<double>::quiet_NaN());
}
double d1() const {
return GetField<double>(VT_D1, std::numeric_limits<double>::quiet_NaN());
}
bool mutate_d1(double _d1) {
bool mutate_d1(double _d1 = std::numeric_limits<double>::quiet_NaN()) {
return SetField<double>(VT_D1, _d1, std::numeric_limits<double>::quiet_NaN());
}
double d2() const {
return GetField<double>(VT_D2, std::numeric_limits<double>::infinity());
}
bool mutate_d2(double _d2) {
bool mutate_d2(double _d2 = std::numeric_limits<double>::infinity()) {
return SetField<double>(VT_D2, _d2, std::numeric_limits<double>::infinity());
}
double d3() const {
return GetField<double>(VT_D3, -std::numeric_limits<double>::infinity());
}
bool mutate_d3(double _d3) {
bool mutate_d3(double _d3 = -std::numeric_limits<double>::infinity()) {
return SetField<double>(VT_D3, _d3, -std::numeric_limits<double>::infinity());
}
float f0() const {
return GetField<float>(VT_F0, std::numeric_limits<float>::quiet_NaN());
}
bool mutate_f0(float _f0) {
bool mutate_f0(float _f0 = std::numeric_limits<float>::quiet_NaN()) {
return SetField<float>(VT_F0, _f0, std::numeric_limits<float>::quiet_NaN());
}
float f1() const {
return GetField<float>(VT_F1, std::numeric_limits<float>::quiet_NaN());
}
bool mutate_f1(float _f1) {
bool mutate_f1(float _f1 = std::numeric_limits<float>::quiet_NaN()) {
return SetField<float>(VT_F1, _f1, std::numeric_limits<float>::quiet_NaN());
}
float f2() const {
return GetField<float>(VT_F2, std::numeric_limits<float>::infinity());
}
bool mutate_f2(float _f2) {
bool mutate_f2(float _f2 = std::numeric_limits<float>::infinity()) {
return SetField<float>(VT_F2, _f2, std::numeric_limits<float>::infinity());
}
float f3() const {
return GetField<float>(VT_F3, -std::numeric_limits<float>::infinity());
}
bool mutate_f3(float _f3) {
bool mutate_f3(float _f3 = -std::numeric_limits<float>::infinity()) {
return SetField<float>(VT_F3, _f3, -std::numeric_limits<float>::infinity());
}
const flatbuffers::Vector<double> *dvec() const {