mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 20:15:34 +00:00
[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,
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
e837d5a296
commit
f0f0efe7b8
@@ -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) +
|
||||
|
||||
Reference in New Issue
Block a user