diff options
author | Derek Bailey <derekbailey@google.com> | 2019-11-07 12:22:54 -0800 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-11-07 12:22:54 -0800 |
commit | f0f0efe7b8bb1e32e7ea21b17bdea28835ad81c4 (patch) | |
tree | eb0c5f977400166f7c6f8067d7764d9753aa1ea3 /src/idl_gen_cpp.cpp | |
parent | e837d5a296c725d141802777808aaff944e7b427 (diff) | |
download | flatbuffers-f0f0efe7b8bb1e32e7ea21b17bdea28835ad81c4.tar.gz |
[C++] Refactor to conform to Google C++ style guide (#5608)
* Automatic refractor of C++ headers to Google C++ style guide
* Automatic refractor of C++ source to Google C++ style guide
* Automatic refractor of C++ tests to Google C++ style guide
* Fixed clang-format issues by running clang-format twice to correct itself. Kotlin was missing clang-format on after turning it off, so it was changed,
Diffstat (limited to 'src/idl_gen_cpp.cpp')
-rw-r--r-- | src/idl_gen_cpp.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index d7b3abb5..706732b0 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -16,13 +16,13 @@ // independent from idl_parser, since this code is not needed for most clients +#include <unordered_set> + #include "flatbuffers/code_generators.h" #include "flatbuffers/flatbuffers.h" #include "flatbuffers/idl.h" #include "flatbuffers/util.h" -#include <unordered_set> - namespace flatbuffers { // Pedantic warning free version of toupper(). @@ -208,9 +208,7 @@ class CppGenerator : public BaseGenerator { for (std::size_t i = 0; i < parser_.opts.cpp_includes.size(); ++i) { code_ += "#include \"" + parser_.opts.cpp_includes[i] + "\""; } - if (!parser_.opts.cpp_includes.empty()) { - code_ += ""; - } + if (!parser_.opts.cpp_includes.empty()) { code_ += ""; } } std::string EscapeKeyword(const std::string &name) const { @@ -577,7 +575,9 @@ class CppGenerator : public BaseGenerator { } case BASE_TYPE_UNION: // fall through - default: { return "void"; } + default: { + return "void"; + } } } @@ -696,7 +696,9 @@ class CppGenerator : public BaseGenerator { case BASE_TYPE_UNION: { return type.enum_def->name + "Union"; } - default: { return GenTypeBasic(type, true); } + default: { + return GenTypeBasic(type, true); + } } } @@ -1163,7 +1165,8 @@ class CppGenerator : public BaseGenerator { code_ += " void Set(T&& val) {"; code_ += " using RT = typename std::remove_reference<T>::type;"; code_ += " Reset();"; - code_ += " type = {{NAME}}Traits<typename RT::TableType>::enum_value;"; + code_ += + " type = {{NAME}}Traits<typename RT::TableType>::enum_value;"; code_ += " if (type != {{NONE}}) {"; code_ += " value = new RT(std::forward<T>(val));"; code_ += " }"; @@ -1276,7 +1279,8 @@ class CppGenerator : public BaseGenerator { " auto ptr = reinterpret_cast<const {{TYPE}} *>(obj);"; if (ev.union_type.base_type == BASE_TYPE_STRUCT) { if (ev.union_type.struct_def->fixed) { - code_ += " return verifier.Verify<{{TYPE}}>(static_cast<const " + code_ += + " return verifier.Verify<{{TYPE}}>(static_cast<const " "uint8_t *>(obj), 0);"; } else { code_ += getptr; @@ -1295,7 +1299,7 @@ class CppGenerator : public BaseGenerator { code_ += " }"; } } - code_ += " default: return true;"; // unknown values are OK. + code_ += " default: return true;"; // unknown values are OK. code_ += " }"; code_ += "}"; code_ += ""; @@ -1763,7 +1767,9 @@ class CppGenerator : public BaseGenerator { } break; } - default: { break; } + default: { + break; + } } } @@ -1925,7 +1931,8 @@ class CppGenerator : public BaseGenerator { } } - if (parser_.opts.mutable_buffer && !(is_scalar && IsUnion(field.value.type))) { + if (parser_.opts.mutable_buffer && + !(is_scalar && IsUnion(field.value.type))) { if (is_scalar) { const auto type = GenTypeWire(field.value.type, "", false); code_.SetValue("SET_FN", "SetField<" + type + ">"); @@ -2901,8 +2908,8 @@ class CppGenerator : public BaseGenerator { } else if (IsArray(field.value.type)) { auto underlying = GenTypeGet(field.value.type, "", "", "", false); code_ += " flatbuffers::Array<" + mut_field_type + ", " + - NumToString(field.value.type.fixed_length) + - "> *" + "mutable_{{FIELD_NAME}}() {"; + NumToString(field.value.type.fixed_length) + "> *" + + "mutable_{{FIELD_NAME}}() {"; code_ += " return reinterpret_cast<flatbuffers::Array<" + mut_field_type + ", " + NumToString(field.value.type.fixed_length) + |