Add constant accessors to C++ unions (#4433)

* Add constant accessors to C++ unions

* Remove redundant const pointer return type

* Update generate_code.bat to reflect generate_code.sh

* Add updated generated files

* Remove extra space from generated code

* Update generated files

* Change directory back to tests after generating code
This commit is contained in:
endorph-soft
2017-09-22 06:36:20 +09:30
committed by Wouter van Oortmerssen
parent 28920aff8f
commit 21a8121982
5 changed files with 54 additions and 3 deletions

View File

@@ -162,14 +162,26 @@ struct AnyUnion {
return type == Any_Monster ?
reinterpret_cast<MonsterT *>(value) : nullptr;
}
const MonsterT *AsMonster() const {
return type == Any_Monster ?
reinterpret_cast<const MonsterT *>(value) : nullptr;
}
TestSimpleTableWithEnumT *AsTestSimpleTableWithEnum() {
return type == Any_TestSimpleTableWithEnum ?
reinterpret_cast<TestSimpleTableWithEnumT *>(value) : nullptr;
}
const TestSimpleTableWithEnumT *AsTestSimpleTableWithEnum() const {
return type == Any_TestSimpleTableWithEnum ?
reinterpret_cast<const TestSimpleTableWithEnumT *>(value) : nullptr;
}
MyGame::Example2::MonsterT *AsMyGame_Example2_Monster() {
return type == Any_MyGame_Example2_Monster ?
reinterpret_cast<MyGame::Example2::MonsterT *>(value) : nullptr;
}
const MyGame::Example2::MonsterT *AsMyGame_Example2_Monster() const {
return type == Any_MyGame_Example2_Monster ?
reinterpret_cast<const MyGame::Example2::MonsterT *>(value) : nullptr;
}
};
bool VerifyAny(flatbuffers::Verifier &verifier, const void *obj, Any type);