mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-23 17:00:03 +00:00
C++: mini_reflect: Add DefaultTypeTable (#4614)
* mini_reflect: Add DefaultTypeTable
Currently it's very easy to make a mistake when it comes to
instantiating the TypeTable to print a buffer because it is not type
safe.
This will allow us to write safer cpp code:
flatbuffers::FlatBufferToString(reinterpret_cast<const uint8_t *>(&t),
decltype(t)::DefaultTypeTable());
* c++: mini_reflect: update generated code
* Ensure types and names are set for mini_reflect
* c++: mini_refelct: update unit tests with new typed TypeTable
* Adding PR feedback of sylte and naming convention
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
daf0a420be
commit
36f8564846
@@ -16,6 +16,14 @@ struct BookReader;
|
||||
struct Movie;
|
||||
struct MovieT;
|
||||
|
||||
inline flatbuffers::TypeTable *AttackerTypeTable();
|
||||
|
||||
inline flatbuffers::TypeTable *RapunzelTypeTable();
|
||||
|
||||
inline flatbuffers::TypeTable *BookReaderTypeTable();
|
||||
|
||||
inline flatbuffers::TypeTable *MovieTypeTable();
|
||||
|
||||
enum Character {
|
||||
Character_NONE = 0,
|
||||
Character_MuLan = 1,
|
||||
@@ -183,6 +191,9 @@ struct AttackerT : public flatbuffers::NativeTable {
|
||||
|
||||
struct Attacker FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
typedef AttackerT NativeTableType;
|
||||
static flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return AttackerTypeTable();
|
||||
}
|
||||
enum {
|
||||
VT_SWORD_ATTACK_DAMAGE = 4
|
||||
};
|
||||
@@ -240,6 +251,9 @@ struct MovieT : public flatbuffers::NativeTable {
|
||||
|
||||
struct Movie FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
typedef MovieT NativeTableType;
|
||||
static flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return MovieTypeTable();
|
||||
}
|
||||
enum {
|
||||
VT_MAIN_CHARACTER_TYPE = 4,
|
||||
VT_MAIN_CHARACTER = 6,
|
||||
@@ -595,14 +609,6 @@ inline void CharacterUnion::Reset() {
|
||||
type = Character_NONE;
|
||||
}
|
||||
|
||||
inline flatbuffers::TypeTable *AttackerTypeTable();
|
||||
|
||||
inline flatbuffers::TypeTable *RapunzelTypeTable();
|
||||
|
||||
inline flatbuffers::TypeTable *BookReaderTypeTable();
|
||||
|
||||
inline flatbuffers::TypeTable *MovieTypeTable();
|
||||
|
||||
inline flatbuffers::TypeTable *CharacterTypeTable() {
|
||||
static flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_SEQUENCE, 0, -1 },
|
||||
|
||||
Reference in New Issue
Block a user