mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 12:05:50 +00:00
C++98 (stlport) support for core FlatBuffers and FlexBuffers.
* Added internal - limited - implementation of flatbuffers::unique_ptr for STLs that don't ship with std::unique_ptr. In C++11 and beyond this is just an alias for std::unique_ptr. * Aliased used type traits structs is_scalar is_floating_point is_unsigned into flatbuffers namespace so they can be replaced in C++98 implementations. Right now these point at stlport's TR1 implementations. * Wrapped vector::data() in vector_data(). * Wrapped vector::emplace_back() in vector_emplace_back(). * Wrapper string::back() in string_back(). * Added variants of FlatBufferBuilder::CreateVector() and FlatBufferBuilder::CreateVectorOfStructs() that allow the use of plain function pointers. Generated code has also been modified to use plain functions to build objects rather than std::function() so all generated code will work in C++98 applications. * Added flexbuffers::Builder::Vector(), flexbuffers::Builder::TypedVector() and flexbuffers::Builder::Map() methods that allow the use of plain function pointers. * Changed Parser to internally use plain function pointers when parsing table and vector delimiters. * Added specializations of NumToString() for 64-bit types that aren't supported by stringstream in stlport. * Overloaded numeric_limits for 64-bit types not supported by stlport. * Replaced build_apk.sh (which was broken by deprecation of the "android" tool in the Android SDK) with build.gradle and the appropriate gradle wrapper to build an APK. * Switched Android build to build against all STL variants. * Updated travis configuration to build Android test and sample. Tested: * Verified all tests continue to work on Linux, OSX and Android. * Verified Travis build is green. Change-Id: I9e634363793f85b9f141d21454b10686020a2065
This commit is contained in:
@@ -722,6 +722,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += " void Reset();";
|
||||
code_ += "";
|
||||
if (!enum_def.uses_type_aliases) {
|
||||
code_ += "#ifndef FLATBUFFERS_CPP98_STL";
|
||||
code_ += " template <typename T>";
|
||||
code_ += " void Set(T&& val) {";
|
||||
code_ += " Reset();";
|
||||
@@ -730,6 +731,7 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += " value = new T(std::forward<T>(val));";
|
||||
code_ += " }";
|
||||
code_ += " }";
|
||||
code_ += "#endif // FLATBUFFERS_CPP98_STL";
|
||||
code_ += "";
|
||||
}
|
||||
code_ += " " + UnionUnPackSignature(enum_def, true) + ";";
|
||||
@@ -1802,11 +1804,13 @@ class CppGenerator : public BaseGenerator {
|
||||
code += "(" + value + ")";
|
||||
} else {
|
||||
code += "_fbb.CreateVector<flatbuffers::Offset<";
|
||||
code += WrapInNameSpace(*vector_type.struct_def) + ">>";
|
||||
code += "(" + value + ".size(), [&](size_t i) {";
|
||||
code += " return Create" + vector_type.struct_def->name;
|
||||
code += "(_fbb, " + value + "[i]" + GenPtrGet(field) + ", ";
|
||||
code += "_rehasher); })";
|
||||
code += WrapInNameSpace(*vector_type.struct_def) + ">> ";
|
||||
code += "(" + value + ".size(), ";
|
||||
code += "[](size_t i, _VectorArgs *__va) { ";
|
||||
code += "return Create" + vector_type.struct_def->name;
|
||||
code += "(*__va->__fbb, __va->_" + value + "[i]" +
|
||||
GenPtrGet(field) + ", ";
|
||||
code += "__va->__rehasher); }, &_va )";
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1815,16 +1819,19 @@ class CppGenerator : public BaseGenerator {
|
||||
break;
|
||||
}
|
||||
case BASE_TYPE_UNION: {
|
||||
code += "_fbb.CreateVector<flatbuffers::Offset<void>>(" + value +
|
||||
".size(), [&](size_t i) { return " + value +
|
||||
"[i].Pack(_fbb, _rehasher); })";
|
||||
code += "_fbb.CreateVector<flatbuffers::"
|
||||
"Offset<void>>(" + value +
|
||||
".size(), [](size_t i, _VectorArgs *__va) { "
|
||||
"return __va->_" + value +
|
||||
"[i].Pack(*__va->__fbb, __va->__rehasher); }, &_va)";
|
||||
break;
|
||||
}
|
||||
case BASE_TYPE_UTYPE: {
|
||||
value = StripUnionType(value);
|
||||
code += "_fbb.CreateVector<uint8_t>(" + value +
|
||||
".size(), [&](size_t i) { return static_cast<uint8_t>(" + value +
|
||||
"[i].type); })";
|
||||
".size(), [](size_t i, _VectorArgs *__va) { "
|
||||
"return static_cast<uint8_t>(__va->_" + value +
|
||||
"[i].type); }, &_va)";
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -1935,6 +1942,15 @@ class CppGenerator : public BaseGenerator {
|
||||
code_ += " (void)_rehasher;";
|
||||
code_ += " (void)_o;";
|
||||
|
||||
code_ +=
|
||||
" struct _VectorArgs "
|
||||
"{ flatbuffers::FlatBufferBuilder *__fbb; "
|
||||
"const " +
|
||||
NativeName(struct_def.name, &struct_def) +
|
||||
"* __o; "
|
||||
"const flatbuffers::rehasher_function_t *__rehasher; } _va = { "
|
||||
"&_fbb, _o, _rehasher}; (void)_va;";
|
||||
|
||||
for (auto it = struct_def.fields.vec.begin();
|
||||
it != struct_def.fields.vec.end(); ++it) {
|
||||
auto &field = **it;
|
||||
|
||||
Reference in New Issue
Block a user