mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-21 02:17:32 +00:00
Add support for using array of scalar as key field in Cpp (#7623)
* add support for using array of scalar as key field * update cmakelist and test.cpp to include the tests * update bazel rule * address comments * clang format * delete comment * delete comment * address the rest of the commnets * address comments * update naming in test file * format build file * buildifier * make keycomparelessthan call keycomparewithvalue * update to use flatbuffer array instead of raw pointer * clang * format * revert format * revert format * update * run generate_code.py * run code generator * revert changes by generate_code.py * fist run make flatc and then run generate_code.py Co-authored-by: Wen Sun <sunwen@google.com>
This commit is contained in:
@@ -22,6 +22,9 @@ cc_test(
|
||||
"is_quiet_nan.h",
|
||||
"json_test.cpp",
|
||||
"json_test.h",
|
||||
"key_field/key_field_sample_generated.h",
|
||||
"key_field_test.cpp",
|
||||
"key_field_test.h",
|
||||
"monster_test.cpp",
|
||||
"monster_test.h",
|
||||
"monster_test_bfbs_generated.h",
|
||||
@@ -63,6 +66,7 @@ cc_test(
|
||||
":evolution_test/evolution_v2.json",
|
||||
":include_test/include_test1.fbs",
|
||||
":include_test/sub/include_test2.fbs",
|
||||
":key_field/key_field_sample.fbs",
|
||||
":monster_extra.fbs",
|
||||
":monster_test.bfbs",
|
||||
":monster_test.fbs",
|
||||
|
||||
@@ -730,7 +730,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Ability FLATBUFFERS_FINAL_CLASS {
|
||||
void mutate_id(uint32_t _id) {
|
||||
flatbuffers::WriteScalar(&id_, _id);
|
||||
}
|
||||
bool KeyCompareLessThan(const Ability *o) const {
|
||||
bool KeyCompareLessThan(const Ability * const o) const {
|
||||
return id() < o->id();
|
||||
}
|
||||
int KeyCompareWithValue(uint32_t _id) const {
|
||||
@@ -1094,7 +1094,7 @@ struct Stat FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_count(uint16_t _count = 0) {
|
||||
return SetField<uint16_t>(VT_COUNT, _count, 0);
|
||||
}
|
||||
bool KeyCompareLessThan(const Stat *o) const {
|
||||
bool KeyCompareLessThan(const Stat * const o) const {
|
||||
return count() < o->count();
|
||||
}
|
||||
int KeyCompareWithValue(uint16_t _count) const {
|
||||
@@ -1207,7 +1207,7 @@ struct Referrable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_id(uint64_t _id = 0) {
|
||||
return SetField<uint64_t>(VT_ID, _id, 0);
|
||||
}
|
||||
bool KeyCompareLessThan(const Referrable *o) const {
|
||||
bool KeyCompareLessThan(const Referrable * const o) const {
|
||||
return id() < o->id();
|
||||
}
|
||||
int KeyCompareWithValue(uint64_t _id) const {
|
||||
@@ -1430,7 +1430,7 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
flatbuffers::String *mutable_name() {
|
||||
return GetPointer<flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
bool KeyCompareLessThan(const Monster *o) const {
|
||||
bool KeyCompareLessThan(const Monster * const o) const {
|
||||
return *name() < *o->name();
|
||||
}
|
||||
int KeyCompareWithValue(const char *_name) const {
|
||||
|
||||
21
tests/key_field/key_field_sample.fbs
Normal file
21
tests/key_field/key_field_sample.fbs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace keyfield.sample;
|
||||
|
||||
struct Baz {
|
||||
a: [uint8:4] (key); // A fixed-sized array of uint8 as a Key
|
||||
b: uint8 ;
|
||||
}
|
||||
|
||||
struct Bar {
|
||||
a: [float:3] (key); // A fixed-sized array of float as a Key
|
||||
b: uint8;
|
||||
}
|
||||
|
||||
table FooTable {
|
||||
a: int;
|
||||
b: int;
|
||||
c: string (key);
|
||||
d: [Baz];
|
||||
e: [Bar];
|
||||
}
|
||||
root_type FooTable;
|
||||
|
||||
260
tests/key_field/key_field_sample_generated.h
Normal file
260
tests/key_field/key_field_sample_generated.h
Normal file
@@ -0,0 +1,260 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_KEYFIELDSAMPLE_KEYFIELD_SAMPLE_H_
|
||||
#define FLATBUFFERS_GENERATED_KEYFIELDSAMPLE_KEYFIELD_SAMPLE_H_
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 22 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 10 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 26,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace keyfield {
|
||||
namespace sample {
|
||||
|
||||
struct Baz;
|
||||
|
||||
struct Bar;
|
||||
|
||||
struct FooTable;
|
||||
struct FooTableBuilder;
|
||||
|
||||
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS {
|
||||
private:
|
||||
uint8_t a_[4];
|
||||
uint8_t b_;
|
||||
|
||||
public:
|
||||
Baz()
|
||||
: a_(),
|
||||
b_(0) {
|
||||
}
|
||||
Baz(uint8_t _b)
|
||||
: a_(),
|
||||
b_(flatbuffers::EndianScalar(_b)) {
|
||||
}
|
||||
Baz(flatbuffers::span<const uint8_t, 4> _a, uint8_t _b)
|
||||
: b_(flatbuffers::EndianScalar(_b)) {
|
||||
flatbuffers::CastToArray(a_).CopyFromSpan(_a);
|
||||
}
|
||||
const flatbuffers::Array<uint8_t, 4> *a() const {
|
||||
return &flatbuffers::CastToArray(a_);
|
||||
}
|
||||
bool KeyCompareLessThan(const Baz * const o) const {
|
||||
return KeyCompareWithValue(o->a()) < 0;
|
||||
}
|
||||
int KeyCompareWithValue(const flatbuffers::Array<uint8_t, 4> *_a) const {
|
||||
for (auto i = 0; i < a()->size(); i++) {
|
||||
const auto a_l = a_[i];
|
||||
const auto a_r = _a->Get(i);
|
||||
if(a_l != a_r)
|
||||
return static_cast<int>(a_l > a_r) - static_cast<int>(a_l < a_r);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
uint8_t b() const {
|
||||
return flatbuffers::EndianScalar(b_);
|
||||
}
|
||||
};
|
||||
FLATBUFFERS_STRUCT_END(Baz, 5);
|
||||
|
||||
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS {
|
||||
private:
|
||||
float a_[3];
|
||||
uint8_t b_;
|
||||
int8_t padding0__; int16_t padding1__;
|
||||
|
||||
public:
|
||||
Bar()
|
||||
: a_(),
|
||||
b_(0),
|
||||
padding0__(0),
|
||||
padding1__(0) {
|
||||
(void)padding0__;
|
||||
(void)padding1__;
|
||||
}
|
||||
Bar(uint8_t _b)
|
||||
: a_(),
|
||||
b_(flatbuffers::EndianScalar(_b)),
|
||||
padding0__(0),
|
||||
padding1__(0) {
|
||||
(void)padding0__;
|
||||
(void)padding1__;
|
||||
}
|
||||
Bar(flatbuffers::span<const float, 3> _a, uint8_t _b)
|
||||
: b_(flatbuffers::EndianScalar(_b)),
|
||||
padding0__(0),
|
||||
padding1__(0) {
|
||||
flatbuffers::CastToArray(a_).CopyFromSpan(_a);
|
||||
(void)padding0__;
|
||||
(void)padding1__;
|
||||
}
|
||||
const flatbuffers::Array<float, 3> *a() const {
|
||||
return &flatbuffers::CastToArray(a_);
|
||||
}
|
||||
bool KeyCompareLessThan(const Bar * const o) const {
|
||||
return KeyCompareWithValue(o->a()) < 0;
|
||||
}
|
||||
int KeyCompareWithValue(const flatbuffers::Array<float, 3> *_a) const {
|
||||
for (auto i = 0; i < a()->size(); i++) {
|
||||
const auto a_l = a_[i];
|
||||
const auto a_r = _a->Get(i);
|
||||
if(a_l != a_r)
|
||||
return static_cast<int>(a_l > a_r) - static_cast<int>(a_l < a_r);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
uint8_t b() const {
|
||||
return flatbuffers::EndianScalar(b_);
|
||||
}
|
||||
};
|
||||
FLATBUFFERS_STRUCT_END(Bar, 16);
|
||||
|
||||
struct FooTable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
typedef FooTableBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_A = 4,
|
||||
VT_B = 6,
|
||||
VT_C = 8,
|
||||
VT_D = 10,
|
||||
VT_E = 12
|
||||
};
|
||||
int32_t a() const {
|
||||
return GetField<int32_t>(VT_A, 0);
|
||||
}
|
||||
int32_t b() const {
|
||||
return GetField<int32_t>(VT_B, 0);
|
||||
}
|
||||
const flatbuffers::String *c() const {
|
||||
return GetPointer<const flatbuffers::String *>(VT_C);
|
||||
}
|
||||
bool KeyCompareLessThan(const FooTable * const o) const {
|
||||
return *c() < *o->c();
|
||||
}
|
||||
int KeyCompareWithValue(const char *_c) const {
|
||||
return strcmp(c()->c_str(), _c);
|
||||
}
|
||||
const flatbuffers::Vector<const keyfield::sample::Baz *> *d() const {
|
||||
return GetPointer<const flatbuffers::Vector<const keyfield::sample::Baz *> *>(VT_D);
|
||||
}
|
||||
const flatbuffers::Vector<const keyfield::sample::Bar *> *e() const {
|
||||
return GetPointer<const flatbuffers::Vector<const keyfield::sample::Bar *> *>(VT_E);
|
||||
}
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<int32_t>(verifier, VT_A, 4) &&
|
||||
VerifyField<int32_t>(verifier, VT_B, 4) &&
|
||||
VerifyOffsetRequired(verifier, VT_C) &&
|
||||
verifier.VerifyString(c()) &&
|
||||
VerifyOffset(verifier, VT_D) &&
|
||||
verifier.VerifyVector(d()) &&
|
||||
VerifyOffset(verifier, VT_E) &&
|
||||
verifier.VerifyVector(e()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct FooTableBuilder {
|
||||
typedef FooTable Table;
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_a(int32_t a) {
|
||||
fbb_.AddElement<int32_t>(FooTable::VT_A, a, 0);
|
||||
}
|
||||
void add_b(int32_t b) {
|
||||
fbb_.AddElement<int32_t>(FooTable::VT_B, b, 0);
|
||||
}
|
||||
void add_c(flatbuffers::Offset<flatbuffers::String> c) {
|
||||
fbb_.AddOffset(FooTable::VT_C, c);
|
||||
}
|
||||
void add_d(flatbuffers::Offset<flatbuffers::Vector<const keyfield::sample::Baz *>> d) {
|
||||
fbb_.AddOffset(FooTable::VT_D, d);
|
||||
}
|
||||
void add_e(flatbuffers::Offset<flatbuffers::Vector<const keyfield::sample::Bar *>> e) {
|
||||
fbb_.AddOffset(FooTable::VT_E, e);
|
||||
}
|
||||
explicit FooTableBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
flatbuffers::Offset<FooTable> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<FooTable>(end);
|
||||
fbb_.Required(o, FooTable::VT_C);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<FooTable> CreateFooTable(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
int32_t a = 0,
|
||||
int32_t b = 0,
|
||||
flatbuffers::Offset<flatbuffers::String> c = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<const keyfield::sample::Baz *>> d = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<const keyfield::sample::Bar *>> e = 0) {
|
||||
FooTableBuilder builder_(_fbb);
|
||||
builder_.add_e(e);
|
||||
builder_.add_d(d);
|
||||
builder_.add_c(c);
|
||||
builder_.add_b(b);
|
||||
builder_.add_a(a);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<FooTable> CreateFooTableDirect(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
int32_t a = 0,
|
||||
int32_t b = 0,
|
||||
const char *c = nullptr,
|
||||
std::vector<keyfield::sample::Baz> *d = nullptr,
|
||||
std::vector<keyfield::sample::Bar> *e = nullptr) {
|
||||
auto c__ = c ? _fbb.CreateString(c) : 0;
|
||||
auto d__ = d ? _fbb.CreateVectorOfSortedStructs<keyfield::sample::Baz>(d) : 0;
|
||||
auto e__ = e ? _fbb.CreateVectorOfSortedStructs<keyfield::sample::Bar>(e) : 0;
|
||||
return keyfield::sample::CreateFooTable(
|
||||
_fbb,
|
||||
a,
|
||||
b,
|
||||
c__,
|
||||
d__,
|
||||
e__);
|
||||
}
|
||||
|
||||
inline const keyfield::sample::FooTable *GetFooTable(const void *buf) {
|
||||
return flatbuffers::GetRoot<keyfield::sample::FooTable>(buf);
|
||||
}
|
||||
|
||||
inline const keyfield::sample::FooTable *GetSizePrefixedFooTable(const void *buf) {
|
||||
return flatbuffers::GetSizePrefixedRoot<keyfield::sample::FooTable>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyFooTableBuffer(
|
||||
flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<keyfield::sample::FooTable>(nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedFooTableBuffer(
|
||||
flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<keyfield::sample::FooTable>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishFooTableBuffer(
|
||||
flatbuffers::FlatBufferBuilder &fbb,
|
||||
flatbuffers::Offset<keyfield::sample::FooTable> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedFooTableBuffer(
|
||||
flatbuffers::FlatBufferBuilder &fbb,
|
||||
flatbuffers::Offset<keyfield::sample::FooTable> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
} // namespace sample
|
||||
} // namespace keyfield
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_KEYFIELDSAMPLE_KEYFIELD_SAMPLE_H_
|
||||
72
tests/key_field_test.cpp
Normal file
72
tests/key_field_test.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "key_field_test.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "key_field/key_field_sample_generated.h"
|
||||
#include "test_assert.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
namespace tests {
|
||||
|
||||
using namespace keyfield::sample;
|
||||
|
||||
void FixedSizedScalarKeyInStructTest() {
|
||||
flatbuffers::FlatBufferBuilder fbb;
|
||||
std::vector<Baz> bazs;
|
||||
uint8_t test_array1[4] = { 8, 2, 3, 0 };
|
||||
uint8_t test_array2[4] = { 1, 2, 3, 4 };
|
||||
uint8_t test_array3[4] = { 2, 2, 3, 4 };
|
||||
uint8_t test_array4[4] = { 3, 2, 3, 4 };
|
||||
bazs.push_back(Baz(flatbuffers::make_span(test_array1), 4));
|
||||
bazs.push_back(Baz(flatbuffers::make_span(test_array2), 1));
|
||||
bazs.push_back(Baz(flatbuffers::make_span(test_array3), 2));
|
||||
bazs.push_back(Baz(flatbuffers::make_span(test_array4), 3));
|
||||
auto baz_vec = fbb.CreateVectorOfSortedStructs(&bazs);
|
||||
auto test_string = fbb.CreateString("TEST");
|
||||
float test_float_array1[3] = { 1.5, 2.5, 0 };
|
||||
float test_float_array2[3] = { 7.5, 2.5, 0 };
|
||||
float test_float_array3[3] = { 1.5, 2.5, -1 };
|
||||
float test_float_array4[3] = { -1.5, 2.5, 0 };
|
||||
std::vector<Bar> bars;
|
||||
bars.push_back(Bar(flatbuffers::make_span(test_float_array1), 3));
|
||||
bars.push_back(Bar(flatbuffers::make_span(test_float_array2), 4));
|
||||
bars.push_back(Bar(flatbuffers::make_span(test_float_array3), 2));
|
||||
bars.push_back(Bar(flatbuffers::make_span(test_float_array4), 1));
|
||||
auto bar_vec = fbb.CreateVectorOfSortedStructs(&bars);
|
||||
|
||||
auto t = CreateFooTable(fbb, 1, 2, test_string, baz_vec, bar_vec);
|
||||
fbb.Finish(t);
|
||||
|
||||
uint8_t *buf = fbb.GetBufferPointer();
|
||||
auto foo_table = GetFooTable(buf);
|
||||
|
||||
auto sorted_baz_vec = foo_table->d();
|
||||
TEST_EQ(sorted_baz_vec->Get(0)->b(), 1);
|
||||
TEST_EQ(sorted_baz_vec->Get(3)->b(), 4);
|
||||
TEST_NOTNULL(
|
||||
sorted_baz_vec->LookupByKey(&flatbuffers::CastToArray(test_array1)));
|
||||
TEST_EQ(
|
||||
sorted_baz_vec->LookupByKey(&flatbuffers::CastToArray(test_array1))->b(),
|
||||
4);
|
||||
uint8_t array_int[4] = { 7, 2, 3, 0 };
|
||||
TEST_EQ(sorted_baz_vec->LookupByKey(&flatbuffers::CastToArray(array_int)),
|
||||
static_cast<const Baz *>(nullptr));
|
||||
|
||||
auto sorted_bar_vec = foo_table->e();
|
||||
TEST_EQ(sorted_bar_vec->Get(0)->b(), 1);
|
||||
TEST_EQ(sorted_bar_vec->Get(3)->b(), 4);
|
||||
TEST_NOTNULL(sorted_bar_vec->LookupByKey(
|
||||
&flatbuffers::CastToArray(test_float_array1)));
|
||||
TEST_EQ(
|
||||
sorted_bar_vec->LookupByKey(&flatbuffers::CastToArray(test_float_array1))
|
||||
->b(),
|
||||
3);
|
||||
float array_float[3] = { -1, -2, -3 };
|
||||
TEST_EQ(sorted_bar_vec->LookupByKey(&flatbuffers::CastToArray(array_float)),
|
||||
static_cast<const Bar *>(nullptr));
|
||||
}
|
||||
|
||||
} // namespace tests
|
||||
} // namespace flatbuffers
|
||||
12
tests/key_field_test.h
Normal file
12
tests/key_field_test.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef TESTS_KEY_FIELD_TEST_H
|
||||
#define TESTS_KEY_FIELD_TEST_H
|
||||
|
||||
namespace flatbuffers {
|
||||
namespace tests {
|
||||
|
||||
void FixedSizedScalarKeyInStructTest();
|
||||
|
||||
} // namespace tests
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif
|
||||
@@ -825,7 +825,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Ability FLATBUFFERS_FINAL_CLASS {
|
||||
void mutate_id(uint32_t _id) {
|
||||
flatbuffers::WriteScalar(&id_, _id);
|
||||
}
|
||||
bool KeyCompareLessThan(const Ability *o) const {
|
||||
bool KeyCompareLessThan(const Ability * const o) const {
|
||||
return id() < o->id();
|
||||
}
|
||||
int KeyCompareWithValue(uint32_t _id) const {
|
||||
@@ -1123,7 +1123,7 @@ struct Stat FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_count(uint16_t _count = 0) {
|
||||
return SetField<uint16_t>(VT_COUNT, _count, 0);
|
||||
}
|
||||
bool KeyCompareLessThan(const Stat *o) const {
|
||||
bool KeyCompareLessThan(const Stat * const o) const {
|
||||
return count() < o->count();
|
||||
}
|
||||
int KeyCompareWithValue(uint16_t _count) const {
|
||||
@@ -1213,7 +1213,7 @@ struct Referrable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_id(uint64_t _id = 0) {
|
||||
return SetField<uint64_t>(VT_ID, _id, 0);
|
||||
}
|
||||
bool KeyCompareLessThan(const Referrable *o) const {
|
||||
bool KeyCompareLessThan(const Referrable * const o) const {
|
||||
return id() < o->id();
|
||||
}
|
||||
int KeyCompareWithValue(uint64_t _id) const {
|
||||
@@ -1417,7 +1417,7 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
flatbuffers::String *mutable_name() {
|
||||
return GetPointer<flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
bool KeyCompareLessThan(const Monster *o) const {
|
||||
bool KeyCompareLessThan(const Monster * const o) const {
|
||||
return *name() < *o->name();
|
||||
}
|
||||
int KeyCompareWithValue(const char *_name) const {
|
||||
|
||||
@@ -825,7 +825,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Ability FLATBUFFERS_FINAL_CLASS {
|
||||
void mutate_id(uint32_t _id) {
|
||||
flatbuffers::WriteScalar(&id_, _id);
|
||||
}
|
||||
bool KeyCompareLessThan(const Ability *o) const {
|
||||
bool KeyCompareLessThan(const Ability * const o) const {
|
||||
return id() < o->id();
|
||||
}
|
||||
int KeyCompareWithValue(uint32_t _id) const {
|
||||
@@ -1123,7 +1123,7 @@ struct Stat FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_count(uint16_t _count = 0) {
|
||||
return SetField<uint16_t>(VT_COUNT, _count, 0);
|
||||
}
|
||||
bool KeyCompareLessThan(const Stat *o) const {
|
||||
bool KeyCompareLessThan(const Stat * const o) const {
|
||||
return count() < o->count();
|
||||
}
|
||||
int KeyCompareWithValue(uint16_t _count) const {
|
||||
@@ -1213,7 +1213,7 @@ struct Referrable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_id(uint64_t _id = 0) {
|
||||
return SetField<uint64_t>(VT_ID, _id, 0);
|
||||
}
|
||||
bool KeyCompareLessThan(const Referrable *o) const {
|
||||
bool KeyCompareLessThan(const Referrable * const o) const {
|
||||
return id() < o->id();
|
||||
}
|
||||
int KeyCompareWithValue(uint64_t _id) const {
|
||||
@@ -1417,7 +1417,7 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
flatbuffers::String *mutable_name() {
|
||||
return GetPointer<flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
bool KeyCompareLessThan(const Monster *o) const {
|
||||
bool KeyCompareLessThan(const Monster * const o) const {
|
||||
return *name() < *o->name();
|
||||
}
|
||||
int KeyCompareWithValue(const char *_name) const {
|
||||
|
||||
@@ -825,7 +825,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Ability FLATBUFFERS_FINAL_CLASS {
|
||||
void mutate_id(uint32_t _id) {
|
||||
flatbuffers::WriteScalar(&id_, _id);
|
||||
}
|
||||
bool KeyCompareLessThan(const Ability *o) const {
|
||||
bool KeyCompareLessThan(const Ability * const o) const {
|
||||
return id() < o->id();
|
||||
}
|
||||
int KeyCompareWithValue(uint32_t _id) const {
|
||||
@@ -1123,7 +1123,7 @@ struct Stat FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_count(uint16_t _count = 0) {
|
||||
return SetField<uint16_t>(VT_COUNT, _count, 0);
|
||||
}
|
||||
bool KeyCompareLessThan(const Stat *o) const {
|
||||
bool KeyCompareLessThan(const Stat * const o) const {
|
||||
return count() < o->count();
|
||||
}
|
||||
int KeyCompareWithValue(uint16_t _count) const {
|
||||
@@ -1213,7 +1213,7 @@ struct Referrable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_id(uint64_t _id = 0) {
|
||||
return SetField<uint64_t>(VT_ID, _id, 0);
|
||||
}
|
||||
bool KeyCompareLessThan(const Referrable *o) const {
|
||||
bool KeyCompareLessThan(const Referrable * const o) const {
|
||||
return id() < o->id();
|
||||
}
|
||||
int KeyCompareWithValue(uint64_t _id) const {
|
||||
@@ -1417,7 +1417,7 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
flatbuffers::String *mutable_name() {
|
||||
return GetPointer<flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
bool KeyCompareLessThan(const Monster *o) const {
|
||||
bool KeyCompareLessThan(const Monster * const o) const {
|
||||
return *name() < *o->name();
|
||||
}
|
||||
int KeyCompareWithValue(const char *_name) const {
|
||||
|
||||
@@ -825,7 +825,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Ability FLATBUFFERS_FINAL_CLASS {
|
||||
void mutate_id(uint32_t _id) {
|
||||
flatbuffers::WriteScalar(&id_, _id);
|
||||
}
|
||||
bool KeyCompareLessThan(const Ability *o) const {
|
||||
bool KeyCompareLessThan(const Ability * const o) const {
|
||||
return id() < o->id();
|
||||
}
|
||||
int KeyCompareWithValue(uint32_t _id) const {
|
||||
@@ -1123,7 +1123,7 @@ struct Stat FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_count(uint16_t _count = 0) {
|
||||
return SetField<uint16_t>(VT_COUNT, _count, 0);
|
||||
}
|
||||
bool KeyCompareLessThan(const Stat *o) const {
|
||||
bool KeyCompareLessThan(const Stat * const o) const {
|
||||
return count() < o->count();
|
||||
}
|
||||
int KeyCompareWithValue(uint16_t _count) const {
|
||||
@@ -1213,7 +1213,7 @@ struct Referrable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_id(uint64_t _id = 0) {
|
||||
return SetField<uint64_t>(VT_ID, _id, 0);
|
||||
}
|
||||
bool KeyCompareLessThan(const Referrable *o) const {
|
||||
bool KeyCompareLessThan(const Referrable * const o) const {
|
||||
return id() < o->id();
|
||||
}
|
||||
int KeyCompareWithValue(uint64_t _id) const {
|
||||
@@ -1417,7 +1417,7 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
flatbuffers::String *mutable_name() {
|
||||
return GetPointer<flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
bool KeyCompareLessThan(const Monster *o) const {
|
||||
bool KeyCompareLessThan(const Monster * const o) const {
|
||||
return *name() < *o->name();
|
||||
}
|
||||
int KeyCompareWithValue(const char *_name) const {
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "evolution_test.h"
|
||||
#include "alignment_test.h"
|
||||
#include "evolution_test.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/minireflect.h"
|
||||
@@ -29,10 +29,11 @@
|
||||
#include "flatbuffers/util.h"
|
||||
#include "fuzz_test.h"
|
||||
#include "json_test.h"
|
||||
#include "key_field_test.h"
|
||||
#include "monster_test.h"
|
||||
#include "monster_test_generated.h"
|
||||
#include "optional_scalars_test.h"
|
||||
#include "native_inline_table_test_generated.h"
|
||||
#include "optional_scalars_test.h"
|
||||
#include "parser_test.h"
|
||||
#include "proto_test.h"
|
||||
#include "reflection_test.h"
|
||||
@@ -1418,7 +1419,7 @@ void NativeInlineTableVectorTest() {
|
||||
TEST_ASSERT(unpacked.t == test.t);
|
||||
}
|
||||
|
||||
void DoNotRequireEofTest(const std::string& tests_data_path) {
|
||||
void DoNotRequireEofTest(const std::string &tests_data_path) {
|
||||
std::string schemafile;
|
||||
bool ok = flatbuffers::LoadFile(
|
||||
(tests_data_path + "monster_test.fbs").c_str(), false, &schemafile);
|
||||
@@ -1432,7 +1433,7 @@ void DoNotRequireEofTest(const std::string& tests_data_path) {
|
||||
flatbuffers::Parser parser(opt);
|
||||
ok = parser.Parse(schemafile.c_str(), include_directories);
|
||||
TEST_EQ(ok, true);
|
||||
|
||||
|
||||
const char *str = R"(This string contains two monsters, the first one is {
|
||||
"name": "Blob",
|
||||
"hp": 5
|
||||
@@ -1449,7 +1450,7 @@ void DoNotRequireEofTest(const std::string& tests_data_path) {
|
||||
const Monster *monster = GetMonster(parser.builder_.GetBufferPointer());
|
||||
TEST_EQ_STR(monster->name()->c_str(), "Blob");
|
||||
TEST_EQ(monster->hp(), 5);
|
||||
|
||||
|
||||
tableStart += parser.BytesConsumed();
|
||||
|
||||
tableStart = std::strchr(tableStart + 1, '{');
|
||||
@@ -1564,6 +1565,7 @@ int FlatBufferTests(const std::string &tests_data_path) {
|
||||
JsonUnsortedArrayTest();
|
||||
VectorSpanTest();
|
||||
NativeInlineTableVectorTest();
|
||||
FixedSizedScalarKeyInStructTest();
|
||||
return 0;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user