summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDavid P. Sicilia <dpacbach@users.noreply.github.com>2021-03-05 13:01:40 -0500
committerGitHub <noreply@github.com>2021-03-05 10:01:40 -0800
commita69815f72c7432a838f7163ecdcf6b30c8b3bf35 (patch)
treeab61ecc8a9808584ee7fc70869f2a0e212fdf916 /include
parent4033ff5892ed6a5e083811fa13c7f9094d46d5db (diff)
downloadflatbuffers-a69815f72c7432a838f7163ecdcf6b30c8b3bf35.tar.gz
flatbuffers-a69815f72c7432a838f7163ecdcf6b30c8b3bf35.tar.bz2
flatbuffers-a69815f72c7432a838f7163ecdcf6b30c8b3bf35.zip
[C++17] Add compile-time reflection for fields. (#6324)
* [C++17] Add compile-time reflection for fields. Included in this commit is the following: - The C++ generator has been modified so that, when in C++17 mode, it will emit Table and Struct field traits that can be used at com- pile time as a form of static reflection. This includes field types, field names, and a tuple of field getter results. - Diffs to the cpp17 generated files. No other generated files are affected. - A unit test that also serves as an example. It demonstrates how to use the full power of this reflection to implement a full recursive JSON-like stringifier for Flatbuffers types, but without needing any runtime access to the *.fbs definition files; the computation is done using only static reflection. Tested on Linux with gcc 10.2.0. Fixes #6285. * Fix int-conversion warning on MSVC. * Try to fix std::to_string ambiguity on MSVC. * Fix clang-format diffs. * Fix more clang-format diffs. * Fix last clang-format diff. * Enable C++17 build/test for VC 19 platform in CI. * Forgot to add value to cmake command line variable. * Various fixes/changes in response to @vglavnyy's feedback. * Replace "fields pack" with index-based getters. * Fix MSVC error. * Fix clang-format diffs. * getter_for method returns result instead of address-of-getter. * Next round of reviewer suggestions. * Use type instead of hardcoded struct name. * Fix clang-format diff. * Add test for FieldType since it is not used in the stringify test. * Add fields_number field to Traits struct. * Add --cpp-static-reflection flag and put those features behind it. * Fix clang-format diffs. * Remove <tuple> include.
Diffstat (limited to 'include')
-rw-r--r--include/flatbuffers/idl.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h
index 0e9a3bcd..d9ef95b4 100644
--- a/include/flatbuffers/idl.h
+++ b/include/flatbuffers/idl.h
@@ -588,6 +588,7 @@ struct IDLOptions {
bool cs_gen_json_serializer;
std::vector<std::string> cpp_includes;
std::string cpp_std;
+ bool cpp_static_reflection;
std::string proto_namespace_suffix;
std::string filename_suffix;
std::string filename_extension;
@@ -673,6 +674,7 @@ struct IDLOptions {
force_defaults(false),
java_primitive_has_method(false),
cs_gen_json_serializer(false),
+ cpp_static_reflection(false),
filename_suffix("_generated"),
filename_extension(),
no_warnings(false),