Commit d5b4db06 authored by endorph-soft's avatar endorph-soft Committed by Wouter van Oortmerssen

C++ Customise prefix/suffix of object API [Issue #4419] (#4422)

* Allow prefix/suffix of C++ Object API classes to be customised

* Address review comments
parent 5808f7fb
...@@ -366,6 +366,8 @@ struct IDLOptions { ...@@ -366,6 +366,8 @@ struct IDLOptions {
bool generate_object_based_api; bool generate_object_based_api;
std::string cpp_object_api_pointer_type; std::string cpp_object_api_pointer_type;
std::string cpp_object_api_string_type; std::string cpp_object_api_string_type;
std::string object_prefix;
std::string object_suffix;
bool union_value_namespacing; bool union_value_namespacing;
bool allow_non_utf8; bool allow_non_utf8;
std::string include_prefix; std::string include_prefix;
...@@ -415,6 +417,7 @@ struct IDLOptions { ...@@ -415,6 +417,7 @@ struct IDLOptions {
escape_proto_identifiers(false), escape_proto_identifiers(false),
generate_object_based_api(false), generate_object_based_api(false),
cpp_object_api_pointer_type("std::unique_ptr"), cpp_object_api_pointer_type("std::unique_ptr"),
object_suffix("T"),
union_value_namespacing(true), union_value_namespacing(true),
allow_non_utf8(false), allow_non_utf8(false),
keep_include_path(false), keep_include_path(false),
......
...@@ -90,6 +90,9 @@ std::string FlatCompiler::GetUsageString(const char* program_name) const { ...@@ -90,6 +90,9 @@ std::string FlatCompiler::GetUsageString(const char* program_name) const {
" --cpp-ptr-type T Set object API pointer type (default std::unique_ptr)\n" " --cpp-ptr-type T Set object API pointer type (default std::unique_ptr)\n"
" --cpp-str-type T Set object API string type (default std::string)\n" " --cpp-str-type T Set object API string type (default std::string)\n"
" T::c_str() and T::length() must be supported\n" " T::c_str() and T::length() must be supported\n"
" --object-prefix Customise class prefix for C++ object-based API.\n"
" --object-suffix Customise class suffix for C++ object-based API.\n"
" Default value is \"T\"\n"
" --no-js-exports Removes Node.js style export lines in JS.\n" " --no-js-exports Removes Node.js style export lines in JS.\n"
" --goog-js-export Uses goog.exports* for closure compiler exporting in JS.\n" " --goog-js-export Uses goog.exports* for closure compiler exporting in JS.\n"
" --go-namespace Generate the overrided namespace in Golang.\n" " --go-namespace Generate the overrided namespace in Golang.\n"
...@@ -201,6 +204,12 @@ int FlatCompiler::Compile(int argc, const char** argv) { ...@@ -201,6 +204,12 @@ int FlatCompiler::Compile(int argc, const char** argv) {
} else if (arg == "--cpp-str-type") { } else if (arg == "--cpp-str-type") {
if (++argi >= argc) Error("missing type following" + arg, true); if (++argi >= argc) Error("missing type following" + arg, true);
opts.cpp_object_api_string_type = argv[argi]; opts.cpp_object_api_string_type = argv[argi];
} else if (arg == "--object-prefix") {
if (++argi >= argc) Error("missing prefix following" + arg, true);
opts.object_prefix = argv[argi];
} else if (arg == "--object-suffix") {
if (++argi >= argc) Error("missing suffix following" + arg, true);
opts.object_suffix = argv[argi];
} else if(arg == "--gen-all") { } else if(arg == "--gen-all") {
opts.generate_all = true; opts.generate_all = true;
opts.include_dependence_headers = false; opts.include_dependence_headers = false;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment