Test case for CreateVectorOfStructs() using a callback.

Fixes issue #4392, also fixed C++98 compatible code generation in tests.

Change-Id: Ia5833026e615ad19d24a0439bdba2e3b45c5f86c
This commit is contained in:
Stewart Miles
2017-07-24 14:11:59 -07:00
parent d6f14b704f
commit f064a6cc60
21 changed files with 284 additions and 43 deletions

View File

@@ -547,6 +547,7 @@ struct MonsterT : public flatbuffers::NativeTable {
std::vector<std::string> testarrayofstring2;
std::vector<Ability> testarrayofsortedstruct;
std::vector<uint8_t> flex;
std::vector<Test> test5;
MonsterT()
: mana(150),
hp(100),
@@ -599,7 +600,8 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
VT_TESTF3 = 58,
VT_TESTARRAYOFSTRING2 = 60,
VT_TESTARRAYOFSORTEDSTRUCT = 62,
VT_FLEX = 64
VT_FLEX = 64,
VT_TEST5 = 66
};
const Vec3 *pos() const {
return GetStruct<const Vec3 *>(VT_POS);
@@ -807,6 +809,12 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
auto v = flex();
return flexbuffers::GetRoot(v->Data(), v->size());
}
const flatbuffers::Vector<const Test *> *test5() const {
return GetPointer<const flatbuffers::Vector<const Test *> *>(VT_TEST5);
}
flatbuffers::Vector<const Test *> *mutable_test5() {
return GetPointer<flatbuffers::Vector<const Test *> *>(VT_TEST5);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<Vec3>(verifier, VT_POS) &&
@@ -855,6 +863,8 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
verifier.Verify(testarrayofsortedstruct()) &&
VerifyOffset(verifier, VT_FLEX) &&
verifier.Verify(flex()) &&
VerifyOffset(verifier, VT_TEST5) &&
verifier.Verify(test5()) &&
verifier.EndTable();
}
MonsterT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
@@ -967,13 +977,16 @@ struct MonsterBuilder {
void add_flex(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> flex) {
fbb_.AddOffset(Monster::VT_FLEX, flex);
}
void add_test5(flatbuffers::Offset<flatbuffers::Vector<const Test *>> test5) {
fbb_.AddOffset(Monster::VT_TEST5, test5);
}
MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
MonsterBuilder &operator=(const MonsterBuilder &);
flatbuffers::Offset<Monster> Finish() {
const auto end = fbb_.EndTable(start_, 31);
const auto end = fbb_.EndTable(start_, 32);
auto o = flatbuffers::Offset<Monster>(end);
fbb_.Required(o, Monster::VT_NAME);
return o;
@@ -1011,12 +1024,14 @@ inline flatbuffers::Offset<Monster> CreateMonster(
float testf3 = 0.0f,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> testarrayofstring2 = 0,
flatbuffers::Offset<flatbuffers::Vector<const Ability *>> testarrayofsortedstruct = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> flex = 0) {
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> flex = 0,
flatbuffers::Offset<flatbuffers::Vector<const Test *>> test5 = 0) {
MonsterBuilder builder_(_fbb);
builder_.add_testhashu64_fnv1a(testhashu64_fnv1a);
builder_.add_testhashs64_fnv1a(testhashs64_fnv1a);
builder_.add_testhashu64_fnv1(testhashu64_fnv1);
builder_.add_testhashs64_fnv1(testhashs64_fnv1);
builder_.add_test5(test5);
builder_.add_flex(flex);
builder_.add_testarrayofsortedstruct(testarrayofsortedstruct);
builder_.add_testarrayofstring2(testarrayofstring2);
@@ -1077,7 +1092,8 @@ inline flatbuffers::Offset<Monster> CreateMonsterDirect(
float testf3 = 0.0f,
const std::vector<flatbuffers::Offset<flatbuffers::String>> *testarrayofstring2 = nullptr,
const std::vector<const Ability *> *testarrayofsortedstruct = nullptr,
const std::vector<uint8_t> *flex = nullptr) {
const std::vector<uint8_t> *flex = nullptr,
const std::vector<const Test *> *test5 = nullptr) {
return MyGame::Example::CreateMonster(
_fbb,
pos,
@@ -1109,7 +1125,8 @@ inline flatbuffers::Offset<Monster> CreateMonsterDirect(
testf3,
testarrayofstring2 ? _fbb.CreateVector<flatbuffers::Offset<flatbuffers::String>>(*testarrayofstring2) : 0,
testarrayofsortedstruct ? _fbb.CreateVector<const Ability *>(*testarrayofsortedstruct) : 0,
flex ? _fbb.CreateVector<uint8_t>(*flex) : 0);
flex ? _fbb.CreateVector<uint8_t>(*flex) : 0,
test5 ? _fbb.CreateVector<const Test *>(*test5) : 0);
}
flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
@@ -1242,6 +1259,7 @@ inline void Monster::UnPackTo(MonsterT *_o, const flatbuffers::resolver_function
{ auto _e = testarrayofstring2(); if (_e) { _o->testarrayofstring2.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->testarrayofstring2[_i] = _e->Get(_i)->str(); } } };
{ auto _e = testarrayofsortedstruct(); if (_e) { _o->testarrayofsortedstruct.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->testarrayofsortedstruct[_i] = *_e->Get(_i); } } };
{ auto _e = flex(); if (_e) { _o->flex.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->flex[_i] = _e->Get(_i); } } };
{ auto _e = test5(); if (_e) { _o->test5.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->test5[_i] = *_e->Get(_i); } } };
}
inline flatbuffers::Offset<Monster> Monster::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
@@ -1282,6 +1300,7 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
auto _testarrayofstring2 = _o->testarrayofstring2.size() ? _fbb.CreateVectorOfStrings(_o->testarrayofstring2) : 0;
auto _testarrayofsortedstruct = _o->testarrayofsortedstruct.size() ? _fbb.CreateVectorOfStructs(_o->testarrayofsortedstruct) : 0;
auto _flex = _o->flex.size() ? _fbb.CreateVector(_o->flex) : 0;
auto _test5 = _o->test5.size() ? _fbb.CreateVectorOfStructs(_o->test5) : 0;
return MyGame::Example::CreateMonster(
_fbb,
_pos,
@@ -1313,7 +1332,8 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
_testf3,
_testarrayofstring2,
_testarrayofsortedstruct,
_flex);
_flex,
_test5);
}
inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *obj, Any type) {