From bdd668df7b9be266ff756e6493e0859cc880880d Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Wed, 20 Jul 2016 18:13:11 -0700 Subject: [PATCH] Fixed VS2010 build --- build_ide/VS2010/flatc.vcxproj.user | 2 +- src/idl_gen_cpp.cpp | 10 +++++++--- tests/monster_test_generated.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/build_ide/VS2010/flatc.vcxproj.user b/build_ide/VS2010/flatc.vcxproj.user index 5ef05f7e3..1132b8ab9 100755 --- a/build_ide/VS2010/flatc.vcxproj.user +++ b/build_ide/VS2010/flatc.vcxproj.user @@ -3,7 +3,7 @@ ..\..\tests WindowsLocalDebugger - -j -c -n -g --php --no-includes --gen-mutable monster_test.fbs + -j -c -n -g --php --no-includes --gen-mutable --gen-object-api monster_test.fbs ..\.. diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 890ab9298..cf85a93b8 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -966,7 +966,7 @@ class CppGenerator : public BaseGenerator { auto dest = deref + field.name; auto assign = prefix + dest + " = "; auto gen_unpack_val = [&](const Type &type, const std::string &val, - bool invector) { + bool invector) -> std::string { switch (type.base_type) { case BASE_TYPE_STRING: return val + "->str()"; @@ -987,14 +987,18 @@ class CppGenerator : public BaseGenerator { } }; switch (field.value.type.base_type) { - case BASE_TYPE_VECTOR: + case BASE_TYPE_VECTOR: { code += prefix; code += "{ for (size_t _i = 0; _i < _e->size(); _i++) { "; code += dest + ".push_back("; + std::string indexing = "_e->Get(_i)"; + if (field.value.type.element == BASE_TYPE_BOOL) + indexing += "!=0"; code += gen_unpack_val(field.value.type.VectorType(), - "_e->Get(_i)", true); + indexing, true); code += "); } }"; break; + } case BASE_TYPE_UTYPE: { auto &union_field = **(it + 1); assert(union_field.value.type.base_type == BASE_TYPE_UNION); diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index da27de74d..86f388fa8 100644 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -645,7 +645,7 @@ inline std::unique_ptr Monster::UnPack() const { { auto _e = testhashu32_fnv1a(); _o->testhashu32_fnv1a = _e; }; { auto _e = testhashs64_fnv1a(); _o->testhashs64_fnv1a = _e; }; { auto _e = testhashu64_fnv1a(); _o->testhashu64_fnv1a = _e; }; - { auto _e = testarrayofbools(); if (_e) { for (size_t _i = 0; _i < _e->size(); _i++) { _o->testarrayofbools.push_back(_e->Get(_i)); } } }; + { auto _e = testarrayofbools(); if (_e) { for (size_t _i = 0; _i < _e->size(); _i++) { _o->testarrayofbools.push_back(_e->Get(_i)!=0); } } }; { auto _e = testf(); _o->testf = _e; }; { auto _e = testf2(); _o->testf2 = _e; }; { auto _e = testf3(); _o->testf3 = _e; };