mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-20 22:57:32 +00:00
Removal of support for FLATBUFFERS_CPP98_STL (#6918)
* Removal of support for FLATBUFFERS_CPP98_STL For context, see https://github.com/google/flatbuffers/issues/6704 * Also removed vector_data
This commit is contained in:
committed by
GitHub
parent
3fab0c6ee4
commit
6748c373be
@@ -229,7 +229,6 @@ struct AnyUnion {
|
||||
|
||||
void Reset();
|
||||
|
||||
#ifndef FLATBUFFERS_CPP98_STL
|
||||
template <typename T>
|
||||
void Set(T&& val) {
|
||||
using RT = typename std::remove_reference<T>::type;
|
||||
@@ -239,7 +238,6 @@ struct AnyUnion {
|
||||
value = new RT(std::forward<T>(val));
|
||||
}
|
||||
}
|
||||
#endif // FLATBUFFERS_CPP98_STL
|
||||
|
||||
static void *UnPack(const void *obj, Any type, const flatbuffers::resolver_function_t *resolver);
|
||||
flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
|
||||
@@ -342,7 +340,6 @@ struct AnyUniqueAliasesUnion {
|
||||
|
||||
void Reset();
|
||||
|
||||
#ifndef FLATBUFFERS_CPP98_STL
|
||||
template <typename T>
|
||||
void Set(T&& val) {
|
||||
using RT = typename std::remove_reference<T>::type;
|
||||
@@ -352,7 +349,6 @@ struct AnyUniqueAliasesUnion {
|
||||
value = new RT(std::forward<T>(val));
|
||||
}
|
||||
}
|
||||
#endif // FLATBUFFERS_CPP98_STL
|
||||
|
||||
static void *UnPack(const void *obj, AnyUniqueAliases type, const flatbuffers::resolver_function_t *resolver);
|
||||
flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
|
||||
|
||||
@@ -259,7 +259,6 @@ struct AnyUnion {
|
||||
|
||||
void Reset();
|
||||
|
||||
#ifndef FLATBUFFERS_CPP98_STL
|
||||
template <typename T>
|
||||
void Set(T&& val) {
|
||||
using RT = typename std::remove_reference<T>::type;
|
||||
@@ -269,7 +268,6 @@ struct AnyUnion {
|
||||
value = new RT(std::forward<T>(val));
|
||||
}
|
||||
}
|
||||
#endif // FLATBUFFERS_CPP98_STL
|
||||
|
||||
static void *UnPack(const void *obj, Any type, const flatbuffers::resolver_function_t *resolver);
|
||||
flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
|
||||
@@ -401,7 +399,6 @@ struct AnyUniqueAliasesUnion {
|
||||
|
||||
void Reset();
|
||||
|
||||
#ifndef FLATBUFFERS_CPP98_STL
|
||||
template <typename T>
|
||||
void Set(T&& val) {
|
||||
using RT = typename std::remove_reference<T>::type;
|
||||
@@ -411,7 +408,6 @@ struct AnyUniqueAliasesUnion {
|
||||
value = new RT(std::forward<T>(val));
|
||||
}
|
||||
}
|
||||
#endif // FLATBUFFERS_CPP98_STL
|
||||
|
||||
static void *UnPack(const void *obj, AnyUniqueAliases type, const flatbuffers::resolver_function_t *resolver);
|
||||
flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
|
||||
|
||||
@@ -79,7 +79,6 @@ struct UnionInNestedNSUnion {
|
||||
|
||||
void Reset();
|
||||
|
||||
#ifndef FLATBUFFERS_CPP98_STL
|
||||
template <typename T>
|
||||
void Set(T&& val) {
|
||||
using RT = typename std::remove_reference<T>::type;
|
||||
@@ -89,7 +88,6 @@ struct UnionInNestedNSUnion {
|
||||
value = new RT(std::forward<T>(val));
|
||||
}
|
||||
}
|
||||
#endif // FLATBUFFERS_CPP98_STL
|
||||
|
||||
static void *UnPack(const void *obj, UnionInNestedNS type, const flatbuffers::resolver_function_t *resolver);
|
||||
flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
|
||||
|
||||
120
tests/test.cpp
120
tests/test.cpp
@@ -22,14 +22,6 @@
|
||||
#include "flatbuffers/registry.h"
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
// clang-format off
|
||||
#ifdef FLATBUFFERS_CPP98_STL
|
||||
namespace std {
|
||||
using flatbuffers::unique_ptr;
|
||||
}
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
#include "monster_test_generated.h"
|
||||
#include "namespace_test/namespace_test1_generated.h"
|
||||
#include "namespace_test/namespace_test2_generated.h"
|
||||
@@ -107,21 +99,11 @@ flatbuffers::DetachedBuffer CreateFlatBufferTest(std::string &buffer) {
|
||||
Test tests[] = { Test(10, 20), Test(30, 40) };
|
||||
auto testv = builder.CreateVectorOfStructs(tests, 2);
|
||||
|
||||
// clang-format off
|
||||
#ifndef FLATBUFFERS_CPP98_STL
|
||||
// Create a vector of structures from a lambda.
|
||||
auto testv2 = builder.CreateVectorOfStructs<Test>(
|
||||
2, [&](size_t i, Test* s) -> void {
|
||||
*s = tests[i];
|
||||
});
|
||||
#else
|
||||
// Create a vector of structures using a plain old C++ function.
|
||||
auto testv2 = builder.CreateVectorOfStructs<Test>(
|
||||
2, [](size_t i, Test* s, void *state) -> void {
|
||||
*s = (reinterpret_cast<Test*>(state))[i];
|
||||
}, tests);
|
||||
#endif // FLATBUFFERS_CPP98_STL
|
||||
// clang-format on
|
||||
// Create a vector of structures from a lambda.
|
||||
auto testv2 = builder.CreateVectorOfStructs<Test>(
|
||||
2, [&](size_t i, Test* s) -> void {
|
||||
*s = tests[i];
|
||||
});
|
||||
|
||||
// create monster with very few fields set:
|
||||
// (same functionality as CreateMonster below, but sets fields manually)
|
||||
@@ -1071,8 +1053,7 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
|
||||
// Get the root.
|
||||
// This time we wrap the result from GetAnyRoot in a smartpointer that
|
||||
// will keep rroot valid as resizingbuf resizes.
|
||||
auto rroot = flatbuffers::piv(
|
||||
flatbuffers::GetAnyRoot(flatbuffers::vector_data(resizingbuf)),
|
||||
auto rroot = flatbuffers::piv(flatbuffers::GetAnyRoot(resizingbuf.data()),
|
||||
resizingbuf);
|
||||
SetString(schema, "totally new string", GetFieldS(**rroot, name_field),
|
||||
&resizingbuf);
|
||||
@@ -1117,13 +1098,12 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
|
||||
TEST_EQ_STR(rtestarrayofstring->Get(2)->c_str(), "hank");
|
||||
// Test integrity of all resize operations above.
|
||||
flatbuffers::Verifier resize_verifier(
|
||||
reinterpret_cast<const uint8_t *>(flatbuffers::vector_data(resizingbuf)),
|
||||
reinterpret_cast<const uint8_t *>(resizingbuf.data()),
|
||||
resizingbuf.size());
|
||||
TEST_EQ(VerifyMonsterBuffer(resize_verifier), true);
|
||||
|
||||
// Test buffer is valid using reflection as well
|
||||
TEST_EQ(flatbuffers::Verify(schema, *schema.root_table(),
|
||||
flatbuffers::vector_data(resizingbuf),
|
||||
TEST_EQ(flatbuffers::Verify(schema, *schema.root_table(), resizingbuf.data(),
|
||||
resizingbuf.size()),
|
||||
true);
|
||||
|
||||
@@ -3000,60 +2980,36 @@ void FlexBuffersTest() {
|
||||
// Write the equivalent of:
|
||||
// { vec: [ -100, "Fred", 4.0, false ], bar: [ 1, 2, 3 ], bar3: [ 1, 2, 3 ],
|
||||
// foo: 100, bool: true, mymap: { foo: "Fred" } }
|
||||
// clang-format off
|
||||
#ifndef FLATBUFFERS_CPP98_STL
|
||||
// It's possible to do this without std::function support as well.
|
||||
slb.Map([&]() {
|
||||
slb.Vector("vec", [&]() {
|
||||
slb += -100; // Equivalent to slb.Add(-100) or slb.Int(-100);
|
||||
slb += "Fred";
|
||||
slb.IndirectFloat(4.0f);
|
||||
auto i_f = slb.LastValue();
|
||||
uint8_t blob[] = { 77 };
|
||||
slb.Blob(blob, 1);
|
||||
slb += false;
|
||||
slb.ReuseValue(i_f);
|
||||
});
|
||||
int ints[] = { 1, 2, 3 };
|
||||
slb.Vector("bar", ints, 3);
|
||||
slb.FixedTypedVector("bar3", ints, 3);
|
||||
bool bools[] = {true, false, true, false};
|
||||
slb.Vector("bools", bools, 4);
|
||||
slb.Bool("bool", true);
|
||||
slb.Double("foo", 100);
|
||||
slb.Map("mymap", [&]() {
|
||||
slb.String("foo", "Fred"); // Testing key and string reuse.
|
||||
});
|
||||
});
|
||||
slb.Finish();
|
||||
#else
|
||||
// It's possible to do this without std::function support as well.
|
||||
slb.Map([](flexbuffers::Builder& slb2) {
|
||||
slb2.Vector("vec", [](flexbuffers::Builder& slb3) {
|
||||
slb3 += -100; // Equivalent to slb.Add(-100) or slb.Int(-100);
|
||||
slb3 += "Fred";
|
||||
slb3.IndirectFloat(4.0f);
|
||||
auto i_f = slb3.LastValue();
|
||||
uint8_t blob[] = { 77 };
|
||||
slb3.Blob(blob, 1);
|
||||
slb3 += false;
|
||||
slb3.ReuseValue(i_f);
|
||||
}, slb2);
|
||||
int ints[] = { 1, 2, 3 };
|
||||
slb2.Vector("bar", ints, 3);
|
||||
slb2.FixedTypedVector("bar3", ints, 3);
|
||||
slb2.Bool("bool", true);
|
||||
slb2.Double("foo", 100);
|
||||
slb2.Map("mymap", [](flexbuffers::Builder& slb3) {
|
||||
slb3.String("foo", "Fred"); // Testing key and string reuse.
|
||||
}, slb2);
|
||||
}, slb);
|
||||
slb.Finish();
|
||||
#endif // FLATBUFFERS_CPP98_STL
|
||||
|
||||
// It's possible to do this without std::function support as well.
|
||||
slb.Map([&]() {
|
||||
slb.Vector("vec", [&]() {
|
||||
slb += -100; // Equivalent to slb.Add(-100) or slb.Int(-100);
|
||||
slb += "Fred";
|
||||
slb.IndirectFloat(4.0f);
|
||||
auto i_f = slb.LastValue();
|
||||
uint8_t blob[] = { 77 };
|
||||
slb.Blob(blob, 1);
|
||||
slb += false;
|
||||
slb.ReuseValue(i_f);
|
||||
});
|
||||
int ints[] = { 1, 2, 3 };
|
||||
slb.Vector("bar", ints, 3);
|
||||
slb.FixedTypedVector("bar3", ints, 3);
|
||||
bool bools[] = {true, false, true, false};
|
||||
slb.Vector("bools", bools, 4);
|
||||
slb.Bool("bool", true);
|
||||
slb.Double("foo", 100);
|
||||
slb.Map("mymap", [&]() {
|
||||
slb.String("foo", "Fred"); // Testing key and string reuse.
|
||||
});
|
||||
});
|
||||
slb.Finish();
|
||||
|
||||
// clang-format off
|
||||
#ifdef FLATBUFFERS_TEST_VERBOSE
|
||||
for (size_t i = 0; i < slb.GetBuffer().size(); i++)
|
||||
printf("%d ", flatbuffers::vector_data(slb.GetBuffer())[i]);
|
||||
printf("%d ", slb.GetBuffer().data()[i]);
|
||||
printf("\n");
|
||||
#endif
|
||||
// clang-format on
|
||||
@@ -4142,11 +4098,7 @@ int FlatBufferTests() {
|
||||
|
||||
std::string rawbuf;
|
||||
auto flatbuf1 = CreateFlatBufferTest(rawbuf);
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
auto flatbuf = std::move(flatbuf1); // Test move assignment.
|
||||
#else
|
||||
auto &flatbuf = flatbuf1;
|
||||
#endif // !defined(FLATBUFFERS_CPP98_STL)
|
||||
auto flatbuf = std::move(flatbuf1); // Test move assignment.
|
||||
|
||||
TriviallyCopyableTest();
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ struct underlying_of_scalar {
|
||||
template<typename T> struct underlying_of_scalar<T, true> {
|
||||
// clang-format off
|
||||
// There are old compilers without full C++11 support (see stl_emulation.h).
|
||||
#if defined(FLATBUFFERS_TEMPLATES_ALIASES) && !defined(FLATBUFFERS_CPP98_STL)
|
||||
#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
|
||||
using type = typename std::underlying_type<T>::type;
|
||||
#else
|
||||
typedef int64_t type;
|
||||
|
||||
@@ -9,20 +9,13 @@ struct OwnedAllocator : public flatbuffers::DefaultAllocator {};
|
||||
|
||||
class TestHeapBuilder : public flatbuffers::FlatBufferBuilder {
|
||||
private:
|
||||
// clang-format off
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
TestHeapBuilder(const TestHeapBuilder &);
|
||||
TestHeapBuilder &operator=(const TestHeapBuilder &);
|
||||
#endif // !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
|
||||
public:
|
||||
TestHeapBuilder()
|
||||
: flatbuffers::FlatBufferBuilder(2048, new OwnedAllocator(), true) {}
|
||||
|
||||
// clang-format off
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
TestHeapBuilder(TestHeapBuilder &&other)
|
||||
: FlatBufferBuilder(std::move(other)) {}
|
||||
|
||||
@@ -30,9 +23,6 @@ class TestHeapBuilder : public flatbuffers::FlatBufferBuilder {
|
||||
FlatBufferBuilder::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
// clang-format off
|
||||
#endif // !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
// This class simulates flatbuffers::grpc::detail::SliceAllocatorMember
|
||||
@@ -56,18 +46,12 @@ struct GrpcLikeMessageBuilder : private AllocatorMember,
|
||||
Swap(other);
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
GrpcLikeMessageBuilder &operator=(GrpcLikeMessageBuilder &&other) {
|
||||
// Construct temporary and swap idiom
|
||||
GrpcLikeMessageBuilder temp(std::move(other));
|
||||
Swap(temp);
|
||||
return *this;
|
||||
}
|
||||
// clang-format off
|
||||
#endif // !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
|
||||
void Swap(GrpcLikeMessageBuilder &other) {
|
||||
// No need to swap member_allocator_ because it's stateless.
|
||||
@@ -155,4 +139,4 @@ void FlatBufferBuilderTest() {
|
||||
}
|
||||
|
||||
// Link-time check using pointer type.
|
||||
void CheckTestGeneratedIsValid(const MyGame::Example::Color &) {}
|
||||
void CheckTestGeneratedIsValid(const MyGame::Example::Color &) {}
|
||||
|
||||
@@ -54,9 +54,6 @@ bool release_n_verify(flatbuffers::FlatBufferBuilder &fbb,
|
||||
bool release_n_verify(flatbuffers::grpc::MessageBuilder &mbb,
|
||||
const std::string &expected_name, Color color);
|
||||
|
||||
// clang-format off
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
// Invokes this function when testing the following Builder types
|
||||
// FlatBufferBuilder, TestHeapBuilder, and GrpcLikeMessageBuilder
|
||||
template<class Builder>
|
||||
@@ -78,18 +75,12 @@ void builder_move_assign_after_releaseraw_test(Builder b1) {
|
||||
TEST_ASSERT_FUNC(release_n_verify(b1, m2_name(), m2_color()));
|
||||
TEST_EQ_FUNC(src.GetSize(), 0);
|
||||
}
|
||||
// clang-format off
|
||||
#endif // !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
|
||||
void builder_move_assign_after_releaseraw_test(
|
||||
flatbuffers::grpc::MessageBuilder b1);
|
||||
|
||||
template<class DestBuilder, class SrcBuilder = DestBuilder>
|
||||
struct BuilderTests {
|
||||
// clang-format off
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
static void empty_builder_movector_test() {
|
||||
SrcBuilder src;
|
||||
size_t src_size = src.GetSize();
|
||||
@@ -171,9 +162,6 @@ struct BuilderTests {
|
||||
TEST_ASSERT_FUNC(release_n_verify(dst, m2_name(), m2_color()));
|
||||
TEST_EQ_FUNC(src.GetSize(), 0);
|
||||
}
|
||||
// clang-format off
|
||||
#endif // !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
|
||||
static void builder_swap_before_finish_test(
|
||||
bool run = is_same<DestBuilder, SrcBuilder>::value) {
|
||||
@@ -216,9 +204,6 @@ struct BuilderTests {
|
||||
}
|
||||
|
||||
static void all_tests() {
|
||||
// clang-format off
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
empty_builder_movector_test();
|
||||
nonempty_builder_movector_test();
|
||||
builder_movector_before_finish_test();
|
||||
@@ -227,9 +212,6 @@ struct BuilderTests {
|
||||
builder_move_assign_after_finish_test();
|
||||
builder_move_assign_after_release_test();
|
||||
builder_move_assign_after_releaseraw_test(DestBuilder());
|
||||
// clang-format off
|
||||
#endif // !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
builder_swap_before_finish_test();
|
||||
builder_swap_after_finish_test();
|
||||
}
|
||||
@@ -274,9 +256,6 @@ template<class DestBuilder, class SrcBuilder> struct BuilderReuseTests {
|
||||
}
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
static void builder_reusable_after_release_and_move_assign_test(
|
||||
TestSelector selector) {
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_AND_MOVE_ASSIGN)) { return; }
|
||||
@@ -311,21 +290,12 @@ template<class DestBuilder, class SrcBuilder> struct BuilderReuseTests {
|
||||
TEST_EQ_FUNC(src.GetSize(), 0);
|
||||
}
|
||||
}
|
||||
// clang-format off
|
||||
#endif // !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
|
||||
static void run_tests(TestSelector selector) {
|
||||
builder_reusable_after_release_test(selector);
|
||||
builder_reusable_after_releaseraw_test(selector);
|
||||
// clang-format off
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
builder_reusable_after_release_and_move_assign_test(selector);
|
||||
builder_reusable_after_releaseraw_and_move_assign_test(selector);
|
||||
// clang-format off
|
||||
#endif // !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user