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"
#include <unistd.h>
#endif
-#ifdef _STLPORT_VERSION
- #define FLATBUFFERS_CPP98_STL
-#endif
-
#ifdef __ANDROID__
#include <android/api-level.h>
#endif
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_),
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;
return *this;
}
- // clang-format off
- #endif // !defined(FLATBUFFERS_CPP98_STL)
- // clang-format on
~DetachedBuffer() { destroy(); }
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_;
} // namespace flatbuffers
-#endif // FLATBUFFERS_DETACHED_BUFFER_H_
\ No newline at end of file
+#endif // FLATBUFFERS_DETACHED_BUFFER_H_
#include "flatbuffers/vector_downward.h"
#include "flatbuffers/verifier.h"
-#ifndef FLATBUFFERS_CPP98_STL
-# include <functional>
-#endif
+#include <functional>
namespace flatbuffers {
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),
// 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
Swap(temp);
return *this;
}
- // clang-format off
- #endif // defined(FLATBUFFERS_CPP98_STL)
- // clang-format on
void Swap(FlatBufferBuilder &other) {
using std::swap;
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.
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
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
}
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.
} // namespace flatbuffers
-#endif // FLATBUFFERS_VECTOR_DOWNWARD_H_
\ No newline at end of file
+#endif // FLATBUFFERS_VECTOR_DOWNWARD_H_
/// 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.
}
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.
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) {
// 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.
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) {
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_;
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_;
#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.
}
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;
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*(); }
}
// 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;
#include <memory>
#include <limits>
-#if defined(_STLPORT_VERSION) && !defined(FLATBUFFERS_CPP98_STL)
- #define FLATBUFFERS_CPP98_STL
-#endif // defined(_STLPORT_VERSION) && !defined(FLATBUFFERS_CPP98_STL)
-
-#if defined(FLATBUFFERS_CPP98_STL)
- #include <cctype>
-#endif // defined(FLATBUFFERS_CPP98_STL)
-
// Detect C++17 compatible compiler.
// __cplusplus >= 201703L - a compiler has support of 'static inline' variables.
#if defined(FLATBUFFERS_USE_STD_OPTIONAL) \
#endif
#else
// Disable non-trivial ctors if FLATBUFFERS_SPAN_MINIMAL defined.
- #if !defined(FLATBUFFERS_TEMPLATES_ALIASES) || defined(FLATBUFFERS_CPP98_STL)
+ #if !defined(FLATBUFFERS_TEMPLATES_ALIASES)
#define FLATBUFFERS_SPAN_MINIMAL
#else
// Enable implicit construction of a span<T,N> from a std::array<T,N>.
#endif
#endif // defined(FLATBUFFERS_USE_STD_SPAN)
-// This header provides backwards compatibility for C++98 STLs like stlport.
+// This header provides backwards compatibility for older versions of the STL.
namespace flatbuffers {
-// Retrieve ::back() from a string in a way that is compatible with pre C++11
-// STLs (e.g stlport).
-inline char& string_back(std::string &value) {
- return value[value.length() - 1];
-}
-
-inline char string_back(const std::string &value) {
- return value[value.length() - 1];
-}
-
-// Helper method that retrieves ::data() from a vector in a way that is
-// compatible with pre C++11 STLs (e.g stlport).
-template <typename T> inline T *vector_data(std::vector<T> &vector) {
- // In some debug environments, operator[] does bounds checking, so &vector[0]
- // can't be used.
- return vector.empty() ? nullptr : &vector[0];
-}
-
-template <typename T> inline const T *vector_data(
- const std::vector<T> &vector) {
- return vector.empty() ? nullptr : &vector[0];
-}
-
-template <typename T, typename V>
-inline void vector_emplace_back(std::vector<T> *vector, V &&data) {
- #if defined(FLATBUFFERS_CPP98_STL)
- vector->push_back(data);
- #else
- vector->emplace_back(std::forward<V>(data));
- #endif // defined(FLATBUFFERS_CPP98_STL)
-}
-
-#ifndef FLATBUFFERS_CPP98_STL
- #if defined(FLATBUFFERS_TEMPLATES_ALIASES)
- template <typename T>
- using numeric_limits = std::numeric_limits<T>;
- #else
- template <typename T> class numeric_limits :
- public std::numeric_limits<T> {};
- #endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
+#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
+ template <typename T>
+ using numeric_limits = std::numeric_limits<T>;
#else
template <typename T> class numeric_limits :
- public std::numeric_limits<T> {
- public:
- // Android NDK fix.
- static T lowest() {
- return std::numeric_limits<T>::min();
- }
- };
-
- template <> class numeric_limits<float> :
- public std::numeric_limits<float> {
- public:
- static float lowest() { return -FLT_MAX; }
- };
-
- template <> class numeric_limits<double> :
- public std::numeric_limits<double> {
- public:
- static double lowest() { return -DBL_MAX; }
- };
-
- template <> class numeric_limits<unsigned long long> {
- public:
- static unsigned long long min() { return 0ULL; }
- static unsigned long long max() { return ~0ULL; }
- static unsigned long long lowest() {
- return numeric_limits<unsigned long long>::min();
- }
- };
-
- template <> class numeric_limits<long long> {
- public:
- static long long min() {
- return static_cast<long long>(1ULL << ((sizeof(long long) << 3) - 1));
- }
- static long long max() {
- return static_cast<long long>(
- (1ULL << ((sizeof(long long) << 3) - 1)) - 1);
- }
- static long long lowest() {
- return numeric_limits<long long>::min();
- }
- };
-#endif // FLATBUFFERS_CPP98_STL
+ public std::numeric_limits<T> {};
+#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
- #ifndef FLATBUFFERS_CPP98_STL
- template <typename T> using is_scalar = std::is_scalar<T>;
- template <typename T, typename U> using is_same = std::is_same<T,U>;
- template <typename T> using is_floating_point = std::is_floating_point<T>;
- template <typename T> using is_unsigned = std::is_unsigned<T>;
- template <typename T> using is_enum = std::is_enum<T>;
- template <typename T> using make_unsigned = std::make_unsigned<T>;
- template<bool B, class T, class F>
- using conditional = std::conditional<B, T, F>;
- template<class T, T v>
- using integral_constant = std::integral_constant<T, v>;
- template <bool B>
- using bool_constant = integral_constant<bool, B>;
- using true_type = std::true_type;
- using false_type = std::false_type;
- #else
- // Map C++ TR1 templates defined by stlport.
- template <typename T> using is_scalar = std::tr1::is_scalar<T>;
- template <typename T, typename U> using is_same = std::tr1::is_same<T,U>;
- template <typename T> using is_floating_point =
- std::tr1::is_floating_point<T>;
- template <typename T> using is_unsigned = std::tr1::is_unsigned<T>;
- template <typename T> using is_enum = std::tr1::is_enum<T>;
- // Android NDK doesn't have std::make_unsigned or std::tr1::make_unsigned.
- template<typename T> struct make_unsigned {
- static_assert(is_unsigned<T>::value, "Specialization not implemented!");
- using type = T;
- };
- template<> struct make_unsigned<char> { using type = unsigned char; };
- template<> struct make_unsigned<short> { using type = unsigned short; };
- template<> struct make_unsigned<int> { using type = unsigned int; };
- template<> struct make_unsigned<long> { using type = unsigned long; };
- template<>
- struct make_unsigned<long long> { using type = unsigned long long; };
- template<bool B, class T, class F>
- using conditional = std::tr1::conditional<B, T, F>;
- template<class T, T v>
- using integral_constant = std::tr1::integral_constant<T, v>;
- template <bool B>
- using bool_constant = integral_constant<bool, B>;
- using true_type = bool_constant<true>;
- using false_type = bool_constant<false>;
- #endif // !FLATBUFFERS_CPP98_STL
+ template <typename T> using is_scalar = std::is_scalar<T>;
+ template <typename T, typename U> using is_same = std::is_same<T,U>;
+ template <typename T> using is_floating_point = std::is_floating_point<T>;
+ template <typename T> using is_unsigned = std::is_unsigned<T>;
+ template <typename T> using is_enum = std::is_enum<T>;
+ template <typename T> using make_unsigned = std::make_unsigned<T>;
+ template<bool B, class T, class F>
+ using conditional = std::conditional<B, T, F>;
+ template<class T, T v>
+ using integral_constant = std::integral_constant<T, v>;
+ template <bool B>
+ using bool_constant = integral_constant<bool, B>;
+ using true_type = std::true_type;
+ using false_type = std::false_type;
#else
// MSVC 2010 doesn't support C++11 aliases.
template <typename T> struct is_scalar : public std::is_scalar<T> {};
typedef bool_constant<false> false_type;
#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
-#ifndef FLATBUFFERS_CPP98_STL
- #if defined(FLATBUFFERS_TEMPLATES_ALIASES)
- template <class T> using unique_ptr = std::unique_ptr<T>;
- #else
- // MSVC 2010 doesn't support C++11 aliases.
- // We're manually "aliasing" the class here as we want to bring unique_ptr
- // into the flatbuffers namespace. We have unique_ptr in the flatbuffers
- // namespace we have a completely independent implementation (see below)
- // for C++98 STL implementations.
- template <class T> class unique_ptr : public std::unique_ptr<T> {
- public:
- unique_ptr() {}
- explicit unique_ptr(T* p) : std::unique_ptr<T>(p) {}
- unique_ptr(std::unique_ptr<T>&& u) { *this = std::move(u); }
- unique_ptr(unique_ptr&& u) { *this = std::move(u); }
- unique_ptr& operator=(std::unique_ptr<T>&& u) {
- std::unique_ptr<T>::reset(u.release());
- return *this;
- }
- unique_ptr& operator=(unique_ptr&& u) {
- std::unique_ptr<T>::reset(u.release());
- return *this;
- }
- unique_ptr& operator=(T* p) {
- return std::unique_ptr<T>::operator=(p);
- }
- };
- #endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
+#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
+ template <class T> using unique_ptr = std::unique_ptr<T>;
#else
- // Very limited implementation of unique_ptr.
- // This is provided simply to allow the C++ code generated from the default
- // settings to function in C++98 environments with no modifications.
- template <class T> class unique_ptr {
- public:
- typedef T element_type;
-
- unique_ptr() : ptr_(nullptr) {}
- explicit unique_ptr(T* p) : ptr_(p) {}
- unique_ptr(unique_ptr&& u) : ptr_(nullptr) { reset(u.release()); }
- unique_ptr(const unique_ptr& u) : ptr_(nullptr) {
- reset(const_cast<unique_ptr*>(&u)->release());
- }
- ~unique_ptr() { reset(); }
-
- unique_ptr& operator=(const unique_ptr& u) {
- reset(const_cast<unique_ptr*>(&u)->release());
+ // MSVC 2010 doesn't support C++11 aliases.
+ // We're manually "aliasing" the class here as we want to bring unique_ptr
+ // into the flatbuffers namespace. We have unique_ptr in the flatbuffers
+ // namespace we have a completely independent implementation (see below)
+ // for C++98 STL implementations.
+ template <class T> class unique_ptr : public std::unique_ptr<T> {
+ public:
+ unique_ptr() {}
+ explicit unique_ptr(T* p) : std::unique_ptr<T>(p) {}
+ unique_ptr(std::unique_ptr<T>&& u) { *this = std::move(u); }
+ unique_ptr(unique_ptr&& u) { *this = std::move(u); }
+ unique_ptr& operator=(std::unique_ptr<T>&& u) {
+ std::unique_ptr<T>::reset(u.release());
return *this;
}
-
unique_ptr& operator=(unique_ptr&& u) {
- reset(u.release());
+ std::unique_ptr<T>::reset(u.release());
return *this;
}
-
unique_ptr& operator=(T* p) {
- reset(p);
- return *this;
- }
-
- const T& operator*() const { return *ptr_; }
- T* operator->() const { return ptr_; }
- T* get() const noexcept { return ptr_; }
- explicit operator bool() const { return ptr_ != nullptr; }
-
- // modifiers
- T* release() {
- T* value = ptr_;
- ptr_ = nullptr;
- return value;
- }
-
- void reset(T* p = nullptr) {
- T* value = ptr_;
- ptr_ = p;
- if (value) delete value;
- }
-
- void swap(unique_ptr& u) {
- T* temp_ptr = ptr_;
- ptr_ = u.ptr_;
- u.ptr_ = temp_ptr;
+ return std::unique_ptr<T>::operator=(p);
}
-
- private:
- T* ptr_;
};
-
- template <class T> bool operator==(const unique_ptr<T>& x,
- const unique_ptr<T>& y) {
- return x.get() == y.get();
- }
-
- template <class T, class D> bool operator==(const unique_ptr<T>& x,
- const D* y) {
- return static_cast<D*>(x.get()) == y;
- }
-
- template <class T> bool operator==(const unique_ptr<T>& x, intptr_t y) {
- return reinterpret_cast<intptr_t>(x.get()) == y;
- }
-
- template <class T> bool operator!=(const unique_ptr<T>& x, decltype(nullptr)) {
- return !!x;
- }
-
- template <class T> bool operator!=(decltype(nullptr), const unique_ptr<T>& x) {
- return !!x;
- }
-
- template <class T> bool operator==(const unique_ptr<T>& x, decltype(nullptr)) {
- return !x;
- }
-
- template <class T> bool operator==(decltype(nullptr), const unique_ptr<T>& x) {
- return !x;
- }
-
-#endif // !FLATBUFFERS_CPP98_STL
+#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
#ifdef FLATBUFFERS_USE_STD_OPTIONAL
template<class T>
template<> inline std::string NumToString<char>(char t) {
return NumToString(static_cast<int>(t));
}
-#if defined(FLATBUFFERS_CPP98_STL)
-template<> inline std::string NumToString<long long>(long long t) {
- char buf[21]; // (log((1 << 63) - 1) / log(10)) + 2
- snprintf(buf, sizeof(buf), "%lld", t);
- return std::string(buf);
-}
-
-template<>
-inline std::string NumToString<unsigned long long>(unsigned long long t) {
- char buf[22]; // (log((1 << 63) - 1) / log(10)) + 1
- snprintf(buf, sizeof(buf), "%llu", t);
- return std::string(buf);
-}
-#endif // defined(FLATBUFFERS_CPP98_STL)
// Special versions for floats/doubles.
template<typename T> std::string FloatToString(T t, int precision) {
return *this;
}
- // clang-format off
- #if !defined(FLATBUFFERS_CPP98_STL)
VectorIterator &operator=(VectorIterator &&other) {
data_ = other.data_;
return *this;
}
- #endif // !defined(FLATBUFFERS_CPP98_STL)
- // clang-format on
bool operator==(const VectorIterator &other) const {
return data_ == other.data_;
VectorOfAny &operator=(const VectorOfAny &);
};
-#ifndef FLATBUFFERS_CPP98_STL
template<typename T, typename U>
Vector<Offset<T>> *VectorCast(Vector<Offset<U>> *ptr) {
static_assert(std::is_base_of<T, U>::value, "Unrelated types");
static_assert(std::is_base_of<T, U>::value, "Unrelated types");
return reinterpret_cast<const Vector<Offset<T>> *>(ptr);
}
-#endif
// Convenient helper function to get the length of any vector, regardless
// of whether it is null or not (the field is not set).
cur_(nullptr),
scratch_(nullptr) {}
- // clang-format off
- #if !defined(FLATBUFFERS_CPP98_STL)
vector_downward(vector_downward &&other)
- #else
- vector_downward(vector_downward &other)
- #endif // defined(FLATBUFFERS_CPP98_STL)
// clang-format on
: allocator_(other.allocator_),
own_allocator_(other.own_allocator_),
other.scratch_ = nullptr;
}
- // clang-format off
- #if !defined(FLATBUFFERS_CPP98_STL)
- // clang-format on
vector_downward &operator=(vector_downward &&other) {
// Move construct a temporary and swap idiom
vector_downward temp(std::move(other));
swap(temp);
return *this;
}
- // clang-format off
- #endif // defined(FLATBUFFERS_CPP98_STL)
- // clang-format on
~vector_downward() {
clear_buffer();
} // namespace flatbuffers
-#endif // FLATBUFFERS_VECTOR_DOWNWARD_H_
\ No newline at end of file
+#endif // FLATBUFFERS_VECTOR_DOWNWARD_H_
void Reset();
-#ifndef FLATBUFFERS_CPP98_STL
template <typename T>
void Set(T&& val) {
using RT = typename std::remove_reference<T>::type;
value = new RT(std::forward<T>(val));
}
}
-#endif // FLATBUFFERS_CPP98_STL
static void *UnPack(const void *obj, Equipment type, const flatbuffers::resolver_function_t *resolver);
flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
// Update the text to everything after the }}.
text = text.substr(end + 2);
}
- if (!text.empty() && string_back(text) == '\\') {
+ if (!text.empty() && text.back() == '\\') {
text.pop_back();
ignore_ident_ = true;
stream_ << text;
code_ += " void Reset();";
code_ += "";
if (!enum_def.uses_multiple_type_instances) {
- code_ += "#ifndef FLATBUFFERS_CPP98_STL";
code_ += " template <typename T>";
code_ += " void Set(T&& val) {";
code_ += " using RT = typename std::remove_reference<T>::type;";
code_ += " value = new RT(std::forward<T>(val));";
code_ += " }";
code_ += " }";
- code_ += "#endif // FLATBUFFERS_CPP98_STL";
code_ += "";
}
code_ += " " + UnionUnPackSignature(enum_def, true) + ";";
#include "flatbuffers/idl.h"
#include "flatbuffers/util.h"
-#if defined(FLATBUFFERS_CPP98_STL)
-# include <cctype>
-#endif // defined(FLATBUFFERS_CPP98_STL)
-
namespace flatbuffers {
static TypedFloatConstantGenerator CSharpFloatGen("Double.", "Single.", "NaN",
#include "flatbuffers/idl.h"
#include "flatbuffers/util.h"
-#if defined(FLATBUFFERS_CPP98_STL)
-# include <cctype>
-#endif // defined(FLATBUFFERS_CPP98_STL)
-
namespace flatbuffers {
namespace java {
#include "flatbuffers/flatbuffers.h"
#include "flatbuffers/idl.h"
#include "flatbuffers/util.h"
-#if defined(FLATBUFFERS_CPP98_STL)
-# include <cctype>
-#endif // defined(FLATBUFFERS_CPP98_STL)
namespace flatbuffers {
auto length = array.type.fixed_length;
uoffset_t count = 0;
auto err = ParseVectorDelimiters(count, [&](uoffset_t &) -> CheckedError {
- vector_emplace_back(&stack, Value());
+ stack.emplace_back(Value());
auto &val = stack.back();
val.type = type;
if (IsStruct(type)) {
ECHECK(ParseProtoDecl());
} else if (IsIdent("native_include")) {
NEXT();
- vector_emplace_back(&native_included_files_, attribute_);
+ native_included_files_.emplace_back(attribute_);
EXPECT(kTokenStringConstant);
EXPECT(';');
} else if (IsIdent("include") || (opts.proto_mode && IsIdent("import"))) {
std::vector<uint8_t> *flatbuf,
const reflection::Object *root_table = nullptr)
: schema_(schema),
- startptr_(vector_data(*flatbuf) + start),
+ startptr_(flatbuf->data() + start),
delta_(delta),
buf_(*flatbuf),
dag_check_(flatbuf->size() / sizeof(uoffset_t), false) {
delta_ = (delta_ + mask) & ~mask;
if (!delta_) return; // We can't shrink by less than largest_scalar_t.
// Now change all the offsets by delta_.
- auto root = GetAnyRoot(vector_data(buf_));
- Straddle<uoffset_t, 1>(vector_data(buf_), root, vector_data(buf_));
+ auto root = GetAnyRoot(buf_.data());
+ Straddle<uoffset_t, 1>(buf_.data(), root, buf_.data());
ResizeTable(root_table ? *root_table : *schema.root_table(), root);
// We can now add or remove bytes at start.
if (delta_ > 0)
// will straddle and which won't.
uint8_t &DagCheck(const void *offsetloc) {
auto dag_idx = reinterpret_cast<const uoffset_t *>(offsetloc) -
- reinterpret_cast<const uoffset_t *>(vector_data(buf_));
+ reinterpret_cast<const uoffset_t *>(buf_.data());
return dag_check_[dag_idx];
}
const reflection::Object *root_table) {
auto delta = static_cast<int>(val.size()) - static_cast<int>(str->size());
auto str_start = static_cast<uoffset_t>(
- reinterpret_cast<const uint8_t *>(str) - vector_data(*flatbuf));
+ reinterpret_cast<const uint8_t *>(str) - flatbuf->data());
auto start = str_start + static_cast<uoffset_t>(sizeof(uoffset_t));
if (delta) {
// Clear the old string, since we don't want parts of it remaining.
- memset(vector_data(*flatbuf) + start, 0, str->size());
+ memset(flatbuf->data() + start, 0, str->size());
// Different size, we must expand (or contract).
ResizeContext(schema, start, delta, flatbuf, root_table);
// Set the new length.
- WriteScalar(vector_data(*flatbuf) + str_start,
+ WriteScalar(flatbuf->data() + str_start,
static_cast<uoffset_t>(val.size()));
}
// Copy new data. Safe because we created the right amount of space.
- memcpy(vector_data(*flatbuf) + start, val.c_str(), val.size() + 1);
+ memcpy(flatbuf->data() + start, val.c_str(), val.size() + 1);
}
uint8_t *ResizeAnyVector(const reflection::Schema &schema, uoffset_t newsize,
auto delta_elem = static_cast<int>(newsize) - static_cast<int>(num_elems);
auto delta_bytes = delta_elem * static_cast<int>(elem_size);
auto vec_start =
- reinterpret_cast<const uint8_t *>(vec) - vector_data(*flatbuf);
+ reinterpret_cast<const uint8_t *>(vec) - flatbuf->data();
auto start = static_cast<uoffset_t>(vec_start + sizeof(uoffset_t) +
elem_size * num_elems);
if (delta_bytes) {
// Clear elements we're throwing away, since some might remain in the
// buffer.
auto size_clear = -delta_elem * elem_size;
- memset(vector_data(*flatbuf) + start - size_clear, 0, size_clear);
+ memset(flatbuf->data() + start - size_clear, 0, size_clear);
}
ResizeContext(schema, start, delta_bytes, flatbuf, root_table);
- WriteScalar(vector_data(*flatbuf) + vec_start, newsize); // Length field.
+ WriteScalar(flatbuf->data() + vec_start, newsize); // Length field.
// Set new elements to 0.. this can be overwritten by the caller.
if (delta_elem > 0) {
- memset(vector_data(*flatbuf) + start, 0, delta_elem * elem_size);
+ memset(flatbuf->data() + start, 0, delta_elem * elem_size);
}
}
- return vector_data(*flatbuf) + start;
+ return flatbuf->data() + start;
}
const uint8_t *AddFlatBuffer(std::vector<uint8_t> &flatbuf,
// Insert the entire FlatBuffer minus the root pointer.
flatbuf.insert(flatbuf.end(), newbuf + sizeof(uoffset_t), newbuf + newlen);
auto root_offset = ReadScalar<uoffset_t>(newbuf) - sizeof(uoffset_t);
- return vector_data(flatbuf) + insertion_point + root_offset;
+ return flatbuf.data() + insertion_point + root_offset;
}
void CopyInline(FlatBufferBuilder &fbb, const reflection::Field &fielddef,
const std::string &filename) {
std::string filepath = path;
if (filepath.length()) {
- char &filepath_last_character = string_back(filepath);
+ char &filepath_last_character = filepath.back();
if (filepath_last_character == kPathSeparatorWindows) {
filepath_last_character = kPathSeparator;
} else if (filepath_last_character != kPathSeparator) {
std::string RemoveStringQuotes(const std::string &s) {
auto ch = *s.c_str();
return ((s.size() >= 2) && (ch == '\"' || ch == '\'') &&
- (ch == string_back(s)))
+ (ch == s.back()))
? s.substr(1, s.length() - 2)
: s;
}
void Reset();
-#ifndef FLATBUFFERS_CPP98_STL
template <typename T>
void Set(T&& val) {
using RT = typename std::remove_reference<T>::type;
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;
void Reset();
-#ifndef FLATBUFFERS_CPP98_STL
template <typename T>
void Set(T&& val) {
using RT = typename std::remove_reference<T>::type;
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;
void Reset();
-#ifndef FLATBUFFERS_CPP98_STL
template <typename T>
void Set(T&& val) {
using RT = typename std::remove_reference<T>::type;
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;
void Reset();
-#ifndef FLATBUFFERS_CPP98_STL
template <typename T>
void Set(T&& val) {
using RT = typename std::remove_reference<T>::type;
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;
void Reset();
-#ifndef FLATBUFFERS_CPP98_STL
template <typename T>
void Set(T&& val) {
using RT = typename std::remove_reference<T>::type;
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;
#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"
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)
// 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);
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);
// 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.
- });
+
+ // 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);
});
- 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
+ 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
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();
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;
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)) {}
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
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.
}
// Link-time check using pointer type.
-void CheckTestGeneratedIsValid(const MyGame::Example::Color &) {}
\ No newline at end of file
+void CheckTestGeneratedIsValid(const MyGame::Example::Color &) {}
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>
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();
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) {
}
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();
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();
}
}
}
- // 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; }
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
}
};