Skip to content

Commit

Permalink
Removal of support for FLATBUFFERS_CPP98_STL (#6918)
Browse files Browse the repository at this point in the history
* Removal of support for FLATBUFFERS_CPP98_STL

For context, see #6704

* Also removed vector_data
  • Loading branch information
aardappel committed Nov 12, 2021
1 parent 3fab0c6 commit 6748c37
Show file tree
Hide file tree
Showing 29 changed files with 118 additions and 544 deletions.
10 changes: 0 additions & 10 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ android {

flavorDimensions "stl-variant"
productFlavors {
stlport {
dimension "stl-variant"
applicationIdSuffix ".stlport"
versionNameSuffix "-stlport"
externalNativeBuild {
ndkBuild {
arguments "APP_STL=stlport_static"
}
}
}
gnustl {
dimension "stl-variant"
applicationIdSuffix ".gnustl"
Expand Down
4 changes: 0 additions & 4 deletions include/flatbuffers/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@
#include <unistd.h>
#endif

#ifdef _STLPORT_VERSION
#define FLATBUFFERS_CPP98_STL
#endif

#ifdef __ANDROID__
#include <android/api-level.h>
#endif
Expand Down
20 changes: 1 addition & 19 deletions include/flatbuffers/detached_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ class DetachedBuffer {
cur_(cur),
size_(sz) {}

// clang-format off
#if !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
DetachedBuffer(DetachedBuffer &&other)
: allocator_(other.allocator_),
own_allocator_(other.own_allocator_),
Expand All @@ -57,13 +54,7 @@ class DetachedBuffer {
size_(other.size_) {
other.reset();
}
// clang-format off
#endif // !defined(FLATBUFFERS_CPP98_STL)
// clang-format on

// clang-format off
#if !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
DetachedBuffer &operator=(DetachedBuffer &&other) {
if (this == &other) return *this;

Expand All @@ -80,9 +71,6 @@ class DetachedBuffer {

return *this;
}
// clang-format off
#endif // !defined(FLATBUFFERS_CPP98_STL)
// clang-format on

~DetachedBuffer() { destroy(); }

Expand All @@ -92,16 +80,10 @@ class DetachedBuffer {

size_t size() const { return size_; }

// clang-format off
#if !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
// These may change access mode, leave these at end of public section
FLATBUFFERS_DELETE_FUNC(DetachedBuffer(const DetachedBuffer &other));
FLATBUFFERS_DELETE_FUNC(
DetachedBuffer &operator=(const DetachedBuffer &other));
// clang-format off
#endif // !defined(FLATBUFFERS_CPP98_STL)
// clang-format on

protected:
Allocator *allocator_;
Expand Down Expand Up @@ -129,4 +111,4 @@ class DetachedBuffer {

} // namespace flatbuffers

#endif // FLATBUFFERS_DETACHED_BUFFER_H_
#endif // FLATBUFFERS_DETACHED_BUFFER_H_
26 changes: 2 additions & 24 deletions include/flatbuffers/flatbuffer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
#include "flatbuffers/vector_downward.h"
#include "flatbuffers/verifier.h"

#ifndef FLATBUFFERS_CPP98_STL
# include <functional>
#endif
#include <functional>

namespace flatbuffers {

Expand Down Expand Up @@ -96,13 +94,8 @@ class FlatBufferBuilder {
EndianCheck();
}

// clang-format off
/// @brief Move constructor for FlatBufferBuilder.
#if !defined(FLATBUFFERS_CPP98_STL)
FlatBufferBuilder(FlatBufferBuilder &&other)
#else
FlatBufferBuilder(FlatBufferBuilder &other)
#endif // #if !defined(FLATBUFFERS_CPP98_STL)
: buf_(1024, nullptr, false, AlignOf<largest_scalar_t>()),
num_field_loc(0),
max_voffset_(0),
Expand All @@ -117,21 +110,14 @@ class FlatBufferBuilder {
// Lack of delegating constructors in vs2010 makes it more verbose than needed.
Swap(other);
}
// clang-format on

// clang-format off
#if !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
/// @brief Move assignment operator for FlatBufferBuilder.
FlatBufferBuilder &operator=(FlatBufferBuilder &&other) {
// Move construct a temporary and swap idiom
FlatBufferBuilder temp(std::move(other));
Swap(temp);
return *this;
}
// clang-format off
#endif // defined(FLATBUFFERS_CPP98_STL)
// clang-format on

void Swap(FlatBufferBuilder &other) {
using std::swap;
Expand Down Expand Up @@ -683,8 +669,6 @@ class FlatBufferBuilder {
return Offset<Vector<uint8_t>>(EndVector(v.size()));
}

// clang-format off
#ifndef FLATBUFFERS_CPP98_STL
/// @brief Serialize values returned by a function into a FlatBuffer `vector`.
/// This is a convenience function that takes care of iteration for you.
/// @tparam T The data type of the `std::vector` elements.
Expand All @@ -699,8 +683,6 @@ class FlatBufferBuilder {
for (size_t i = 0; i < vector_size; i++) elems[i] = f(i);
return CreateVector(elems);
}
#endif // FLATBUFFERS_CPP98_STL
// clang-format on

/// @brief Serialize values returned by a function into a FlatBuffer `vector`.
/// This is a convenience function that takes care of iteration for you. This
Expand Down Expand Up @@ -811,8 +793,6 @@ class FlatBufferBuilder {
return CreateVectorOfNativeStructs(v, len, Pack);
}

// clang-format off
#ifndef FLATBUFFERS_CPP98_STL
/// @brief Serialize an array of structs into a FlatBuffer `vector`.
/// @tparam T The data type of the struct array elements.
/// @param[in] filler A function that takes the current iteration 0..vector_size-1
Expand All @@ -830,8 +810,6 @@ class FlatBufferBuilder {
}
return EndVectorOfStructs<T>(vector_size);
}
#endif
// clang-format on

/// @brief Serialize an array of structs into a FlatBuffer `vector`.
/// @tparam T The data type of the struct array elements.
Expand Down Expand Up @@ -1198,4 +1176,4 @@ void FlatBufferBuilder::Required(Offset<T> table, voffset_t field) {

} // namespace flatbuffers

#endif // FLATBUFFERS_VECTOR_DOWNWARD_H_
#endif // FLATBUFFERS_VECTOR_DOWNWARD_H_
13 changes: 3 additions & 10 deletions include/flatbuffers/flatbuffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,9 @@ struct NativeTable {};
/// if you wish. The resolver does the opposite lookup, for when the object
/// is being serialized again.
typedef uint64_t hash_value_t;
// clang-format off
#ifdef FLATBUFFERS_CPP98_STL
typedef void (*resolver_function_t)(void **pointer_adr, hash_value_t hash);
typedef hash_value_t (*rehasher_function_t)(void *pointer);
#else
typedef std::function<void (void **pointer_adr, hash_value_t hash)>
resolver_function_t;
typedef std::function<hash_value_t (void *pointer)> rehasher_function_t;
#endif
// clang-format on
typedef std::function<void (void **pointer_adr, hash_value_t hash)>
resolver_function_t;
typedef std::function<hash_value_t (void *pointer)> rehasher_function_t;

// Helper function to test if a field is present, using any of the field
// enums in the generated code.
Expand Down
27 changes: 10 additions & 17 deletions include/flatbuffers/flexbuffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ inline Reference GetRoot(const uint8_t *buffer, size_t size) {
}

inline Reference GetRoot(const std::vector<uint8_t> &buffer) {
return GetRoot(flatbuffers::vector_data(buffer), buffer.size());
return GetRoot(buffer.data(), buffer.size());
}

// Flags that configure how the Builder behaves.
Expand Down Expand Up @@ -1069,7 +1069,7 @@ class Builder FLATBUFFERS_FINAL_CLASS {
return CreateBlob(data, len, 0, FBT_BLOB);
}
size_t Blob(const std::vector<uint8_t> &v) {
return CreateBlob(flatbuffers::vector_data(v), v.size(), 0, FBT_BLOB);
return CreateBlob(v.data(), v.size(), 0, FBT_BLOB);
}

void Blob(const char *key, const void *data, size_t len) {
Expand Down Expand Up @@ -1131,14 +1131,11 @@ class Builder FLATBUFFERS_FINAL_CLASS {
// step automatically when appliccable, and encourage people to write in
// sorted fashion.
// std::sort is typically already a lot faster on sorted data though.
auto dict =
reinterpret_cast<TwoValue *>(flatbuffers::vector_data(stack_) + start);
auto dict = reinterpret_cast<TwoValue *>(stack_.data() + start);
std::sort(dict, dict + len,
[&](const TwoValue &a, const TwoValue &b) -> bool {
auto as = reinterpret_cast<const char *>(
flatbuffers::vector_data(buf_) + a.key.u_);
auto bs = reinterpret_cast<const char *>(
flatbuffers::vector_data(buf_) + b.key.u_);
auto as = reinterpret_cast<const char *>(buf_.data() + a.key.u_);
auto bs = reinterpret_cast<const char *>(buf_.data() + b.key.u_);
auto comp = strcmp(as, bs);
// We want to disallow duplicate keys, since this results in a
// map where values cannot be found.
Expand Down Expand Up @@ -1205,7 +1202,7 @@ class Builder FLATBUFFERS_FINAL_CLASS {
Vector(elems, len);
}
template<typename T> void Vector(const std::vector<T> &vec) {
Vector(flatbuffers::vector_data(vec), vec.size());
Vector(vec.data(), vec.size());
}

template<typename F> size_t TypedVector(F f) {
Expand Down Expand Up @@ -1607,10 +1604,8 @@ class Builder FLATBUFFERS_FINAL_CLASS {
struct KeyOffsetCompare {
explicit KeyOffsetCompare(const std::vector<uint8_t> &buf) : buf_(&buf) {}
bool operator()(size_t a, size_t b) const {
auto stra =
reinterpret_cast<const char *>(flatbuffers::vector_data(*buf_) + a);
auto strb =
reinterpret_cast<const char *>(flatbuffers::vector_data(*buf_) + b);
auto stra = reinterpret_cast<const char *>(buf_->data() + a);
auto strb = reinterpret_cast<const char *>(buf_->data() + b);
return strcmp(stra, strb) < 0;
}
const std::vector<uint8_t> *buf_;
Expand All @@ -1621,10 +1616,8 @@ class Builder FLATBUFFERS_FINAL_CLASS {
explicit StringOffsetCompare(const std::vector<uint8_t> &buf)
: buf_(&buf) {}
bool operator()(const StringOffset &a, const StringOffset &b) const {
auto stra = reinterpret_cast<const char *>(
flatbuffers::vector_data(*buf_) + a.first);
auto strb = reinterpret_cast<const char *>(
flatbuffers::vector_data(*buf_) + b.first);
auto stra = reinterpret_cast<const char *>(buf_->data() + a.first);
auto strb = reinterpret_cast<const char *>(buf_->data() + b.first);
return strncmp(stra, strb, (std::min)(a.second, b.second) + 1) < 0;
}
const std::vector<uint8_t> *buf_;
Expand Down
6 changes: 2 additions & 4 deletions include/flatbuffers/idl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
#include "flatbuffers/hash.h"
#include "flatbuffers/reflection.h"

#if !defined(FLATBUFFERS_CPP98_STL)
# include <functional>
#endif // !defined(FLATBUFFERS_CPP98_STL)
#include <functional>

// This file defines the data types representing a parsed IDL (Interface
// Definition Language) / schema file.
Expand Down Expand Up @@ -207,7 +205,7 @@ template<typename T> class SymbolTable {
}

bool Add(const std::string &name, T *e) {
vector_emplace_back(&vec, e);
vec.emplace_back(e);
auto it = dict.find(name);
if (it != dict.end()) return true;
dict[name] = e;
Expand Down
6 changes: 3 additions & 3 deletions include/flatbuffers/reflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,12 @@ template<typename T, typename U> class pointer_inside_vector {
public:
pointer_inside_vector(T *ptr, std::vector<U> &vec)
: offset_(reinterpret_cast<uint8_t *>(ptr) -
reinterpret_cast<uint8_t *>(flatbuffers::vector_data(vec))),
reinterpret_cast<uint8_t *>(vec.data())),
vec_(vec) {}

T *operator*() const {
return reinterpret_cast<T *>(
reinterpret_cast<uint8_t *>(flatbuffers::vector_data(vec_)) + offset_);
return reinterpret_cast<T *>(reinterpret_cast<uint8_t *>(vec_.data()) +
offset_);
}
T *operator->() const { return operator*(); }

Expand Down
2 changes: 1 addition & 1 deletion include/flatbuffers/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Registry {
}
// Parse schema.
parser->opts = opts_;
if (!parser->Parse(schematext.c_str(), vector_data(include_paths_),
if (!parser->Parse(schematext.c_str(), include_paths_.data(),
schema.path_.c_str())) {
lasterror_ = parser->error_;
return false;
Expand Down
Loading

0 comments on commit 6748c37

Please sign in to comment.