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

@@ -84,26 +84,50 @@ struct CharacterUnion {
return type == Character_MuLan ?
reinterpret_cast<AttackerT *>(value) : nullptr;
}
const AttackerT *AsMuLan() const {
return type == Character_MuLan ?
reinterpret_cast<const AttackerT *>(value) : nullptr;
}
Rapunzel *AsRapunzel() {
return type == Character_Rapunzel ?
reinterpret_cast<Rapunzel *>(value) : nullptr;
}
const Rapunzel *AsRapunzel() const {
return type == Character_Rapunzel ?
reinterpret_cast<const Rapunzel *>(value) : nullptr;
}
BookReader *AsBelle() {
return type == Character_Belle ?
reinterpret_cast<BookReader *>(value) : nullptr;
}
const BookReader *AsBelle() const {
return type == Character_Belle ?
reinterpret_cast<const BookReader *>(value) : nullptr;
}
BookReader *AsBookFan() {
return type == Character_BookFan ?
reinterpret_cast<BookReader *>(value) : nullptr;
}
const BookReader *AsBookFan() const {
return type == Character_BookFan ?
reinterpret_cast<const BookReader *>(value) : nullptr;
}
std::string *AsOther() {
return type == Character_Other ?
reinterpret_cast<std::string *>(value) : nullptr;
}
const std::string *AsOther() const {
return type == Character_Other ?
reinterpret_cast<const std::string *>(value) : nullptr;
}
std::string *AsUnused() {
return type == Character_Unused ?
reinterpret_cast<std::string *>(value) : nullptr;
}
const std::string *AsUnused() const {
return type == Character_Unused ?
reinterpret_cast<const std::string *>(value) : nullptr;
}
};
bool VerifyCharacter(flatbuffers::Verifier &verifier, const void *obj, Character type);