#include "flatbuffers/stl_emulation.h"
#ifndef FLATBUFFERS_CPP98_STL
- #include <functional>
+# include <functional>
#endif
#if defined(FLATBUFFERS_NAN_DEFAULTS)
(void)p2;
CopyFromSpanImpl(
- flatbuffers::integral_constant<bool,
- !scalar_tag::value || sizeof(T) == 1 || FLATBUFFERS_LITTLEENDIAN>(),
+ flatbuffers::integral_constant < bool,
+ !scalar_tag::value || sizeof(T) == 1 || FLATBUFFERS_LITTLEENDIAN > (),
src);
}
// Cast a raw T[length] to a raw flatbuffers::Array<T, length>
// without endian conversion. Use with care.
template<typename T, uint16_t length>
-Array<T, length>& CastToArray(T (&arr)[length]) {
+Array<T, length> &CastToArray(T (&arr)[length]) {
return *reinterpret_cast<Array<T, length> *>(arr);
}
template<typename T, uint16_t length>
-const Array<T, length>& CastToArray(const T (&arr)[length]) {
+const Array<T, length> &CastToArray(const T (&arr)[length]) {
return *reinterpret_cast<const Array<T, length> *>(arr);
}
static inline flatbuffers::string_view GetStringView(const String *str) {
return str ? str->string_view() : flatbuffers::string_view();
}
-#endif // FLATBUFFERS_HAS_STRING_VIEW
+#endif // FLATBUFFERS_HAS_STRING_VIEW
// Allocator interface. This is flatbuffers-specific and meant only for
// `vector_downward` usage.
// causing the wrong overload to be selected, remove it.
AssertScalarT<T>();
StartVector(len, sizeof(T));
- if (len == 0) {
- return Offset<Vector<T>>(EndVector(len));
- }
+ if (len == 0) { return Offset<Vector<T>>(EndVector(len)); }
// clang-format off
#if FLATBUFFERS_LITTLEENDIAN
PushBytes(reinterpret_cast<const uint8_t *>(v), len * sizeof(T));
// bitfields is otherwise implementation-defined and causes warnings on older
// GCC compilers.
struct TypeCode {
- unsigned short base_type : 4; // ElementaryType
- unsigned short is_repeating : 1; // Either vector (in table) or array (in struct)
- signed short sequence_ref : 11; // Index into type_refs below, or -1 for none.
+ // ElementaryType
+ unsigned short base_type : 4;
+ // Either vector (in table) or array (in struct)
+ unsigned short is_repeating : 1;
+ // Index into type_refs below, or -1 for none.
+ signed short sequence_ref : 11;
};
static_assert(sizeof(TypeCode) == 2, "TypeCode");
inline size_t GetTypeSize(reflection::BaseType base_type) {
// This needs to correspond to the BaseType enum.
static size_t sizes[] = {
- 0, // None
- 1, // UType
- 1, // Bool
- 1, // Byte
- 1, // UByte
- 2, // Short
- 2, // UShort
- 4, // Int
- 4, // UInt
- 8, // Long
- 8, // ULong
- 4, // Float
- 8, // Double
- 4, // String
- 4, // Vector
- 4, // Obj
- 4, // Union
- 0, // Array. Only used in structs. 0 was chosen to prevent out-of-bounds errors.
+ 0, // None
+ 1, // UType
+ 1, // Bool
+ 1, // Byte
+ 1, // UByte
+ 2, // Short
+ 2, // UShort
+ 4, // Int
+ 4, // UInt
+ 8, // Long
+ 8, // ULong
+ 4, // Float
+ 8, // Double
+ 4, // String
+ 4, // Vector
+ 4, // Obj
+ 4, // Union
+ 0, // Array. Only used in structs. 0 was chosen to prevent out-of-bounds
+ // errors.
0 // MaxBaseType. This must be kept the last entry in this array.
- };
+ };
static_assert(sizeof(sizes) / sizeof(size_t) == reflection::MaxBaseType + 1,
- "Size of sizes[] array does not match the count of BaseType enum values.");
+ "Size of sizes[] array does not match the count of BaseType "
+ "enum values.");
return sizes[base_type];
}
- /*
+/*
* Copyright 2014 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
if (!field.deprecated) {
code_.SetValue("FIELD_NAME", Name(field));
code_ += ",\n {{FIELD_NAME}}\\";
- if (IsString(field.value.type) ||
- IsVector(field.value.type)) {
+ if (IsString(field.value.type) || IsVector(field.value.type)) {
code_ += "__\\";
}
}
WrapInNameSpace(*field.value.type.enum_def) + ">(";
}
indexing += "_e->Get(_i)";
- if (field.value.type.enum_def) {
- indexing += ")";
- }
+ if (field.value.type.enum_def) { indexing += ")"; }
if (field.value.type.element == BASE_TYPE_BOOL) {
indexing += " != 0";
}
case BASE_TYPE_ARRAY: {
auto type_name = GenTypeGet_ObjectAPI(field.value.type, opts);
auto length_str = NumToString(field.value.type.fixed_length);
- auto unpack_method = field.value.type.struct_def == nullptr ? ""
- : field.value.type.struct_def->fixed
- ? ".UnPack()"
- : "?.UnPack()";
+ auto unpack_method = field.value.type.struct_def == nullptr
+ ? ""
+ : field.value.type.struct_def->fixed
+ ? ".UnPack()"
+ : "?.UnPack()";
code += start + "new " + type_name.substr(0, type_name.length() - 1) +
length_str + "];\n";
code += " for (var _j = 0; _j < " + length_str + "; ++_j) { _o." +
if (i == 0) {
code += "\tn := flatbuffers.GetUOffsetT(buf[offset:])\n";
} else {
- code += "\tn := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])\n";
+ code +=
+ "\tn := "
+ "flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])\n";
}
code += "\tx := &" + struct_def.name + "{}\n";
if (i == 0) {
}
bool save() const {
- const auto file_path =
- GeneratedFileName(path_, file_name_, parser_.opts);
+ const auto file_path = GeneratedFileName(path_, file_name_, parser_.opts);
return SaveFile(file_path.c_str(), code_, false);
}
} else {
BuildFieldOfTable(field, offset, code_ptr);
}
- if (IsVector(field.value.type)) {
- BuildVectorOfTable(field, code_ptr);
- }
+ if (IsVector(field.value.type)) { BuildVectorOfTable(field, code_ptr); }
}
GetEndOffsetOnTable(struct_def, code_ptr);
const FieldDef &field,
std::string *code_ptr) {
auto nested = field.attributes.Lookup("nested_flatbuffer");
- if (!nested) { return; } // There is no nested flatbuffer.
+ if (!nested) { return; } // There is no nested flatbuffer.
std::string unqualified_name = nested->constant;
std::string qualified_name = nested->constant;
auto nested_root = parser_.LookupStruct(nested->constant);
if (nested_root == nullptr) {
- qualified_name = parser_.current_namespace_->GetFullyQualifiedName(
- nested->constant);
+ qualified_name =
+ parser_.current_namespace_->GetFullyQualifiedName(nested->constant);
nested_root = parser_.LookupStruct(qualified_name);
}
FLATBUFFERS_ASSERT(nested_root); // Guaranteed to exist by parser.
field_instance_name + "))):";
code_prefix +=
GenIndents(4) + "self." + field_instance_name + "[i].Pack(builder)";
- code_prefix += GenIndents(3) + field_instance_name + " = builder.EndVector()";
+ code_prefix +=
+ GenIndents(3) + field_instance_name + " = builder.EndVector()";
} else {
// If the vector is a struct vector, we need to first build accessor for
// each struct element.
field_instance_name + "))):";
code_prefix += GenIndents(4) + "builder.PrependUOffsetTRelative" + "(" +
field_instance_name + "list[i])";
- code_prefix += GenIndents(3) + field_instance_name + " = builder.EndVector()";
+ code_prefix +=
+ GenIndents(3) + field_instance_name + " = builder.EndVector()";
}
// Adds the field into the struct.
field_instance_name + "[i]))";
GenPackForScalarVectorFieldHelper(struct_def, field, code_prefix_ptr, 3);
code_prefix += "(" + MakeLowerCamel(field) + "list[i])";
- code_prefix += GenIndents(3) + field_instance_name + " = builder.EndVector()";
+ code_prefix +=
+ GenIndents(3) + field_instance_name + " = builder.EndVector()";
return;
}
code_prefix += GenIndents(3) + "else:";
GenPackForScalarVectorFieldHelper(struct_def, field, code_prefix_ptr, 4);
code_prefix += "(self." + field_instance_name + "[i])";
- code_prefix += GenIndents(4) + field_instance_name + " = builder.EndVector()";
+ code_prefix +=
+ GenIndents(4) + field_instance_name + " = builder.EndVector()";
}
void GenPackForStructField(const StructDef &struct_def, const FieldDef &field,
// changes to that webpage in the future.
// currently-used keywords
- "as", "break", "const", "continue", "crate", "else", "enum", "extern",
- "false", "fn", "for", "if", "impl", "in", "let", "loop", "match", "mod",
- "move", "mut", "pub", "ref", "return", "Self", "self", "static", "struct",
- "super", "trait", "true", "type", "unsafe", "use", "where", "while",
+ "as",
+ "break",
+ "const",
+ "continue",
+ "crate",
+ "else",
+ "enum",
+ "extern",
+ "false",
+ "fn",
+ "for",
+ "if",
+ "impl",
+ "in",
+ "let",
+ "loop",
+ "match",
+ "mod",
+ "move",
+ "mut",
+ "pub",
+ "ref",
+ "return",
+ "Self",
+ "self",
+ "static",
+ "struct",
+ "super",
+ "trait",
+ "true",
+ "type",
+ "unsafe",
+ "use",
+ "where",
+ "while",
// future possible keywords
- "abstract", "alignof", "become", "box", "do", "final", "macro",
- "offsetof", "override", "priv", "proc", "pure", "sizeof", "typeof",
- "unsized", "virtual", "yield",
+ "abstract",
+ "alignof",
+ "become",
+ "box",
+ "do",
+ "final",
+ "macro",
+ "offsetof",
+ "override",
+ "priv",
+ "proc",
+ "pure",
+ "sizeof",
+ "typeof",
+ "unsized",
+ "virtual",
+ "yield",
// other rust terms we should not use
- "std", "usize", "isize", "u8", "i8", "u16", "i16", "u32", "i32", "u64",
- "i64", "u128", "i128", "f32", "f64",
+ "std",
+ "usize",
+ "isize",
+ "u8",
+ "i8",
+ "u16",
+ "i16",
+ "u32",
+ "i32",
+ "u64",
+ "i64",
+ "u128",
+ "i128",
+ "f32",
+ "f64",
// These are terms the code generator can implement on types.
//
// implementation detail, and how we implement methods could change in
// the future. as a result, we proactively block these out as reserved
// words.
- "follow", "push", "size", "alignment", "to_little_endian",
- "from_little_endian", nullptr,
+ "follow",
+ "push",
+ "size",
+ "alignment",
+ "to_little_endian",
+ "from_little_endian",
+ nullptr,
// used by Enum constants
- "ENUM_MAX", "ENUM_MIN", "ENUM_VALUES",
- }; // clang-format on
+ "ENUM_MAX",
+ "ENUM_MIN",
+ "ENUM_VALUES",
+ };
for (auto kw = keywords; *kw; kw++) keywords_.insert(*kw);
}
}
void Parser::Warning(const std::string &msg) {
- if (!opts.no_warnings)
- Message("warning: " + msg);
+ if (!opts.no_warnings) Message("warning: " + msg);
}
CheckedError Parser::Error(const std::string &msg) {
return true;
}
-template<typename T>
-CheckedError atot(const char *s, Parser &parser, T *val) {
+template<typename T> CheckedError atot(const char *s, Parser &parser, T *val) {
auto done = atot_scalar(s, val, bool_constant<is_floating_point<T>::value>());
if (done) return NoError();
if (0 == *val)
return NoError();
}
-CheckedError Parser::DoParseJson()
-{
+CheckedError Parser::DoParseJson() {
if (token_ != '{') {
EXPECT('{');
} else {
- if (!root_struct_def_)
- return Error("no root type set to parse json with");
+ if (!root_struct_def_) return Error("no root type set to parse json with");
if (builder_.GetSize()) {
return Error("cannot have more than one json object in a file");
}
file_identifier_.length() ? file_identifier_.c_str() : nullptr);
} else {
builder_.Finish(Offset<Table>(toff), file_identifier_.length()
- ? file_identifier_.c_str()
- : nullptr);
+ ? file_identifier_.c_str()
+ : nullptr);
}
}
// Check that JSON file doesn't contain more objects or IDL directives.
std::memcpy(&b, &v, sizeof(T));
return ((b & qnan_base) == qnan_base);
}
-#if defined(__mips__) || defined(__hppa__)
+# if defined(__mips__) || defined(__hppa__)
static bool is_quiet_nan(float v) {
return is_quiet_nan_impl<float, uint32_t, 0x7FC00000u>(v) ||
is_quiet_nan_impl<float, uint32_t, 0x7FBFFFFFu>(v);
return is_quiet_nan_impl<double, uint64_t, 0x7FF8000000000000ul>(v) ||
is_quiet_nan_impl<double, uint64_t, 0x7FF7FFFFFFFFFFFFu>(v);
}
-#else
+# else
static bool is_quiet_nan(float v) {
return is_quiet_nan_impl<float, uint32_t, 0x7FC00000u>(v);
}
static bool is_quiet_nan(double v) {
return is_quiet_nan_impl<double, uint64_t, 0x7FF8000000000000ul>(v);
}
-#endif
+# endif
void TestMonsterExtraFloats() {
TEST_EQ(is_quiet_nan(1.0), false);
// set memory chunk of size ArrayStruct to 1's
std::memset(static_cast<void *>(non_zero_memory), 1, arr_size);
// after placement-new it should be all 0's
-#if defined (_MSC_VER) && defined (_DEBUG)
- #undef new
-#endif
- MyGame::Example::ArrayStruct *ap = new (non_zero_memory) MyGame::Example::ArrayStruct;
-#if defined (_MSC_VER) && defined (_DEBUG)
- #define new DEBUG_NEW
-#endif
+# if defined(_MSC_VER) && defined(_DEBUG)
+# undef new
+# endif
+ MyGame::Example::ArrayStruct *ap =
+ new (non_zero_memory) MyGame::Example::ArrayStruct;
+# if defined(_MSC_VER) && defined(_DEBUG)
+# define new DEBUG_NEW
+# endif
(void)ap;
- for (size_t i = 0; i < arr_size; ++i) {
- TEST_EQ(non_zero_memory[i], 0);
- }
+ for (size_t i = 0; i < arr_size; ++i) { TEST_EQ(non_zero_memory[i], 0); }
#endif
}
-#if !defined(FLATBUFFERS_SPAN_MINIMAL) && (!defined(_MSC_VER) || _MSC_VER >= 1700)
+#if !defined(FLATBUFFERS_SPAN_MINIMAL) && \
+ (!defined(_MSC_VER) || _MSC_VER >= 1700)
void FixedLengthArrayConstructorTest() {
const int32_t nested_a[2] = { 1, 2 };
MyGame::Example::TestEnum nested_c[2] = { MyGame::Example::TestEnum::A,
TEST_EQ(arr_struct.f()->Get(1), -1);
}
#else
-void FixedLengthArrayConstructorTest() {
-}
+void FixedLengthArrayConstructorTest() {}
#endif
void NativeTypeTest() {
schemas.push_back("table Monster { mana : bool; }");
schemas.push_back("table Monster { mana : bool = 42; }");
schemas.push_back("table Monster { mana : bool = null; }");
- schemas.push_back("enum Enum: int {A=0, B=1} "
- "table Monster { mana : Enum; }");
- schemas.push_back("enum Enum: int {A=0, B=1} "
- "table Monster { mana : Enum = B; }");
- schemas.push_back("enum Enum: int {A=0, B=1} "
- "table Monster { mana : Enum = null; }");
+ schemas.push_back(
+ "enum Enum: int {A=0, B=1} "
+ "table Monster { mana : Enum; }");
+ schemas.push_back(
+ "enum Enum: int {A=0, B=1} "
+ "table Monster { mana : Enum = B; }");
+ schemas.push_back(
+ "enum Enum: int {A=0, B=1} "
+ "table Monster { mana : Enum = null; }");
// Check the FieldDef is correctly set.
for (auto schema = schemas.begin(); schema < schemas.end(); schema++) {