Skip to content

Commit

Permalink
Move defined part to idl.h (#7823)
Browse files Browse the repository at this point in the history
  • Loading branch information
enum-class authored and dbaileychess committed Mar 15, 2023
1 parent a5655f4 commit 688a120
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 11 additions & 0 deletions include/flatbuffers/idl.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ inline const char* TypeName(const BaseType t) {
return nullptr;
}

inline const char* StringOf(const BaseType t) {
switch (t) {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
case BASE_TYPE_##ENUM: return #CTYPE;
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD
default: FLATBUFFERS_ASSERT(0);
}
return "";
}

// clang-format on

struct StructDef;
Expand Down
11 changes: 1 addition & 10 deletions src/idl_gen_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,16 +725,7 @@ class CppGenerator : public BaseGenerator {
if (type.enum_def) return WrapInNameSpace(*type.enum_def);
if (type.base_type == BASE_TYPE_BOOL) return "bool";
}
switch (type.base_type) {
// clang-format off
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
case BASE_TYPE_##ENUM: return #CTYPE;
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD
//clang-format on
default: FLATBUFFERS_ASSERT(0);
}
return "";
return StringOf(type.base_type);
}

// Return a C++ pointer type, specialized to the actual struct/table types,
Expand Down

0 comments on commit 688a120

Please sign in to comment.