summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaman <100295082+enum-class@users.noreply.github.com>2023-02-18 12:34:32 +0800
committerGitHub <noreply@github.com>2023-02-17 20:34:32 -0800
commitf7a75173f171b5edae59a1ff28e5b408057e60ac (patch)
tree5f221c13d436520daa71e0647ff73ab3582aec6c
parenta56f9ec50e908362e20254fcef28e62a2f148d91 (diff)
downloadflatbuffers-f7a75173f171b5edae59a1ff28e5b408057e60ac.tar.gz
flatbuffers-f7a75173f171b5edae59a1ff28e5b408057e60ac.tar.bz2
flatbuffers-f7a75173f171b5edae59a1ff28e5b408057e60ac.zip
Move defined part to idl.h (#7823)
-rw-r--r--include/flatbuffers/idl.h11
-rw-r--r--src/idl_gen_cpp.cpp11
2 files changed, 12 insertions, 10 deletions
diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h
index 9ad6edcd..57f83410 100644
--- a/include/flatbuffers/idl.h
+++ b/include/flatbuffers/idl.h
@@ -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;
diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp
index 1033a895..67f228a2 100644
--- a/src/idl_gen_cpp.cpp
+++ b/src/idl_gen_cpp.cpp
@@ -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,