mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 12:05:50 +00:00
committed by
Wouter van Oortmerssen
parent
dd85c3b721
commit
dd6daa709b
@@ -785,7 +785,7 @@ class CppGenerator : public BaseGenerator {
|
||||
struct_def ? (struct_def->fixed ? "ST_STRUCT" : "ST_TABLE")
|
||||
: (enum_def->is_union ? "ST_UNION" : "ST_ENUM"));
|
||||
auto num_fields =
|
||||
struct_def ? struct_def->fields.vec.size() : enum_def->vals.vec.size();
|
||||
struct_def ? struct_def->fields.vec.size() : enum_def->size();
|
||||
code_.SetValue("NUM_FIELDS", NumToString(num_fields));
|
||||
std::vector<std::string> names;
|
||||
std::vector<Type> types;
|
||||
@@ -798,13 +798,13 @@ class CppGenerator : public BaseGenerator {
|
||||
types.push_back(field.value.type);
|
||||
}
|
||||
} else {
|
||||
for (auto it = enum_def->vals.vec.begin(); it != enum_def->vals.vec.end();
|
||||
for (auto it = enum_def->Vals().begin(); it != enum_def->Vals().end();
|
||||
++it) {
|
||||
const auto &ev = **it;
|
||||
names.push_back(Name(ev));
|
||||
types.push_back(enum_def->is_union ? ev.union_type
|
||||
: Type(enum_def->underlying_type));
|
||||
if (static_cast<int64_t>(it - enum_def->vals.vec.begin()) != ev.value) {
|
||||
if (static_cast<int64_t>(it - enum_def->Vals().begin()) != ev.value) {
|
||||
consecutive_enum_from_zero = false;
|
||||
}
|
||||
}
|
||||
@@ -852,7 +852,7 @@ class CppGenerator : public BaseGenerator {
|
||||
}
|
||||
std::string vs;
|
||||
if (enum_def && !consecutive_enum_from_zero) {
|
||||
for (auto it = enum_def->vals.vec.begin(); it != enum_def->vals.vec.end();
|
||||
for (auto it = enum_def->Vals().begin(); it != enum_def->Vals().end();
|
||||
++it) {
|
||||
const auto &ev = **it;
|
||||
if (!vs.empty()) vs += ", ";
|
||||
@@ -919,8 +919,7 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
int64_t anyv = 0;
|
||||
const EnumVal *minv = nullptr, *maxv = nullptr;
|
||||
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
|
||||
++it) {
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
|
||||
const auto &ev = **it;
|
||||
|
||||
GenComment(ev.doc_comment, " ");
|
||||
@@ -966,15 +965,14 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += "";
|
||||
|
||||
// Generate an array of all enumeration values
|
||||
auto num_fields = NumToString(enum_def.vals.vec.size());
|
||||
auto num_fields = NumToString(enum_def.size());
|
||||
code_ += "inline const {{ENUM_NAME}} (&EnumValues{{ENUM_NAME}}())[" +
|
||||
num_fields + "] {";
|
||||
code_ += " static const {{ENUM_NAME}} values[] = {";
|
||||
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
|
||||
++it) {
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
|
||||
const auto &ev = **it;
|
||||
auto value = GetEnumValUse(enum_def, ev);
|
||||
auto suffix = *it != enum_def.vals.vec.back() ? "," : "";
|
||||
auto suffix = *it != enum_def.Vals().back() ? "," : "";
|
||||
code_ += " " + value + suffix;
|
||||
}
|
||||
code_ += " };";
|
||||
@@ -996,8 +994,8 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += "inline const char * const *EnumNames{{ENUM_NAME}}() {";
|
||||
code_ += " static const char * const names[] = {";
|
||||
|
||||
auto val = enum_def.vals.vec.front()->value;
|
||||
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
|
||||
auto val = enum_def.Vals().front()->value;
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end();
|
||||
++it) {
|
||||
const auto &ev = **it;
|
||||
while (val++ != ev.value) { code_ += " \"\","; }
|
||||
@@ -1032,7 +1030,7 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
code_ += " switch (e) {";
|
||||
|
||||
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end();
|
||||
++it) {
|
||||
const auto &ev = **it;
|
||||
code_ += " case " + GetEnumValUse(enum_def, ev) + ": return \"" +
|
||||
@@ -1048,11 +1046,11 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
// Generate type traits for unions to map from a type to union enum value.
|
||||
if (enum_def.is_union && !enum_def.uses_multiple_type_instances) {
|
||||
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end();
|
||||
++it) {
|
||||
const auto &ev = **it;
|
||||
|
||||
if (it == enum_def.vals.vec.begin()) {
|
||||
if (it == enum_def.Vals().begin()) {
|
||||
code_ += "template<typename T> struct {{ENUM_NAME}}Traits {";
|
||||
} else {
|
||||
auto name = GetUnionElement(ev, true, true);
|
||||
@@ -1114,10 +1112,10 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += " " + UnionPackSignature(enum_def, true) + ";";
|
||||
code_ += "";
|
||||
|
||||
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end();
|
||||
++it) {
|
||||
const auto &ev = **it;
|
||||
if (!ev.value) { continue; }
|
||||
if (ev.IsZero()) { continue; }
|
||||
|
||||
const auto native_type =
|
||||
NativeName(GetUnionElement(ev, true, true, true),
|
||||
@@ -1148,11 +1146,11 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += " if (lhs.type != rhs.type) return false;";
|
||||
code_ += " switch (lhs.type) {";
|
||||
|
||||
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end();
|
||||
++it) {
|
||||
const auto &ev = **it;
|
||||
code_.SetValue("NATIVE_ID", GetEnumValUse(enum_def, ev));
|
||||
if (ev.value) {
|
||||
if (ev.IsNonZero()) {
|
||||
const auto native_type =
|
||||
NativeName(GetUnionElement(ev, true, true, true),
|
||||
ev.union_type.struct_def, parser_.opts);
|
||||
@@ -1204,12 +1202,11 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
code_ += "inline " + UnionVerifySignature(enum_def) + " {";
|
||||
code_ += " switch (type) {";
|
||||
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
|
||||
++it) {
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
|
||||
const auto &ev = **it;
|
||||
code_.SetValue("LABEL", GetEnumValUse(enum_def, ev));
|
||||
|
||||
if (ev.value) {
|
||||
if (ev.IsNonZero()) {
|
||||
code_.SetValue("TYPE", GetUnionElement(ev, true, true));
|
||||
code_ += " case {{LABEL}}: {";
|
||||
auto getptr =
|
||||
@@ -1257,10 +1254,10 @@ class CppGenerator : public BaseGenerator {
|
||||
// Generate union Unpack() and Pack() functions.
|
||||
code_ += "inline " + UnionUnPackSignature(enum_def, false) + " {";
|
||||
code_ += " switch (type) {";
|
||||
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end();
|
||||
++it) {
|
||||
const auto &ev = **it;
|
||||
if (!ev.value) { continue; }
|
||||
if (ev.IsZero()) { continue; }
|
||||
|
||||
code_.SetValue("LABEL", GetEnumValUse(enum_def, ev));
|
||||
code_.SetValue("TYPE", GetUnionElement(ev, true, true));
|
||||
@@ -1287,10 +1284,10 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
code_ += "inline " + UnionPackSignature(enum_def, false) + " {";
|
||||
code_ += " switch (type) {";
|
||||
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end();
|
||||
++it) {
|
||||
auto &ev = **it;
|
||||
if (!ev.value) { continue; }
|
||||
if (ev.IsZero()) { continue; }
|
||||
|
||||
code_.SetValue("LABEL", GetEnumValUse(enum_def, ev));
|
||||
code_.SetValue("TYPE",
|
||||
@@ -1324,10 +1321,10 @@ class CppGenerator : public BaseGenerator {
|
||||
"{{ENUM_NAME}}Union &u) FLATBUFFERS_NOEXCEPT : type(u.type), "
|
||||
"value(nullptr) {";
|
||||
code_ += " switch (type) {";
|
||||
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end();
|
||||
++it) {
|
||||
const auto &ev = **it;
|
||||
if (!ev.value) { continue; }
|
||||
if (ev.IsZero()) { continue; }
|
||||
code_.SetValue("LABEL", GetEnumValUse(enum_def, ev));
|
||||
code_.SetValue("TYPE",
|
||||
NativeName(GetUnionElement(ev, true, true, true),
|
||||
@@ -1370,10 +1367,10 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
code_ += "inline void {{ENUM_NAME}}Union::Reset() {";
|
||||
code_ += " switch (type) {";
|
||||
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end();
|
||||
++it) {
|
||||
const auto &ev = **it;
|
||||
if (!ev.value) { continue; }
|
||||
if (ev.IsZero()) { continue; }
|
||||
code_.SetValue("LABEL", GetEnumValUse(enum_def, ev));
|
||||
code_.SetValue("TYPE",
|
||||
NativeName(GetUnionElement(ev, true, true, true),
|
||||
@@ -1834,8 +1831,7 @@ class CppGenerator : public BaseGenerator {
|
||||
" template<typename T> "
|
||||
"const T *{{NULLABLE_EXT}}{{FIELD_NAME}}_as() const;";
|
||||
|
||||
for (auto u_it = u->vals.vec.begin(); u_it != u->vals.vec.end();
|
||||
++u_it) {
|
||||
for (auto u_it = u->Vals().begin(); u_it != u->Vals().end(); ++u_it) {
|
||||
auto &ev = **u_it;
|
||||
if (ev.union_type.base_type == BASE_TYPE_NONE) { continue; }
|
||||
auto full_struct_name = GetUnionElement(ev, true, true);
|
||||
@@ -1967,7 +1963,7 @@ class CppGenerator : public BaseGenerator {
|
||||
|
||||
code_.SetValue("FIELD_NAME", Name(field));
|
||||
|
||||
for (auto u_it = u->vals.vec.begin(); u_it != u->vals.vec.end(); ++u_it) {
|
||||
for (auto u_it = u->Vals().begin(); u_it != u->Vals().end(); ++u_it) {
|
||||
auto &ev = **u_it;
|
||||
if (ev.union_type.base_type == BASE_TYPE_NONE) { continue; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user