diff options
author | thegeorg <thegeorg@yandex-team.ru> | 2022-02-10 16:45:12 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:12 +0300 |
commit | 49116032d905455a7b1c994e4a696afc885c1e71 (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/flatbuffers | |
parent | 4e839db24a3bbc9f1c610c43d6faaaa99824dcca (diff) | |
download | ydb-49116032d905455a7b1c994e4a696afc885c1e71.tar.gz |
Restoring authorship annotation for <thegeorg@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/flatbuffers')
13 files changed, 910 insertions, 910 deletions
diff --git a/contrib/libs/flatbuffers/include/flatbuffers/base.h b/contrib/libs/flatbuffers/include/flatbuffers/base.h index 65052f75d3..e2defddb80 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/base.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/base.h @@ -46,16 +46,16 @@ #include <iterator> #include <memory> -#if defined(__unix__) && !defined(FLATBUFFERS_LOCALE_INDEPENDENT) - #include <unistd.h> -#endif - +#if defined(__unix__) && !defined(FLATBUFFERS_LOCALE_INDEPENDENT) + #include <unistd.h> +#endif + #ifdef _STLPORT_VERSION #define FLATBUFFERS_CPP98_STL #endif - -#ifdef __ANDROID__ - #include <android/api-level.h> + +#ifdef __ANDROID__ + #include <android/api-level.h> #endif #if defined(__ICCARM__) @@ -142,8 +142,8 @@ #endif #endif // !defined(FLATBUFFERS_LITTLEENDIAN) -#define FLATBUFFERS_VERSION_MAJOR 2 -#define FLATBUFFERS_VERSION_MINOR 0 +#define FLATBUFFERS_VERSION_MAJOR 2 +#define FLATBUFFERS_VERSION_MINOR 0 #define FLATBUFFERS_VERSION_REVISION 0 #define FLATBUFFERS_STRING_EXPAND(X) #X #define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X) @@ -157,12 +157,12 @@ namespace flatbuffers { defined(__clang__) #define FLATBUFFERS_FINAL_CLASS final #define FLATBUFFERS_OVERRIDE override - #define FLATBUFFERS_EXPLICIT_CPP11 explicit + #define FLATBUFFERS_EXPLICIT_CPP11 explicit #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t #else #define FLATBUFFERS_FINAL_CLASS #define FLATBUFFERS_OVERRIDE - #define FLATBUFFERS_EXPLICIT_CPP11 + #define FLATBUFFERS_EXPLICIT_CPP11 #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE #endif @@ -170,16 +170,16 @@ namespace flatbuffers { (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \ (defined(__cpp_constexpr) && __cpp_constexpr >= 200704) #define FLATBUFFERS_CONSTEXPR constexpr - #define FLATBUFFERS_CONSTEXPR_CPP11 constexpr - #define FLATBUFFERS_CONSTEXPR_DEFINED + #define FLATBUFFERS_CONSTEXPR_CPP11 constexpr + #define FLATBUFFERS_CONSTEXPR_DEFINED #else #define FLATBUFFERS_CONSTEXPR const - #define FLATBUFFERS_CONSTEXPR_CPP11 + #define FLATBUFFERS_CONSTEXPR_CPP11 #endif #if (defined(__cplusplus) && __cplusplus >= 201402L) || \ (defined(__cpp_constexpr) && __cpp_constexpr >= 201304) - #define FLATBUFFERS_CONSTEXPR_CPP14 FLATBUFFERS_CONSTEXPR_CPP11 + #define FLATBUFFERS_CONSTEXPR_CPP14 FLATBUFFERS_CONSTEXPR_CPP11 #else #define FLATBUFFERS_CONSTEXPR_CPP14 #endif @@ -197,27 +197,27 @@ namespace flatbuffers { #if (!defined(_MSC_VER) || _MSC_FULL_VER >= 180020827) && \ (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)) || \ defined(__clang__) - #define FLATBUFFERS_DELETE_FUNC(func) func = delete + #define FLATBUFFERS_DELETE_FUNC(func) func = delete #else - #define FLATBUFFERS_DELETE_FUNC(func) private: func + #define FLATBUFFERS_DELETE_FUNC(func) private: func +#endif + +#if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \ + (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || \ + defined(__clang__) + #define FLATBUFFERS_DEFAULT_DECLARATION +#endif + +// Check if we can use template aliases +// Not possible if Microsoft Compiler before 2012 +// Possible is the language feature __cpp_alias_templates is defined well +// Or possible if the C++ std is C+11 or newer +#if (defined(_MSC_VER) && _MSC_VER > 1700 /* MSVC2012 */) \ + || (defined(__cpp_alias_templates) && __cpp_alias_templates >= 200704) \ + || (defined(__cplusplus) && __cplusplus >= 201103L) + #define FLATBUFFERS_TEMPLATES_ALIASES #endif -#if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \ - (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || \ - defined(__clang__) - #define FLATBUFFERS_DEFAULT_DECLARATION -#endif - -// Check if we can use template aliases -// Not possible if Microsoft Compiler before 2012 -// Possible is the language feature __cpp_alias_templates is defined well -// Or possible if the C++ std is C+11 or newer -#if (defined(_MSC_VER) && _MSC_VER > 1700 /* MSVC2012 */) \ - || (defined(__cpp_alias_templates) && __cpp_alias_templates >= 200704) \ - || (defined(__cplusplus) && __cplusplus >= 201103L) - #define FLATBUFFERS_TEMPLATES_ALIASES -#endif - #ifndef FLATBUFFERS_HAS_STRING_VIEW // Only provide flatbuffers::string_view if __has_include can be used // to detect a header that provides an implementation @@ -231,7 +231,7 @@ namespace flatbuffers { #define FLATBUFFERS_HAS_STRING_VIEW 1 // Check for std::experimental::string_view (in c++14, compiler-dependent) #elif __has_include(<experimental/string_view>) && (__cplusplus >= 201411) - #error #include <experimental/string_view> + #error #include <experimental/string_view> namespace flatbuffers { typedef std::experimental::string_view string_view; } @@ -261,7 +261,7 @@ namespace flatbuffers { #ifndef FLATBUFFERS_LOCALE_INDEPENDENT // Enable locale independent functions {strtof_l, strtod_l,strtoll_l, strtoull_l}. #if ((defined(_MSC_VER) && _MSC_VER >= 1800) || \ - (defined(_XOPEN_VERSION) && (_XOPEN_VERSION>=700)) && (!defined(__ANDROID_API__) || (defined(__ANDROID_API__) && (__ANDROID_API__>=21)))) + (defined(_XOPEN_VERSION) && (_XOPEN_VERSION>=700)) && (!defined(__ANDROID_API__) || (defined(__ANDROID_API__) && (__ANDROID_API__>=21)))) #define FLATBUFFERS_LOCALE_INDEPENDENT 1 #else #define FLATBUFFERS_LOCALE_INDEPENDENT 0 @@ -332,13 +332,13 @@ typedef uintmax_t largest_scalar_t; // We support aligning the contents of buffers up to this size. #define FLATBUFFERS_MAX_ALIGNMENT 16 -inline bool VerifyAlignmentRequirements(size_t align, size_t min_align = 1) { - return (min_align <= align) && (align <= (FLATBUFFERS_MAX_ALIGNMENT)) && - (align & (align - 1)) == 0; // must be power of 2 -} - +inline bool VerifyAlignmentRequirements(size_t align, size_t min_align = 1) { + return (min_align <= align) && (align <= (FLATBUFFERS_MAX_ALIGNMENT)) && + (align & (align - 1)) == 0; // must be power of 2 +} + #if defined(_MSC_VER) - #pragma warning(disable: 4351) // C4351: new behavior: elements of array ... will be default initialized + #pragma warning(disable: 4351) // C4351: new behavior: elements of array ... will be default initialized #pragma warning(push) #pragma warning(disable: 4127) // C4127: conditional expression is constant #endif @@ -404,13 +404,13 @@ T ReadScalar(const void *p) { return EndianScalar(*reinterpret_cast<const T *>(p)); } -// See https://github.com/google/flatbuffers/issues/5950 - -#if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000) - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wstringop-overflow" -#endif - +// See https://github.com/google/flatbuffers/issues/5950 + +#if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif + template<typename T> // UBSAN: C++ aliasing type rules, see std::bit_cast<> for details. __supress_ubsan__("alignment") @@ -423,10 +423,10 @@ template<typename T> __supress_ubsan__("alignment") void WriteScalar(void *p, Of *reinterpret_cast<uoffset_t *>(p) = EndianScalar(t.o); } -#if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000) - #pragma GCC diagnostic pop -#endif - +#if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000) + #pragma GCC diagnostic pop +#endif + // Computes how many bytes you'd have to pad to be able to write an // "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in // memory). diff --git a/contrib/libs/flatbuffers/include/flatbuffers/code_generators.h b/contrib/libs/flatbuffers/include/flatbuffers/code_generators.h index 118a65747c..09b773a468 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/code_generators.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/code_generators.h @@ -61,7 +61,7 @@ class CodeWriter { } // Appends the given text to the generated code as well as a newline - // character. Any text within {{ and }} delimiters is replaced by values + // character. Any text within {{ and }} delimiters is replaced by values // previously stored in the CodeWriter by calling SetValue above. The newline // will be suppressed if the text ends with the \\ character. void operator+=(std::string text); @@ -76,8 +76,8 @@ class CodeWriter { if (cur_ident_lvl_) cur_ident_lvl_--; } - void SetPadding(const std::string &padding) { pad_ = padding; } - + void SetPadding(const std::string &padding) { pad_ = padding; } + private: std::map<std::string, std::string> value_map_; std::stringstream stream_; @@ -94,11 +94,11 @@ class BaseGenerator { virtual bool generate() = 0; static std::string NamespaceDir(const Parser &parser, const std::string &path, - const Namespace &ns, - const bool dasherize = false); + const Namespace &ns, + const bool dasherize = false); + + static std::string ToDasherizedCase(const std::string pascal_case); - static std::string ToDasherizedCase(const std::string pascal_case); - std::string GeneratedFileName(const std::string &path, const std::string &file_name, const IDLOptions &options) const; @@ -119,8 +119,8 @@ class BaseGenerator { BaseGenerator &operator=(const BaseGenerator &); BaseGenerator(const BaseGenerator &); - std::string NamespaceDir(const Namespace &ns, - const bool dasherize = false) const; + std::string NamespaceDir(const Namespace &ns, + const bool dasherize = false) const; static const char *FlatBuffersGeneratedWarning(); diff --git a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h index 92f1ee5985..20935307a6 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h @@ -18,12 +18,12 @@ #define FLATBUFFERS_H_ #include "base.h" -#include "stl_emulation.h" +#include "stl_emulation.h" + +#ifndef FLATBUFFERS_CPP98_STL +# include <functional> +#endif -#ifndef FLATBUFFERS_CPP98_STL -# include <functional> -#endif - #if defined(FLATBUFFERS_NAN_DEFAULTS) # include <cmath> #endif @@ -172,12 +172,12 @@ template<typename T, typename IT> struct VectorIterator { return (data_ - other.data_) / IndirectHelper<T>::element_stride; } - // Note: return type is incompatible with the standard - // `reference operator*()`. + // Note: return type is incompatible with the standard + // `reference operator*()`. IT operator*() const { return IndirectHelper<T>::Read(data_, 0); } - // Note: return type is incompatible with the standard - // `pointer operator->()`. + // Note: return type is incompatible with the standard + // `pointer operator->()`. IT operator->() const { return IndirectHelper<T>::Read(data_, 0); } VectorIterator &operator++() { @@ -231,18 +231,18 @@ struct VectorReverseIterator : public std::reverse_iterator<Iterator> { explicit VectorReverseIterator(Iterator iter) : std::reverse_iterator<Iterator>(iter) {} - // Note: return type is incompatible with the standard - // `reference operator*()`. + // Note: return type is incompatible with the standard + // `reference operator*()`. typename Iterator::value_type operator*() const { - auto tmp = std::reverse_iterator<Iterator>::current; - return *--tmp; + auto tmp = std::reverse_iterator<Iterator>::current; + return *--tmp; } - // Note: return type is incompatible with the standard - // `pointer operator->()`. + // Note: return type is incompatible with the standard + // `pointer operator->()`. typename Iterator::value_type operator->() const { - auto tmp = std::reverse_iterator<Iterator>::current; - return *--tmp; + auto tmp = std::reverse_iterator<Iterator>::current; + return *--tmp; } }; @@ -267,7 +267,7 @@ template<typename T> class Vector { typedef typename IndirectHelper<T>::return_type return_type; typedef typename IndirectHelper<T>::mutable_return_type mutable_return_type; - typedef return_type value_type; + typedef return_type value_type; return_type Get(uoffset_t i) const { FLATBUFFERS_ASSERT(i < size()); @@ -305,14 +305,14 @@ template<typename T> class Vector { iterator end() { return iterator(Data(), size()); } const_iterator end() const { return const_iterator(Data(), size()); } - reverse_iterator rbegin() { return reverse_iterator(end()); } + reverse_iterator rbegin() { return reverse_iterator(end()); } const_reverse_iterator rbegin() const { - return const_reverse_iterator(end()); + return const_reverse_iterator(end()); } - reverse_iterator rend() { return reverse_iterator(begin()); } + reverse_iterator rend() { return reverse_iterator(begin()); } const_reverse_iterator rend() const { - return const_reverse_iterator(begin()); + return const_reverse_iterator(begin()); } const_iterator cbegin() const { return begin(); } @@ -446,7 +446,7 @@ template<typename T, uint16_t length> class Array { IndirectHelperType; public: - typedef uint16_t size_type; + typedef uint16_t size_type; typedef typename IndirectHelper<IndirectHelperType>::return_type return_type; typedef VectorIterator<T, return_type> const_iterator; typedef VectorReverseIterator<const_iterator> const_reverse_iterator; @@ -473,9 +473,9 @@ template<typename T, uint16_t length> class Array { const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } - const_reverse_iterator rend() const { - return const_reverse_iterator(begin()); - } + const_reverse_iterator rend() const { + return const_reverse_iterator(begin()); + } const_iterator cbegin() const { return begin(); } const_iterator cend() const { return end(); } @@ -506,22 +506,22 @@ template<typename T, uint16_t length> class Array { const T *data() const { return reinterpret_cast<const T *>(Data()); } T *data() { return reinterpret_cast<T *>(Data()); } - // Copy data from a span with endian conversion. - // If this Array and the span overlap, the behavior is undefined. - void CopyFromSpan(flatbuffers::span<const T, length> src) { - const auto p1 = reinterpret_cast<const uint8_t *>(src.data()); - const auto p2 = Data(); - FLATBUFFERS_ASSERT(!(p1 >= p2 && p1 < (p2 + length)) && - !(p2 >= p1 && p2 < (p1 + length))); - (void)p1; - (void)p2; - - CopyFromSpanImpl( - flatbuffers::integral_constant < bool, - !scalar_tag::value || sizeof(T) == 1 || FLATBUFFERS_LITTLEENDIAN > (), - src); - } - + // Copy data from a span with endian conversion. + // If this Array and the span overlap, the behavior is undefined. + void CopyFromSpan(flatbuffers::span<const T, length> src) { + const auto p1 = reinterpret_cast<const uint8_t *>(src.data()); + const auto p2 = Data(); + FLATBUFFERS_ASSERT(!(p1 >= p2 && p1 < (p2 + length)) && + !(p2 >= p1 && p2 < (p1 + length))); + (void)p1; + (void)p2; + + CopyFromSpanImpl( + flatbuffers::integral_constant < bool, + !scalar_tag::value || sizeof(T) == 1 || FLATBUFFERS_LITTLEENDIAN > (), + src); + } + protected: void MutateImpl(flatbuffers::integral_constant<bool, true>, uoffset_t i, const T &val) { @@ -534,20 +534,20 @@ template<typename T, uint16_t length> class Array { *(GetMutablePointer(i)) = val; } - void CopyFromSpanImpl(flatbuffers::integral_constant<bool, true>, - flatbuffers::span<const T, length> src) { - // Use std::memcpy() instead of std::copy() to avoid preformance degradation - // due to aliasing if T is char or unsigned char. - // The size is known at compile time, so memcpy would be inlined. - std::memcpy(data(), src.data(), length * sizeof(T)); - } - - // Copy data from flatbuffers::span with endian conversion. - void CopyFromSpanImpl(flatbuffers::integral_constant<bool, false>, - flatbuffers::span<const T, length> src) { - for (size_type k = 0; k < length; k++) { Mutate(k, src[k]); } - } - + void CopyFromSpanImpl(flatbuffers::integral_constant<bool, true>, + flatbuffers::span<const T, length> src) { + // Use std::memcpy() instead of std::copy() to avoid preformance degradation + // due to aliasing if T is char or unsigned char. + // The size is known at compile time, so memcpy would be inlined. + std::memcpy(data(), src.data(), length * sizeof(T)); + } + + // Copy data from flatbuffers::span with endian conversion. + void CopyFromSpanImpl(flatbuffers::integral_constant<bool, false>, + flatbuffers::span<const T, length> src) { + for (size_type k = 0; k < length; k++) { Mutate(k, src[k]); } + } + // This class is only used to access pre-existing data. Don't ever // try to construct these manually. // 'constexpr' allows us to use 'size()' at compile time. @@ -593,30 +593,30 @@ template<typename T, uint16_t length> class Array<Offset<T>, length> { uint8_t data_[1]; }; -// Cast a raw T[length] to a raw flatbuffers::Array<T, length> -// without endian conversion. Use with care. -template<typename T, uint16_t length> -Array<T, length> &CastToArray(T (&arr)[length]) { - return *reinterpret_cast<Array<T, length> *>(arr); -} - -template<typename T, uint16_t length> -const Array<T, length> &CastToArray(const T (&arr)[length]) { - return *reinterpret_cast<const Array<T, length> *>(arr); -} - -template<typename E, typename T, uint16_t length> -Array<E, length> &CastToArrayOfEnum(T (&arr)[length]) { - static_assert(sizeof(E) == sizeof(T), "invalid enum type E"); - return *reinterpret_cast<Array<E, length> *>(arr); -} - -template<typename E, typename T, uint16_t length> -const Array<E, length> &CastToArrayOfEnum(const T (&arr)[length]) { - static_assert(sizeof(E) == sizeof(T), "invalid enum type E"); - return *reinterpret_cast<const Array<E, length> *>(arr); -} - +// Cast a raw T[length] to a raw flatbuffers::Array<T, length> +// without endian conversion. Use with care. +template<typename T, uint16_t length> +Array<T, length> &CastToArray(T (&arr)[length]) { + return *reinterpret_cast<Array<T, length> *>(arr); +} + +template<typename T, uint16_t length> +const Array<T, length> &CastToArray(const T (&arr)[length]) { + return *reinterpret_cast<const Array<T, length> *>(arr); +} + +template<typename E, typename T, uint16_t length> +Array<E, length> &CastToArrayOfEnum(T (&arr)[length]) { + static_assert(sizeof(E) == sizeof(T), "invalid enum type E"); + return *reinterpret_cast<Array<E, length> *>(arr); +} + +template<typename E, typename T, uint16_t length> +const Array<E, length> &CastToArrayOfEnum(const T (&arr)[length]) { + static_assert(sizeof(E) == sizeof(T), "invalid enum type E"); + return *reinterpret_cast<const Array<E, length> *>(arr); +} + // Lexicographically compare two strings (possibly containing nulls), and // return true if the first is less than the second. static inline bool StringLessThan(const char *a_data, uoffset_t a_size, @@ -654,14 +654,14 @@ static inline const char *GetCstring(const String *str) { return str ? str->c_str() : ""; } -#ifdef FLATBUFFERS_HAS_STRING_VIEW -// Convenience function to get string_view from a String returning an empty -// string_view on null pointer. -static inline flatbuffers::string_view GetStringView(const String *str) { - return str ? str->string_view() : flatbuffers::string_view(); -} -#endif // FLATBUFFERS_HAS_STRING_VIEW - +#ifdef FLATBUFFERS_HAS_STRING_VIEW +// Convenience function to get string_view from a String returning an empty +// string_view on null pointer. +static inline flatbuffers::string_view GetStringView(const String *str) { + return str ? str->string_view() : flatbuffers::string_view(); +} +#endif // FLATBUFFERS_HAS_STRING_VIEW + // Allocator interface. This is flatbuffers-specific and meant only for // `vector_downward` usage. class Allocator { @@ -834,9 +834,9 @@ class DetachedBuffer { #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(const DetachedBuffer &other)); FLATBUFFERS_DELETE_FUNC( - DetachedBuffer &operator=(const DetachedBuffer &other)); + DetachedBuffer &operator=(const DetachedBuffer &other)); // clang-format off #endif // !defined(FLATBUFFERS_CPP98_STL) // clang-format on @@ -1001,7 +1001,7 @@ class vector_downward { Allocator *get_custom_allocator() { return allocator_; } uoffset_t size() const { - return static_cast<uoffset_t>(reserved_ - static_cast<size_t>(cur_ - buf_)); + return static_cast<uoffset_t>(reserved_ - static_cast<size_t>(cur_ - buf_)); } uoffset_t scratch_size() const { @@ -1079,8 +1079,8 @@ class vector_downward { private: // You shouldn't really be copying instances of this class. - FLATBUFFERS_DELETE_FUNC(vector_downward(const vector_downward &)); - FLATBUFFERS_DELETE_FUNC(vector_downward &operator=(const vector_downward &)); + FLATBUFFERS_DELETE_FUNC(vector_downward(const vector_downward &)); + FLATBUFFERS_DELETE_FUNC(vector_downward &operator=(const vector_downward &)); Allocator *allocator_; bool own_allocator_; @@ -1252,14 +1252,14 @@ class FlatBufferBuilder { return buf_.data(); } - /// @brief Get the serialized buffer (after you call `Finish()`) as a span. - /// @return Returns a constructed flatbuffers::span that is a view over the - /// FlatBuffer data inside the buffer. - flatbuffers::span<uint8_t> GetBufferSpan() const { - Finished(); - return flatbuffers::span<uint8_t>(buf_.data(), buf_.size()); - } - + /// @brief Get the serialized buffer (after you call `Finish()`) as a span. + /// @return Returns a constructed flatbuffers::span that is a view over the + /// FlatBuffer data inside the buffer. + flatbuffers::span<uint8_t> GetBufferSpan() const { + Finished(); + return flatbuffers::span<uint8_t>(buf_.data(), buf_.size()); + } + /// @brief Get a pointer to an unfinished buffer. /// @return Returns a `uint8_t` pointer to the unfinished buffer. uint8_t *GetCurrentBufferPointer() const { return buf_.data(); } @@ -1300,7 +1300,7 @@ class FlatBufferBuilder { /// you call Finish()). You can use this information if you need to embed /// a FlatBuffer in some other buffer, such that you can later read it /// without first having to copy it into its own buffer. - size_t GetBufferMinAlignment() const { + size_t GetBufferMinAlignment() const { Finished(); return minalign_; } @@ -1384,11 +1384,11 @@ class FlatBufferBuilder { TrackField(field, off); } - template<typename T> void AddElement(voffset_t field, T e) { - auto off = PushElement(e); - TrackField(field, off); - } - + template<typename T> void AddElement(voffset_t field, T e) { + auto off = PushElement(e); + TrackField(field, off); + } + template<typename T> void AddOffset(voffset_t field, Offset<T> off) { if (off.IsNull()) return; // Don't store. AddElement(field, ReferTo(off.o), static_cast<uoffset_t>(0)); @@ -1624,16 +1624,16 @@ class FlatBufferBuilder { return off; } -#ifdef FLATBUFFERS_HAS_STRING_VIEW - /// @brief Store a string in the buffer, which can contain any binary data. - /// If a string with this exact contents has already been serialized before, - /// instead simply returns the offset of the existing string. - /// @param[in] str A const std::string_view to store in the buffer. - /// @return Returns the offset in the buffer where the string starts - Offset<String> CreateSharedString(const flatbuffers::string_view str) { - return CreateSharedString(str.data(), str.size()); - } -#else +#ifdef FLATBUFFERS_HAS_STRING_VIEW + /// @brief Store a string in the buffer, which can contain any binary data. + /// If a string with this exact contents has already been serialized before, + /// instead simply returns the offset of the existing string. + /// @param[in] str A const std::string_view to store in the buffer. + /// @return Returns the offset in the buffer where the string starts + Offset<String> CreateSharedString(const flatbuffers::string_view str) { + return CreateSharedString(str.data(), str.size()); + } +#else /// @brief Store a string in the buffer, which null-terminated. /// If a string with this exact contents has already been serialized before, /// instead simply returns the offset of the existing string. @@ -1651,7 +1651,7 @@ class FlatBufferBuilder { Offset<String> CreateSharedString(const std::string &str) { return CreateSharedString(str.c_str(), str.length()); } -#endif +#endif /// @brief Store a string in the buffer, which can contain any binary data. /// If a string with this exact contents has already been serialized before, @@ -1682,13 +1682,13 @@ class FlatBufferBuilder { // This is useful when storing a nested_flatbuffer in a vector of bytes, // or when storing SIMD floats, etc. void ForceVectorAlignment(size_t len, size_t elemsize, size_t alignment) { - FLATBUFFERS_ASSERT(VerifyAlignmentRequirements(alignment)); + FLATBUFFERS_ASSERT(VerifyAlignmentRequirements(alignment)); PreAlign(len * elemsize, alignment); } // Similar to ForceVectorAlignment but for String fields. void ForceStringAlignment(size_t len, size_t alignment) { - FLATBUFFERS_ASSERT(VerifyAlignmentRequirements(alignment)); + FLATBUFFERS_ASSERT(VerifyAlignmentRequirements(alignment)); PreAlign((len + 1) * sizeof(char), alignment); } @@ -1706,7 +1706,7 @@ class FlatBufferBuilder { // causing the wrong overload to be selected, remove it. AssertScalarT<T>(); StartVector(len, sizeof(T)); - if (len == 0) { return Offset<Vector<T>>(EndVector(len)); } + if (len == 0) { return Offset<Vector<T>>(EndVector(len)); } // clang-format off #if FLATBUFFERS_LITTLEENDIAN PushBytes(reinterpret_cast<const uint8_t *>(v), len * sizeof(T)); @@ -1818,32 +1818,32 @@ class FlatBufferBuilder { /// @param[in] v A pointer to the array of type `S` to serialize into the /// buffer as a `vector`. /// @param[in] len The number of elements to serialize. - /// @param[in] pack_func Pointer to a function to convert the native struct - /// to the FlatBuffer struct. + /// @param[in] pack_func Pointer to a function to convert the native struct + /// to the FlatBuffer struct. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template<typename T, typename S> + Offset<Vector<const T *>> CreateVectorOfNativeStructs( + const S *v, size_t len, T((*const pack_func)(const S &))) { + FLATBUFFERS_ASSERT(pack_func); + std::vector<T> vv(len); + std::transform(v, v + len, vv.begin(), pack_func); + return CreateVectorOfStructs<T>(data(vv), vv.size()); + } + + /// @brief Serialize an array of native structs into a FlatBuffer `vector`. + /// @tparam T The data type of the struct array elements. + /// @tparam S The data type of the native struct array elements. + /// @param[in] v A pointer to the array of type `S` to serialize into the + /// buffer as a `vector`. + /// @param[in] len The number of elements to serialize. /// @return Returns a typed `Offset` into the serialized data indicating /// where the vector is stored. template<typename T, typename S> - Offset<Vector<const T *>> CreateVectorOfNativeStructs( - const S *v, size_t len, T((*const pack_func)(const S &))) { - FLATBUFFERS_ASSERT(pack_func); - std::vector<T> vv(len); - std::transform(v, v + len, vv.begin(), pack_func); - return CreateVectorOfStructs<T>(data(vv), vv.size()); - } - - /// @brief Serialize an array of native structs into a FlatBuffer `vector`. - /// @tparam T The data type of the struct array elements. - /// @tparam S The data type of the native struct array elements. - /// @param[in] v A pointer to the array of type `S` to serialize into the - /// buffer as a `vector`. - /// @param[in] len The number of elements to serialize. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template<typename T, typename S> Offset<Vector<const T *>> CreateVectorOfNativeStructs(const S *v, size_t len) { extern T Pack(const S &); - return CreateVectorOfNativeStructs(v, len, Pack); + return CreateVectorOfNativeStructs(v, len, Pack); } // clang-format off @@ -1906,26 +1906,26 @@ class FlatBufferBuilder { /// @tparam S The data type of the `std::vector` native struct elements. /// @param[in] v A const reference to the `std::vector` of structs to /// serialize into the buffer as a `vector`. - /// @param[in] pack_func Pointer to a function to convert the native struct - /// to the FlatBuffer struct. + /// @param[in] pack_func Pointer to a function to convert the native struct + /// to the FlatBuffer struct. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template<typename T, typename S> + Offset<Vector<const T *>> CreateVectorOfNativeStructs( + const std::vector<S> &v, T((*const pack_func)(const S &))) { + return CreateVectorOfNativeStructs<T, S>(data(v), v.size(), pack_func); + } + + /// @brief Serialize a `std::vector` of native structs into a FlatBuffer + /// `vector`. + /// @tparam T The data type of the `std::vector` struct elements. + /// @tparam S The data type of the `std::vector` native struct elements. + /// @param[in] v A const reference to the `std::vector` of structs to + /// serialize into the buffer as a `vector`. /// @return Returns a typed `Offset` into the serialized data indicating /// where the vector is stored. template<typename T, typename S> Offset<Vector<const T *>> CreateVectorOfNativeStructs( - const std::vector<S> &v, T((*const pack_func)(const S &))) { - return CreateVectorOfNativeStructs<T, S>(data(v), v.size(), pack_func); - } - - /// @brief Serialize a `std::vector` of native structs into a FlatBuffer - /// `vector`. - /// @tparam T The data type of the `std::vector` struct elements. - /// @tparam S The data type of the `std::vector` native struct elements. - /// @param[in] v A const reference to the `std::vector` of structs to - /// serialize into the buffer as a `vector`. - /// @return Returns a typed `Offset` into the serialized data indicating - /// where the vector is stored. - template<typename T, typename S> - Offset<Vector<const T *>> CreateVectorOfNativeStructs( const std::vector<S> &v) { return CreateVectorOfNativeStructs<T, S>(data(v), v.size()); } @@ -1936,8 +1936,8 @@ class FlatBufferBuilder { return a.KeyCompareLessThan(&b); } - FLATBUFFERS_DELETE_FUNC( - StructKeyComparator &operator=(const StructKeyComparator &)); + FLATBUFFERS_DELETE_FUNC( + StructKeyComparator &operator=(const StructKeyComparator &)); }; /// @endcond @@ -2012,8 +2012,8 @@ class FlatBufferBuilder { vector_downward &buf_; private: - FLATBUFFERS_DELETE_FUNC( - TableKeyComparator &operator=(const TableKeyComparator &other)); + FLATBUFFERS_DELETE_FUNC( + TableKeyComparator &operator=(const TableKeyComparator &other)); }; /// @endcond @@ -2408,8 +2408,8 @@ class Verifier FLATBUFFERS_FINAL_CLASS { template<typename T> bool VerifyBufferFromStart(const char *identifier, size_t start) { - if (identifier && !Check((size_ >= 2 * sizeof(flatbuffers::uoffset_t) && - BufferHasIdentifier(buf_ + start, identifier)))) { + if (identifier && !Check((size_ >= 2 * sizeof(flatbuffers::uoffset_t) && + BufferHasIdentifier(buf_ + start, identifier)))) { return false; } @@ -2591,26 +2591,26 @@ class Table { return field_offset ? reinterpret_cast<P>(p) : nullptr; } - template<typename Raw, typename Face> - flatbuffers::Optional<Face> GetOptional(voffset_t field) const { - auto field_offset = GetOptionalFieldOffset(field); - auto p = data_ + field_offset; - return field_offset ? Optional<Face>(static_cast<Face>(ReadScalar<Raw>(p))) - : Optional<Face>(); - } - + template<typename Raw, typename Face> + flatbuffers::Optional<Face> GetOptional(voffset_t field) const { + auto field_offset = GetOptionalFieldOffset(field); + auto p = data_ + field_offset; + return field_offset ? Optional<Face>(static_cast<Face>(ReadScalar<Raw>(p))) + : Optional<Face>(); + } + template<typename T> bool SetField(voffset_t field, T val, T def) { auto field_offset = GetOptionalFieldOffset(field); if (!field_offset) return IsTheSameAs(val, def); WriteScalar(data_ + field_offset, val); return true; } - template<typename T> bool SetField(voffset_t field, T val) { - auto field_offset = GetOptionalFieldOffset(field); - if (!field_offset) return false; - WriteScalar(data_ + field_offset, val); - return true; - } + template<typename T> bool SetField(voffset_t field, T val) { + auto field_offset = GetOptionalFieldOffset(field); + if (!field_offset) return false; + WriteScalar(data_ + field_offset, val); + return true; + } bool SetPointer(voffset_t field, const uint8_t *val) { auto field_offset = GetOptionalFieldOffset(field); @@ -2678,17 +2678,17 @@ class Table { uint8_t data_[1]; }; -// This specialization allows avoiding warnings like: -// MSVC C4800: type: forcing value to bool 'true' or 'false'. -template<> -inline flatbuffers::Optional<bool> Table::GetOptional<uint8_t, bool>( - voffset_t field) const { - auto field_offset = GetOptionalFieldOffset(field); - auto p = data_ + field_offset; - return field_offset ? Optional<bool>(ReadScalar<uint8_t>(p) != 0) - : Optional<bool>(); -} - +// This specialization allows avoiding warnings like: +// MSVC C4800: type: forcing value to bool 'true' or 'false'. +template<> +inline flatbuffers::Optional<bool> Table::GetOptional<uint8_t, bool>( + voffset_t field) const { + auto field_offset = GetOptionalFieldOffset(field); + auto p = data_ + field_offset; + return field_offset ? Optional<bool>(ReadScalar<uint8_t>(p) != 0) + : Optional<bool>(); +} + template<typename T> void FlatBufferBuilder::Required(Offset<T> table, voffset_t field) { auto table_ptr = reinterpret_cast<const Table *>(buf_.data_at(table.o)); @@ -2866,16 +2866,16 @@ inline const char * const *ElementaryTypeNames() { // clang-format on // Basic type info cost just 16bits per field! -// We're explicitly defining the signedness since the signedness of integer -// bitfields is otherwise implementation-defined and causes warnings on older -// GCC compilers. +// We're explicitly defining the signedness since the signedness of integer +// bitfields is otherwise implementation-defined and causes warnings on older +// GCC compilers. struct TypeCode { - // ElementaryType - unsigned short base_type : 4; - // Either vector (in table) or array (in struct) - unsigned short is_repeating : 1; - // Index into type_refs below, or -1 for none. - signed short sequence_ref : 11; + // ElementaryType + unsigned short base_type : 4; + // Either vector (in table) or array (in struct) + unsigned short is_repeating : 1; + // Index into type_refs below, or -1 for none. + signed short sequence_ref : 11; }; static_assert(sizeof(TypeCode) == 2, "TypeCode"); @@ -2890,7 +2890,7 @@ struct TypeTable { size_t num_elems; // of type_codes, values, names (but not type_refs). const TypeCode *type_codes; // num_elems count const TypeFunction *type_refs; // less than num_elems entries (see TypeCode). - const int16_t *array_sizes; // less than num_elems entries (see TypeCode). + const int16_t *array_sizes; // less than num_elems entries (see TypeCode). const int64_t *values; // Only set for non-consecutive enum/union or structs. const char *const *names; // Only set if compiled with --reflect-names. }; diff --git a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers_iter.h b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers_iter.h index ce0f041a21..a770983dca 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers_iter.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers_iter.h @@ -46,7 +46,7 @@ inline bool hasContiguous(const Iter& spot, uoffset_t length) return spot.hasContiguous(length); } -inline bool hasContiguous(const uint8_t* /* spot */, uoffset_t /* length */) +inline bool hasContiguous(const uint8_t* /* spot */, uoffset_t /* length */) { return true; } diff --git a/contrib/libs/flatbuffers/include/flatbuffers/flexbuffers.h b/contrib/libs/flatbuffers/include/flatbuffers/flexbuffers.h index d4dbbc1c24..d855b67731 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/flexbuffers.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/flexbuffers.h @@ -155,7 +155,7 @@ inline uint64_t ReadUInt64(const uint8_t *data, uint8_t byte_width) { // constant, which here it isn't. Test if memcpy is still faster than // the conditionals in ReadSizedScalar. Can also use inline asm. // clang-format off - #if defined(_MSC_VER) && ((defined(_M_X64) && !defined(_M_ARM64EC)) || defined _M_IX86) + #if defined(_MSC_VER) && ((defined(_M_X64) && !defined(_M_ARM64EC)) || defined _M_IX86) uint64_t u = 0; __movsb(reinterpret_cast<uint8_t *>(&u), reinterpret_cast<const uint8_t *>(data), byte_width); @@ -900,7 +900,7 @@ class Builder FLATBUFFERS_FINAL_CLASS { BuilderFlag flags = BUILDER_FLAG_SHARE_KEYS) : buf_(initial_size), finished_(false), - has_duplicate_keys_(false), + has_duplicate_keys_(false), flags_(flags), force_min_bit_width_(BIT_WIDTH_8), key_pool(KeyOffsetCompare(buf_)), @@ -908,11 +908,11 @@ class Builder FLATBUFFERS_FINAL_CLASS { buf_.clear(); } -#ifdef FLATBUFFERS_DEFAULT_DECLARATION - Builder(Builder &&) = default; - Builder &operator=(Builder &&) = default; -#endif - +#ifdef FLATBUFFERS_DEFAULT_DECLARATION + Builder(Builder &&) = default; + Builder &operator=(Builder &&) = default; +#endif + /// @brief Get the serialized buffer (after you call `Finish()`). /// @return Returns a vector owned by this class. const std::vector<uint8_t> &GetBuffer() const { @@ -1130,16 +1130,16 @@ class Builder FLATBUFFERS_FINAL_CLASS { auto bs = reinterpret_cast<const char *>( flatbuffers::vector_data(buf_) + 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. - // But we can't assert here (since we don't want to fail on - // random JSON input) or have an error mechanism. - // Instead, we set has_duplicate_keys_ in the builder to - // signal this. + // We want to disallow duplicate keys, since this results in a + // map where values cannot be found. + // But we can't assert here (since we don't want to fail on + // random JSON input) or have an error mechanism. + // Instead, we set has_duplicate_keys_ in the builder to + // signal this. // TODO: Have to check for pointer equality, as some sort // implementation apparently call this function with the same // element?? Why? - if (!comp && &a != &b) has_duplicate_keys_ = true; + if (!comp && &a != &b) has_duplicate_keys_ = true; return comp < 0; }); // First create a vector out of all keys. @@ -1153,10 +1153,10 @@ class Builder FLATBUFFERS_FINAL_CLASS { return static_cast<size_t>(vec.u_); } - // Call this after EndMap to see if the map had any duplicate keys. - // Any map with such keys won't be able to retrieve all values. - bool HasDuplicateKeys() const { return has_duplicate_keys_; } - + // Call this after EndMap to see if the map had any duplicate keys. + // Any map with such keys won't be able to retrieve all values. + bool HasDuplicateKeys() const { return has_duplicate_keys_; } + template<typename F> size_t Vector(F f) { auto start = StartVector(); f(); @@ -1270,7 +1270,7 @@ class Builder FLATBUFFERS_FINAL_CLASS { // auto id = builder.LastValue(); // Remember where we stored it. // .. more code goes here .. // builder.ReuseValue(id); // Refers to same double by offset. - // LastValue works regardless of whether the value has a key or not. + // LastValue works regardless of whether the value has a key or not. // Works on any data type. struct Value; Value LastValue() { return stack_.back(); } @@ -1431,10 +1431,10 @@ class Builder FLATBUFFERS_FINAL_CLASS { Value(uint64_t u, Type t, BitWidth bw) : u_(u), type_(t), min_bit_width_(bw) {} - Value(float f) - : f_(static_cast<double>(f)), - type_(FBT_FLOAT), - min_bit_width_(BIT_WIDTH_32) {} + Value(float f) + : f_(static_cast<double>(f)), + type_(FBT_FLOAT), + min_bit_width_(BIT_WIDTH_32) {} Value(double f) : f_(f), type_(FBT_FLOAT), min_bit_width_(WidthF(f)) {} uint8_t StoredPackedType(BitWidth parent_bit_width_ = BIT_WIDTH_8) const { @@ -1539,8 +1539,8 @@ class Builder FLATBUFFERS_FINAL_CLASS { Type vector_type = FBT_KEY; // Check bit widths and types for all elements. for (size_t i = start; i < stack_.size(); i += step) { - auto elem_width = - stack_[i].ElemWidth(buf_.size(), i - start + prefix_elems); + auto elem_width = + stack_[i].ElemWidth(buf_.size(), i - start + prefix_elems); bit_width = (std::max)(bit_width, elem_width); if (typed) { if (i == start) { @@ -1588,7 +1588,7 @@ class Builder FLATBUFFERS_FINAL_CLASS { std::vector<Value> stack_; bool finished_; - bool has_duplicate_keys_; + bool has_duplicate_keys_; BuilderFlag flags_; diff --git a/contrib/libs/flatbuffers/include/flatbuffers/grpc.h b/contrib/libs/flatbuffers/include/flatbuffers/grpc.h index 95dc90e5c7..da7830e7dc 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/grpc.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/grpc.h @@ -21,7 +21,7 @@ #include "flatbuffers.h" #include "grpc/byte_buffer_reader.h" -#include "grpcpp/support/byte_buffer.h" +#include "grpcpp/support/byte_buffer.h" namespace flatbuffers { namespace grpc { @@ -287,9 +287,9 @@ template<class T> class SerializationTraits<flatbuffers::grpc::Message<T>> { } // Deserialize by pulling the - static grpc::Status Deserialize(ByteBuffer *buf, + static grpc::Status Deserialize(ByteBuffer *buf, flatbuffers::grpc::Message<T> *msg) { - grpc_byte_buffer *buffer = *reinterpret_cast<grpc_byte_buffer **>(buf); + grpc_byte_buffer *buffer = *reinterpret_cast<grpc_byte_buffer **>(buf); if (!buffer) { return ::grpc::Status(::grpc::StatusCode::INTERNAL, "No payload"); } diff --git a/contrib/libs/flatbuffers/include/flatbuffers/idl.h b/contrib/libs/flatbuffers/include/flatbuffers/idl.h index 8a5c26bc55..a82ff8a694 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/idl.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/idl.h @@ -35,7 +35,7 @@ // Definition Language) / schema file. // Limits maximum depth of nested objects. -// Prevents stack overflow while parse scheme, or json, or flexbuffer. +// Prevents stack overflow while parse scheme, or json, or flexbuffer. #if !defined(FLATBUFFERS_MAX_PARSING_DEPTH) # define FLATBUFFERS_MAX_PARSING_DEPTH 64 #endif @@ -239,7 +239,7 @@ template<typename T> class SymbolTable { struct Namespace { Namespace() : from_table(0) {} - // Given a (potentially unqualified) name, return the "fully qualified" name + // Given a (potentially unqualified) name, return the "fully qualified" name // which has a full namespaced descriptor. // With max_components you can request less than the number of components // the current namespace has. @@ -295,7 +295,7 @@ struct FieldDef : public Definition { shared(false), native_inline(false), flexbuffer(false), - presence(kDefault), + presence(kDefault), nested_flatbuffer(NULL), padding(0) {} @@ -304,19 +304,19 @@ struct FieldDef : public Definition { bool Deserialize(Parser &parser, const reflection::Field *field); - bool IsScalarOptional() const { - return IsScalar(value.type.base_type) && IsOptional(); - } - bool IsOptional() const { - return presence == kOptional; - } - bool IsRequired() const { - return presence == kRequired; - } - bool IsDefault() const { - return presence == kDefault; - } - + bool IsScalarOptional() const { + return IsScalar(value.type.base_type) && IsOptional(); + } + bool IsOptional() const { + return presence == kOptional; + } + bool IsRequired() const { + return presence == kRequired; + } + bool IsDefault() const { + return presence == kDefault; + } + Value value; bool deprecated; // Field is allowed to be present in old data, but can't be. // written in new data nor accessed in new code. @@ -326,26 +326,26 @@ struct FieldDef : public Definition { bool native_inline; // Field will be defined inline (instead of as a pointer) // for native tables if field is a struct. bool flexbuffer; // This field contains FlexBuffer data. - - enum Presence { - // Field must always be present. - kRequired, - // Non-presence should be signalled to and controlled by users. - kOptional, - // Non-presence is hidden from users. - // Implementations may omit writing default values. - kDefault, - }; - Presence static MakeFieldPresence(bool optional, bool required) { - FLATBUFFERS_ASSERT(!(required && optional)); - // clang-format off - return required ? FieldDef::kRequired - : optional ? FieldDef::kOptional - : FieldDef::kDefault; - // clang-format on - } - Presence presence; - + + enum Presence { + // Field must always be present. + kRequired, + // Non-presence should be signalled to and controlled by users. + kOptional, + // Non-presence is hidden from users. + // Implementations may omit writing default values. + kDefault, + }; + Presence static MakeFieldPresence(bool optional, bool required) { + FLATBUFFERS_ASSERT(!(required && optional)); + // clang-format off + return required ? FieldDef::kRequired + : optional ? FieldDef::kOptional + : FieldDef::kDefault; + // clang-format on + } + Presence presence; + StructDef *nested_flatbuffer; // This field contains nested FlatBuffer data. size_t padding; // Bytes to always pad after this field. }; @@ -442,7 +442,7 @@ struct EnumDef : public Definition { size_t size() const { return vals.vec.size(); } - const std::vector<EnumVal *> &Vals() const { return vals.vec; } + const std::vector<EnumVal *> &Vals() const { return vals.vec; } const EnumVal *Lookup(const std::string &enum_name) const { return vals.Lookup(enum_name); @@ -463,10 +463,10 @@ struct EnumDef : public Definition { SymbolTable<EnumVal> vals; }; -inline bool IsString(const Type &type) { - return type.base_type == BASE_TYPE_STRING; -} - +inline bool IsString(const Type &type) { + return type.base_type == BASE_TYPE_STRING; +} + inline bool IsStruct(const Type &type) { return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed; } @@ -542,7 +542,7 @@ struct ServiceDef : public Definition { // Container of options that may apply to any of the source/text generators. struct IDLOptions { - bool gen_jvmstatic; + bool gen_jvmstatic; // Use flexbuffers instead for binary and text generation bool use_flexbuffers; bool strict_json; @@ -564,7 +564,7 @@ struct IDLOptions { std::string cpp_object_api_pointer_type; std::string cpp_object_api_string_type; bool cpp_object_api_string_flexible_constructor; - bool cpp_direct_copy; + bool cpp_direct_copy; bool gen_nullable; bool java_checkerframework; bool gen_generated; @@ -588,11 +588,11 @@ struct IDLOptions { bool cs_gen_json_serializer; std::vector<std::string> cpp_includes; std::string cpp_std; - bool cpp_static_reflection; + bool cpp_static_reflection; std::string proto_namespace_suffix; std::string filename_suffix; std::string filename_extension; - bool no_warnings; + bool no_warnings; // Possible options for the more general generator below. enum Language { @@ -622,9 +622,9 @@ struct IDLOptions { MiniReflect mini_reflect; - // If set, require all fields in a table to be explicitly numbered. - bool require_explicit_ids; - + // If set, require all fields in a table to be explicitly numbered. + bool require_explicit_ids; + // The corresponding language bit will be set if a language is included // for code generation. unsigned long lang_to_generate; @@ -638,8 +638,8 @@ struct IDLOptions { bool set_empty_vectors_to_null; IDLOptions() - : gen_jvmstatic(false), - use_flexbuffers(false), + : gen_jvmstatic(false), + use_flexbuffers(false), strict_json(false), output_default_scalars_in_json(false), indent_step(2), @@ -658,7 +658,7 @@ struct IDLOptions { gen_compare(false), cpp_object_api_pointer_type("std::unique_ptr"), cpp_object_api_string_flexible_constructor(false), - cpp_direct_copy(true), + cpp_direct_copy(true), gen_nullable(false), java_checkerframework(false), gen_generated(false), @@ -675,13 +675,13 @@ struct IDLOptions { force_defaults(false), java_primitive_has_method(false), cs_gen_json_serializer(false), - cpp_static_reflection(false), - filename_suffix("_generated"), + cpp_static_reflection(false), + filename_suffix("_generated"), filename_extension(), - no_warnings(false), + no_warnings(false), lang(IDLOptions::kJava), mini_reflect(IDLOptions::kNone), - require_explicit_ids(false), + require_explicit_ids(false), lang_to_generate(0), set_empty_strings_to_null(true), set_empty_vectors_to_null(true) {} @@ -781,10 +781,10 @@ class Parser : public ParserState { root_struct_def_(nullptr), opts(options), uses_flexbuffers_(false), - advanced_features_(0), + advanced_features_(0), source_(nullptr), - anonymous_counter_(0), - parse_depth_counter_(0) { + anonymous_counter_(0), + parse_depth_counter_(0) { if (opts.force_defaults) { builder_.ForceDefaults(true); } // Start out with the empty namespace being current. empty_namespace_ = new Namespace(); @@ -811,7 +811,7 @@ class Parser : public ParserState { known_attributes_["native_inline"] = true; known_attributes_["native_custom_alloc"] = true; known_attributes_["native_type"] = true; - known_attributes_["native_type_pack_name"] = true; + known_attributes_["native_type_pack_name"] = true; known_attributes_["native_default"] = true; known_attributes_["flexbuffer"] = true; known_attributes_["private"] = true; @@ -837,8 +837,8 @@ class Parser : public ParserState { bool Parse(const char *_source, const char **include_paths = nullptr, const char *source_filename = nullptr); - bool ParseJson(const char *json, const char *json_filename = nullptr); - + bool ParseJson(const char *json, const char *json_filename = nullptr); + // Set the root type. May override the one set in the schema. bool SetRootType(const char *name); @@ -873,20 +873,20 @@ class Parser : public ParserState { flexbuffers::Builder *builder); StructDef *LookupStruct(const std::string &id) const; - StructDef *LookupStructThruParentNamespaces(const std::string &id) const; + StructDef *LookupStructThruParentNamespaces(const std::string &id) const; std::string UnqualifiedName(const std::string &fullQualifiedName); FLATBUFFERS_CHECKED_ERROR Error(const std::string &msg); - // @brief Verify that any of 'opts.lang_to_generate' supports Optional scalars - // in a schema. - // @param opts Options used to parce a schema and generate code. - static bool SupportsOptionalScalars(const flatbuffers::IDLOptions &opts); - + // @brief Verify that any of 'opts.lang_to_generate' supports Optional scalars + // in a schema. + // @param opts Options used to parce a schema and generate code. + static bool SupportsOptionalScalars(const flatbuffers::IDLOptions &opts); + private: - class ParseDepthGuard; - + class ParseDepthGuard; + void Message(const std::string &msg); void Warning(const std::string &msg); FLATBUFFERS_CHECKED_ERROR ParseHexNum(int nibbles, uint64_t *val); @@ -905,7 +905,7 @@ class Parser : public ParserState { const std::string &name, const Type &type, FieldDef **dest); FLATBUFFERS_CHECKED_ERROR ParseField(StructDef &struct_def); - FLATBUFFERS_CHECKED_ERROR ParseString(Value &val, bool use_string_pooling); + FLATBUFFERS_CHECKED_ERROR ParseString(Value &val, bool use_string_pooling); FLATBUFFERS_CHECKED_ERROR ParseComma(); FLATBUFFERS_CHECKED_ERROR ParseAnyValue(Value &val, FieldDef *field, size_t parent_fieldn, @@ -937,7 +937,7 @@ class Parser : public ParserState { FLATBUFFERS_CHECKED_ERROR TokenError(); FLATBUFFERS_CHECKED_ERROR ParseSingleValue(const std::string *name, Value &e, bool check_now); - FLATBUFFERS_CHECKED_ERROR ParseFunction(const std::string *name, Value &e); + FLATBUFFERS_CHECKED_ERROR ParseFunction(const std::string *name, Value &e); FLATBUFFERS_CHECKED_ERROR ParseEnumFromString(const Type &type, std::string *result); StructDef *LookupCreateStruct(const std::string &name, @@ -959,8 +959,8 @@ class Parser : public ParserState { FLATBUFFERS_CHECKED_ERROR ParseProtoCurliesOrIdent(); FLATBUFFERS_CHECKED_ERROR ParseTypeFromProtoType(Type *type); FLATBUFFERS_CHECKED_ERROR SkipAnyJsonValue(); - FLATBUFFERS_CHECKED_ERROR ParseFlexBufferNumericConstant( - flexbuffers::Builder *builder); + FLATBUFFERS_CHECKED_ERROR ParseFlexBufferNumericConstant( + flexbuffers::Builder *builder); FLATBUFFERS_CHECKED_ERROR ParseFlexBufferValue(flexbuffers::Builder *builder); FLATBUFFERS_CHECKED_ERROR StartParseFile(const char *source, const char *source_filename); @@ -971,17 +971,17 @@ class Parser : public ParserState { const char **include_paths, const char *source_filename, const char *include_filename); - FLATBUFFERS_CHECKED_ERROR DoParseJson(); + FLATBUFFERS_CHECKED_ERROR DoParseJson(); FLATBUFFERS_CHECKED_ERROR CheckClash(std::vector<FieldDef *> &fields, StructDef *struct_def, const char *suffix, BaseType baseType); - FLATBUFFERS_CHECKED_ERROR ParseAlignAttribute( - const std::string &align_constant, size_t min_align, size_t *align); + FLATBUFFERS_CHECKED_ERROR ParseAlignAttribute( + const std::string &align_constant, size_t min_align, size_t *align); bool SupportsAdvancedUnionFeatures() const; bool SupportsAdvancedArrayFeatures() const; - bool SupportsOptionalScalars() const; - bool SupportsDefaultVectorsAndStrings() const; + bool SupportsOptionalScalars() const; + bool SupportsDefaultVectorsAndStrings() const; Namespace *UniqueNamespace(Namespace *ns); FLATBUFFERS_CHECKED_ERROR RecurseError(); @@ -1004,7 +1004,7 @@ class Parser : public ParserState { std::string file_identifier_; std::string file_extension_; - std::map<uint64_t, std::string> included_files_; + std::map<uint64_t, std::string> included_files_; std::map<std::string, std::set<std::string>> files_included_per_file_; std::vector<std::string> native_included_files_; @@ -1013,8 +1013,8 @@ class Parser : public ParserState { IDLOptions opts; bool uses_flexbuffers_; - uint64_t advanced_features_; - + uint64_t advanced_features_; + private: const char *source_; @@ -1022,8 +1022,8 @@ class Parser : public ParserState { std::vector<std::pair<Value, FieldDef *>> field_stack_; - int anonymous_counter_; - int parse_depth_counter_; // stack-overflow guard + int anonymous_counter_; + int parse_depth_counter_; // stack-overflow guard }; // Utility functions for multiple generators: @@ -1048,10 +1048,10 @@ extern bool GenerateText(const Parser &parser, const void *flatbuffer, extern bool GenerateTextFile(const Parser &parser, const std::string &path, const std::string &file_name); -// Generate Json schema to string -// See idl_gen_json_schema.cpp. -extern bool GenerateJsonSchema(const Parser &parser, std::string *json); - +// Generate Json schema to string +// See idl_gen_json_schema.cpp. +extern bool GenerateJsonSchema(const Parser &parser, std::string *json); + // Generate binary files from a given FlatBuffer, and a given Parser // object that has been populated with the corresponding schema. // See code_generators.cpp. @@ -1078,8 +1078,8 @@ extern bool GenerateJava(const Parser &parser, const std::string &path, // Generate JavaScript or TypeScript code from the definitions in the Parser // object. See idl_gen_js. -extern bool GenerateTS(const Parser &parser, const std::string &path, - const std::string &file_name); +extern bool GenerateTS(const Parser &parser, const std::string &path, + const std::string &file_name); // Generate Go files from the definitions in the Parser object. // See idl_gen_go.cpp. @@ -1140,10 +1140,10 @@ extern bool GenerateCPPYandexMapsIter(const Parser &parser, const std::string &path, const std::string &file_name); -// Generate a make rule for the generated TypeScript code. -// See idl_gen_ts.cpp. -extern std::string TSMakeRule(const Parser &parser, const std::string &path, - const std::string &file_name); +// Generate a make rule for the generated TypeScript code. +// See idl_gen_ts.cpp. +extern std::string TSMakeRule(const Parser &parser, const std::string &path, + const std::string &file_name); // Generate a make rule for the generated C++ header. // See idl_gen_cpp.cpp. @@ -1201,8 +1201,8 @@ bool GeneratePythonGRPC(const Parser &parser, const std::string &path, extern bool GenerateSwiftGRPC(const Parser &parser, const std::string &path, const std::string &file_name); -extern bool GenerateTSGRPC(const Parser &parser, const std::string &path, - const std::string &file_name); +extern bool GenerateTSGRPC(const Parser &parser, const std::string &path, + const std::string &file_name); } // namespace flatbuffers #endif // FLATBUFFERS_IDL_H_ diff --git a/contrib/libs/flatbuffers/include/flatbuffers/minireflect.h b/contrib/libs/flatbuffers/include/flatbuffers/minireflect.h index 6cb1a8240e..d95dd24b7e 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/minireflect.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/minireflect.h @@ -38,7 +38,7 @@ struct IterationVisitor { // These mark the scope of a table or struct. virtual void StartSequence() {} virtual void EndSequence() {} - // Called for each field regardless of whether it is present or not. + // Called for each field regardless of whether it is present or not. // If not present, val == nullptr. set_idx is the index of all set fields. virtual void Field(size_t /*field_idx*/, size_t /*set_idx*/, ElementaryType /*type*/, bool /*is_vector*/, @@ -234,11 +234,11 @@ inline void IterateObject(const uint8_t *obj, const TypeTable *type_table, visitor->StartSequence(); const uint8_t *prev_val = nullptr; size_t set_idx = 0; - size_t array_idx = 0; + size_t array_idx = 0; for (size_t i = 0; i < type_table->num_elems; i++) { auto type_code = type_table->type_codes[i]; auto type = static_cast<ElementaryType>(type_code.base_type); - auto is_repeating = type_code.is_repeating != 0; + auto is_repeating = type_code.is_repeating != 0; auto ref_idx = type_code.sequence_ref; const TypeTable *ref = nullptr; if (ref_idx >= 0) { ref = type_table->type_refs[ref_idx](); } @@ -250,25 +250,25 @@ inline void IterateObject(const uint8_t *obj, const TypeTable *type_table, } else { val = obj + type_table->values[i]; } - visitor->Field(i, set_idx, type, is_repeating, ref, name, val); + visitor->Field(i, set_idx, type, is_repeating, ref, name, val); if (val) { set_idx++; - if (is_repeating) { - auto elem_ptr = val; - size_t size = 0; - if (type_table->st == ST_TABLE) { - // variable length vector - val += ReadScalar<uoffset_t>(val); - auto vec = reinterpret_cast<const Vector<uint8_t> *>(val); - elem_ptr = vec->Data(); - size = vec->size(); - } else { - // otherwise fixed size array - size = type_table->array_sizes[array_idx]; - ++array_idx; - } + if (is_repeating) { + auto elem_ptr = val; + size_t size = 0; + if (type_table->st == ST_TABLE) { + // variable length vector + val += ReadScalar<uoffset_t>(val); + auto vec = reinterpret_cast<const Vector<uint8_t> *>(val); + elem_ptr = vec->Data(); + size = vec->size(); + } else { + // otherwise fixed size array + size = type_table->array_sizes[array_idx]; + ++array_idx; + } visitor->StartVector(); - for (size_t j = 0; j < size; j++) { + for (size_t j = 0; j < size; j++) { visitor->Element(j, type, ref, elem_ptr); IterateValue(type, elem_ptr, ref, prev_val, static_cast<soffset_t>(j), visitor); diff --git a/contrib/libs/flatbuffers/include/flatbuffers/reflection.h b/contrib/libs/flatbuffers/include/flatbuffers/reflection.h index b35c7aa93f..d268a3ffea 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/reflection.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/reflection.h @@ -46,32 +46,32 @@ inline bool IsLong(reflection::BaseType t) { // Size of a basic type, don't use with structs. inline size_t GetTypeSize(reflection::BaseType base_type) { // This needs to correspond to the BaseType enum. - static size_t sizes[] = { - 0, // None - 1, // UType - 1, // Bool - 1, // Byte - 1, // UByte - 2, // Short - 2, // UShort - 4, // Int - 4, // UInt - 8, // Long - 8, // ULong - 4, // Float - 8, // Double - 4, // String - 4, // Vector - 4, // Obj - 4, // Union - 0, // Array. Only used in structs. 0 was chosen to prevent out-of-bounds - // errors. - - 0 // MaxBaseType. This must be kept the last entry in this array. - }; - static_assert(sizeof(sizes) / sizeof(size_t) == reflection::MaxBaseType + 1, - "Size of sizes[] array does not match the count of BaseType " - "enum values."); + static size_t sizes[] = { + 0, // None + 1, // UType + 1, // Bool + 1, // Byte + 1, // UByte + 2, // Short + 2, // UShort + 4, // Int + 4, // UInt + 8, // Long + 8, // ULong + 4, // Float + 8, // Double + 4, // String + 4, // Vector + 4, // Obj + 4, // Union + 0, // Array. Only used in structs. 0 was chosen to prevent out-of-bounds + // errors. + + 0 // MaxBaseType. This must be kept the last entry in this array. + }; + static_assert(sizeof(sizes) / sizeof(size_t) == reflection::MaxBaseType + 1, + "Size of sizes[] array does not match the count of BaseType " + "enum values."); return sizes[base_type]; } @@ -494,8 +494,8 @@ Offset<const Table *> CopyTable(FlatBufferBuilder &fbb, // buf should point to the start of flatbuffer data. // length specifies the size of the flatbuffer data. bool Verify(const reflection::Schema &schema, const reflection::Object &root, - const uint8_t *buf, size_t length, uoffset_t max_depth = 64, - uoffset_t max_tables = 1000000); + const uint8_t *buf, size_t length, uoffset_t max_depth = 64, + uoffset_t max_tables = 1000000); } // namespace flatbuffers diff --git a/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h b/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h index c98ebc0a40..93dc4b88b7 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h @@ -53,11 +53,11 @@ enum BaseType { Vector = 14, Obj = 15, Union = 16, - Array = 17, - MaxBaseType = 18 + Array = 17, + MaxBaseType = 18 }; -inline const BaseType (&EnumValuesBaseType())[19] { +inline const BaseType (&EnumValuesBaseType())[19] { static const BaseType values[] = { None, UType, @@ -76,14 +76,14 @@ inline const BaseType (&EnumValuesBaseType())[19] { Vector, Obj, Union, - Array, - MaxBaseType + Array, + MaxBaseType }; return values; } inline const char * const *EnumNamesBaseType() { - static const char * const names[20] = { + static const char * const names[20] = { "None", "UType", "Bool", @@ -102,56 +102,56 @@ inline const char * const *EnumNamesBaseType() { "Obj", "Union", "Array", - "MaxBaseType", + "MaxBaseType", nullptr }; return names; } inline const char *EnumNameBaseType(BaseType e) { - if (flatbuffers::IsOutRange(e, None, MaxBaseType)) return ""; + if (flatbuffers::IsOutRange(e, None, MaxBaseType)) return ""; const size_t index = static_cast<size_t>(e); return EnumNamesBaseType()[index]; } -enum AdvancedFeatures { - AdvancedArrayFeatures = 1ULL, - AdvancedUnionFeatures = 2ULL, - OptionalScalars = 4ULL, - DefaultVectorsAndStrings = 8ULL -}; - -inline const AdvancedFeatures (&EnumValuesAdvancedFeatures())[4] { - static const AdvancedFeatures values[] = { - AdvancedArrayFeatures, - AdvancedUnionFeatures, - OptionalScalars, - DefaultVectorsAndStrings - }; - return values; -} - -inline const char * const *EnumNamesAdvancedFeatures() { - static const char * const names[9] = { - "AdvancedArrayFeatures", - "AdvancedUnionFeatures", - "", - "OptionalScalars", - "", - "", - "", - "DefaultVectorsAndStrings", - nullptr - }; - return names; -} - -inline const char *EnumNameAdvancedFeatures(AdvancedFeatures e) { - if (flatbuffers::IsOutRange(e, AdvancedArrayFeatures, DefaultVectorsAndStrings)) return ""; - const size_t index = static_cast<size_t>(e) - static_cast<size_t>(AdvancedArrayFeatures); - return EnumNamesAdvancedFeatures()[index]; -} - +enum AdvancedFeatures { + AdvancedArrayFeatures = 1ULL, + AdvancedUnionFeatures = 2ULL, + OptionalScalars = 4ULL, + DefaultVectorsAndStrings = 8ULL +}; + +inline const AdvancedFeatures (&EnumValuesAdvancedFeatures())[4] { + static const AdvancedFeatures values[] = { + AdvancedArrayFeatures, + AdvancedUnionFeatures, + OptionalScalars, + DefaultVectorsAndStrings + }; + return values; +} + +inline const char * const *EnumNamesAdvancedFeatures() { + static const char * const names[9] = { + "AdvancedArrayFeatures", + "AdvancedUnionFeatures", + "", + "OptionalScalars", + "", + "", + "", + "DefaultVectorsAndStrings", + nullptr + }; + return names; +} + +inline const char *EnumNameAdvancedFeatures(AdvancedFeatures e) { + if (flatbuffers::IsOutRange(e, AdvancedArrayFeatures, DefaultVectorsAndStrings)) return ""; + const size_t index = static_cast<size_t>(e) - static_cast<size_t>(AdvancedArrayFeatures); + return EnumNamesAdvancedFeatures()[index]; +} + struct Type FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef TypeBuilder Builder; enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { @@ -549,8 +549,8 @@ struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { VT_REQUIRED = 18, VT_KEY = 20, VT_ATTRIBUTES = 22, - VT_DOCUMENTATION = 24, - VT_OPTIONAL = 26 + VT_DOCUMENTATION = 24, + VT_OPTIONAL = 26 }; const flatbuffers::String *name() const { return GetPointer<const flatbuffers::String *>(VT_NAME); @@ -591,9 +591,9 @@ struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *documentation() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(VT_DOCUMENTATION); } - bool optional() const { - return GetField<uint8_t>(VT_OPTIONAL, 0) != 0; - } + bool optional() const { + return GetField<uint8_t>(VT_OPTIONAL, 0) != 0; + } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyOffsetRequired(verifier, VT_NAME) && @@ -613,7 +613,7 @@ struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { VerifyOffset(verifier, VT_DOCUMENTATION) && verifier.VerifyVector(documentation()) && verifier.VerifyVectorOfStrings(documentation()) && - VerifyField<uint8_t>(verifier, VT_OPTIONAL) && + VerifyField<uint8_t>(verifier, VT_OPTIONAL) && verifier.EndTable(); } }; @@ -655,9 +655,9 @@ struct FieldBuilder { void add_documentation(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation) { fbb_.AddOffset(Field::VT_DOCUMENTATION, documentation); } - void add_optional(bool optional) { - fbb_.AddElement<uint8_t>(Field::VT_OPTIONAL, static_cast<uint8_t>(optional), 0); - } + void add_optional(bool optional) { + fbb_.AddElement<uint8_t>(Field::VT_OPTIONAL, static_cast<uint8_t>(optional), 0); + } explicit FieldBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -683,8 +683,8 @@ inline flatbuffers::Offset<Field> CreateField( bool required = false, bool key = false, flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>> attributes = 0, - flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation = 0, - bool optional = false) { + flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation = 0, + bool optional = false) { FieldBuilder builder_(_fbb); builder_.add_default_real(default_real); builder_.add_default_integer(default_integer); @@ -694,7 +694,7 @@ inline flatbuffers::Offset<Field> CreateField( builder_.add_name(name); builder_.add_offset(offset); builder_.add_id(id); - builder_.add_optional(optional); + builder_.add_optional(optional); builder_.add_key(key); builder_.add_required(required); builder_.add_deprecated(deprecated); @@ -713,8 +713,8 @@ inline flatbuffers::Offset<Field> CreateFieldDirect( bool required = false, bool key = false, std::vector<flatbuffers::Offset<reflection::KeyValue>> *attributes = nullptr, - const std::vector<flatbuffers::Offset<flatbuffers::String>> *documentation = nullptr, - bool optional = false) { + const std::vector<flatbuffers::Offset<flatbuffers::String>> *documentation = nullptr, + bool optional = false) { auto name__ = name ? _fbb.CreateString(name) : 0; auto attributes__ = attributes ? _fbb.CreateVectorOfSortedTables<reflection::KeyValue>(attributes) : 0; auto documentation__ = documentation ? _fbb.CreateVector<flatbuffers::Offset<flatbuffers::String>>(*documentation) : 0; @@ -730,8 +730,8 @@ inline flatbuffers::Offset<Field> CreateFieldDirect( required, key, attributes__, - documentation__, - optional); + documentation__, + optional); } struct Object FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { @@ -1101,8 +1101,8 @@ struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { VT_FILE_IDENT = 8, VT_FILE_EXT = 10, VT_ROOT_TABLE = 12, - VT_SERVICES = 14, - VT_ADVANCED_FEATURES = 16 + VT_SERVICES = 14, + VT_ADVANCED_FEATURES = 16 }; const flatbuffers::Vector<flatbuffers::Offset<reflection::Object>> *objects() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<reflection::Object>> *>(VT_OBJECTS); @@ -1122,9 +1122,9 @@ struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { const flatbuffers::Vector<flatbuffers::Offset<reflection::Service>> *services() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<reflection::Service>> *>(VT_SERVICES); } - reflection::AdvancedFeatures advanced_features() const { - return static_cast<reflection::AdvancedFeatures>(GetField<uint64_t>(VT_ADVANCED_FEATURES, 0)); - } + reflection::AdvancedFeatures advanced_features() const { + return static_cast<reflection::AdvancedFeatures>(GetField<uint64_t>(VT_ADVANCED_FEATURES, 0)); + } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyOffsetRequired(verifier, VT_OBJECTS) && @@ -1142,7 +1142,7 @@ struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { VerifyOffset(verifier, VT_SERVICES) && verifier.VerifyVector(services()) && verifier.VerifyVectorOfTables(services()) && - VerifyField<uint64_t>(verifier, VT_ADVANCED_FEATURES) && + VerifyField<uint64_t>(verifier, VT_ADVANCED_FEATURES) && verifier.EndTable(); } }; @@ -1169,9 +1169,9 @@ struct SchemaBuilder { void add_services(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<reflection::Service>>> services) { fbb_.AddOffset(Schema::VT_SERVICES, services); } - void add_advanced_features(reflection::AdvancedFeatures advanced_features) { - fbb_.AddElement<uint64_t>(Schema::VT_ADVANCED_FEATURES, static_cast<uint64_t>(advanced_features), 0); - } + void add_advanced_features(reflection::AdvancedFeatures advanced_features) { + fbb_.AddElement<uint64_t>(Schema::VT_ADVANCED_FEATURES, static_cast<uint64_t>(advanced_features), 0); + } explicit SchemaBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -1192,10 +1192,10 @@ inline flatbuffers::Offset<Schema> CreateSchema( flatbuffers::Offset<flatbuffers::String> file_ident = 0, flatbuffers::Offset<flatbuffers::String> file_ext = 0, flatbuffers::Offset<reflection::Object> root_table = 0, - flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<reflection::Service>>> services = 0, - reflection::AdvancedFeatures advanced_features = static_cast<reflection::AdvancedFeatures>(0)) { + flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<reflection::Service>>> services = 0, + reflection::AdvancedFeatures advanced_features = static_cast<reflection::AdvancedFeatures>(0)) { SchemaBuilder builder_(_fbb); - builder_.add_advanced_features(advanced_features); + builder_.add_advanced_features(advanced_features); builder_.add_services(services); builder_.add_root_table(root_table); builder_.add_file_ext(file_ext); @@ -1212,8 +1212,8 @@ inline flatbuffers::Offset<Schema> CreateSchemaDirect( const char *file_ident = nullptr, const char *file_ext = nullptr, flatbuffers::Offset<reflection::Object> root_table = 0, - std::vector<flatbuffers::Offset<reflection::Service>> *services = nullptr, - reflection::AdvancedFeatures advanced_features = static_cast<reflection::AdvancedFeatures>(0)) { + std::vector<flatbuffers::Offset<reflection::Service>> *services = nullptr, + reflection::AdvancedFeatures advanced_features = static_cast<reflection::AdvancedFeatures>(0)) { auto objects__ = objects ? _fbb.CreateVectorOfSortedTables<reflection::Object>(objects) : 0; auto enums__ = enums ? _fbb.CreateVectorOfSortedTables<reflection::Enum>(enums) : 0; auto file_ident__ = file_ident ? _fbb.CreateString(file_ident) : 0; @@ -1226,8 +1226,8 @@ inline flatbuffers::Offset<Schema> CreateSchemaDirect( file_ident__, file_ext__, root_table, - services__, - advanced_features); + services__, + advanced_features); } inline const reflection::Schema *GetSchema(const void *buf) { diff --git a/contrib/libs/flatbuffers/include/flatbuffers/stl_emulation.h b/contrib/libs/flatbuffers/include/flatbuffers/stl_emulation.h index b32fa82b8c..e8e1e59487 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/stl_emulation.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/stl_emulation.h @@ -18,7 +18,7 @@ #define FLATBUFFERS_STL_EMULATION_H_ // clang-format off -#include "base.h" +#include "base.h" #include <string> #include <type_traits> @@ -34,34 +34,34 @@ #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) \ - || (defined(__cplusplus) && __cplusplus >= 201703L) \ - || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)) - #include <optional> - #ifndef FLATBUFFERS_USE_STD_OPTIONAL - #define FLATBUFFERS_USE_STD_OPTIONAL - #endif -#endif // defined(FLATBUFFERS_USE_STD_OPTIONAL) ... - -// The __cpp_lib_span is the predefined feature macro. -#if defined(FLATBUFFERS_USE_STD_SPAN) - #include <span> -#elif defined(__cpp_lib_span) && defined(__has_include) - #if __has_include(<span>) - #include <span> - #define FLATBUFFERS_USE_STD_SPAN - #endif -#else - // Disable non-trivial ctors if FLATBUFFERS_SPAN_MINIMAL defined. - #if !defined(FLATBUFFERS_TEMPLATES_ALIASES) || defined(FLATBUFFERS_CPP98_STL) - #define FLATBUFFERS_SPAN_MINIMAL - #else - // Enable implicit construction of a span<T,N> from a std::array<T,N>. - #include <array> - #endif -#endif // defined(FLATBUFFERS_USE_STD_SPAN) +// Detect C++17 compatible compiler. +// __cplusplus >= 201703L - a compiler has support of 'static inline' variables. +#if defined(FLATBUFFERS_USE_STD_OPTIONAL) \ + || (defined(__cplusplus) && __cplusplus >= 201703L) \ + || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)) + #include <optional> + #ifndef FLATBUFFERS_USE_STD_OPTIONAL + #define FLATBUFFERS_USE_STD_OPTIONAL + #endif +#endif // defined(FLATBUFFERS_USE_STD_OPTIONAL) ... + +// The __cpp_lib_span is the predefined feature macro. +#if defined(FLATBUFFERS_USE_STD_SPAN) + #include <span> +#elif defined(__cpp_lib_span) && defined(__has_include) + #if __has_include(<span>) + #include <span> + #define FLATBUFFERS_USE_STD_SPAN + #endif +#else + // Disable non-trivial ctors if FLATBUFFERS_SPAN_MINIMAL defined. + #if !defined(FLATBUFFERS_TEMPLATES_ALIASES) || defined(FLATBUFFERS_CPP98_STL) + #define FLATBUFFERS_SPAN_MINIMAL + #else + // Enable implicit construction of a span<T,N> from a std::array<T,N>. + #include <array> + #endif +#endif // defined(FLATBUFFERS_USE_STD_SPAN) // This header provides backwards compatibility for C++98 STLs like stlport. namespace flatbuffers { @@ -164,8 +164,8 @@ inline void vector_emplace_back(std::vector<T> *vector, V &&data) { 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>; + template <bool B> + using bool_constant = integral_constant<bool, B>; #else // Map C++ TR1 templates defined by stlport. template <typename T> using is_scalar = std::tr1::is_scalar<T>; @@ -189,8 +189,8 @@ inline void vector_emplace_back(std::vector<T> *vector, V &&data) { 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>; + template <bool B> + using bool_constant = integral_constant<bool, B>; #endif // !FLATBUFFERS_CPP98_STL #else // MSVC 2010 doesn't support C++11 aliases. @@ -205,8 +205,8 @@ inline void vector_emplace_back(std::vector<T> *vector, V &&data) { struct conditional : public std::conditional<B, T, F> {}; template<class T, T v> struct integral_constant : public std::integral_constant<T, v> {}; - template <bool B> - struct bool_constant : public integral_constant<bool, B> {}; + template <bool B> + struct bool_constant : public integral_constant<bool, B> {}; #endif // defined(FLATBUFFERS_TEMPLATES_ALIASES) #ifndef FLATBUFFERS_CPP98_STL @@ -216,7 +216,7 @@ inline void vector_emplace_back(std::vector<T> *vector, V &&data) { // 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) + // 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: @@ -328,346 +328,346 @@ inline void vector_emplace_back(std::vector<T> *vector, V &&data) { #endif // !FLATBUFFERS_CPP98_STL -#ifdef FLATBUFFERS_USE_STD_OPTIONAL -template<class T> -using Optional = std::optional<T>; -using nullopt_t = std::nullopt_t; -inline constexpr nullopt_t nullopt = std::nullopt; - -#else -// Limited implementation of Optional<T> type for a scalar T. -// This implementation limited by trivial types compatible with -// std::is_arithmetic<T> or std::is_enum<T> type traits. - -// A tag to indicate an empty flatbuffers::optional<T>. -struct nullopt_t { - explicit FLATBUFFERS_CONSTEXPR_CPP11 nullopt_t(int) {} -}; - -#if defined(FLATBUFFERS_CONSTEXPR_DEFINED) - namespace internal { - template <class> struct nullopt_holder { - static constexpr nullopt_t instance_ = nullopt_t(0); - }; - template<class Dummy> - constexpr nullopt_t nullopt_holder<Dummy>::instance_; - } - static constexpr const nullopt_t &nullopt = internal::nullopt_holder<void>::instance_; - -#else - namespace internal { - template <class> struct nullopt_holder { - static const nullopt_t instance_; - }; - template<class Dummy> - const nullopt_t nullopt_holder<Dummy>::instance_ = nullopt_t(0); - } - static const nullopt_t &nullopt = internal::nullopt_holder<void>::instance_; - -#endif - -template<class T> -class Optional FLATBUFFERS_FINAL_CLASS { - // Non-scalar 'T' would extremely complicated Optional<T>. - // Use is_scalar<T> checking because flatbuffers flatbuffers::is_arithmetic<T> - // isn't implemented. - static_assert(flatbuffers::is_scalar<T>::value, "unexpected type T"); - - public: - ~Optional() {} - - FLATBUFFERS_CONSTEXPR_CPP11 Optional() FLATBUFFERS_NOEXCEPT - : value_(), has_value_(false) {} - - FLATBUFFERS_CONSTEXPR_CPP11 Optional(nullopt_t) FLATBUFFERS_NOEXCEPT - : value_(), has_value_(false) {} - - FLATBUFFERS_CONSTEXPR_CPP11 Optional(T val) FLATBUFFERS_NOEXCEPT - : value_(val), has_value_(true) {} - - FLATBUFFERS_CONSTEXPR_CPP11 Optional(const Optional &other) FLATBUFFERS_NOEXCEPT - : value_(other.value_), has_value_(other.has_value_) {} - - FLATBUFFERS_CONSTEXPR_CPP14 Optional &operator=(const Optional &other) FLATBUFFERS_NOEXCEPT { - value_ = other.value_; - has_value_ = other.has_value_; - return *this; - } - - FLATBUFFERS_CONSTEXPR_CPP14 Optional &operator=(nullopt_t) FLATBUFFERS_NOEXCEPT { - value_ = T(); - has_value_ = false; - return *this; - } - - FLATBUFFERS_CONSTEXPR_CPP14 Optional &operator=(T val) FLATBUFFERS_NOEXCEPT { - value_ = val; - has_value_ = true; - return *this; - } - - void reset() FLATBUFFERS_NOEXCEPT { - *this = nullopt; - } - - void swap(Optional &other) FLATBUFFERS_NOEXCEPT { - std::swap(value_, other.value_); - std::swap(has_value_, other.has_value_); - } - - FLATBUFFERS_CONSTEXPR_CPP11 FLATBUFFERS_EXPLICIT_CPP11 operator bool() const FLATBUFFERS_NOEXCEPT { - return has_value_; - } - - FLATBUFFERS_CONSTEXPR_CPP11 bool has_value() const FLATBUFFERS_NOEXCEPT { - return has_value_; - } - - FLATBUFFERS_CONSTEXPR_CPP11 const T& operator*() const FLATBUFFERS_NOEXCEPT { - return value_; - } - - const T& value() const { - FLATBUFFERS_ASSERT(has_value()); - return value_; - } - - T value_or(T default_value) const FLATBUFFERS_NOEXCEPT { - return has_value() ? value_ : default_value; - } - - private: - T value_; - bool has_value_; -}; - -template<class T> -FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const Optional<T>& opt, nullopt_t) FLATBUFFERS_NOEXCEPT { - return !opt; -} -template<class T> -FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(nullopt_t, const Optional<T>& opt) FLATBUFFERS_NOEXCEPT { - return !opt; -} - -template<class T, class U> -FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const Optional<T>& lhs, const U& rhs) FLATBUFFERS_NOEXCEPT { - return static_cast<bool>(lhs) && (*lhs == rhs); -} - -template<class T, class U> -FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const T& lhs, const Optional<U>& rhs) FLATBUFFERS_NOEXCEPT { - return static_cast<bool>(rhs) && (lhs == *rhs); -} - -template<class T, class U> -FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const Optional<T>& lhs, const Optional<U>& rhs) FLATBUFFERS_NOEXCEPT { - return static_cast<bool>(lhs) != static_cast<bool>(rhs) - ? false - : !static_cast<bool>(lhs) ? false : (*lhs == *rhs); -} -#endif // FLATBUFFERS_USE_STD_OPTIONAL - - -// Very limited and naive partial implementation of C++20 std::span<T,Extent>. -#if defined(FLATBUFFERS_USE_STD_SPAN) - inline constexpr std::size_t dynamic_extent = std::dynamic_extent; - template<class T, std::size_t Extent = std::dynamic_extent> - using span = std::span<T, Extent>; - -#else // !defined(FLATBUFFERS_USE_STD_SPAN) -FLATBUFFERS_CONSTEXPR std::size_t dynamic_extent = static_cast<std::size_t>(-1); - -// Exclude this code if MSVC2010 or non-STL Android is active. -// The non-STL Android doesn't have `std::is_convertible` required for SFINAE. -#if !defined(FLATBUFFERS_SPAN_MINIMAL) -namespace internal { - // This is SFINAE helper class for checking of a common condition: - // > This overload only participates in overload resolution - // > Check whether a pointer to an array of U can be converted - // > to a pointer to an array of E. - // This helper is used for checking of 'U -> const U'. - template<class E, std::size_t Extent, class U, std::size_t N> - struct is_span_convertable { - using type = - typename std::conditional<std::is_convertible<U (*)[], E (*)[]>::value - && (Extent == dynamic_extent || N == Extent), - int, void>::type; - }; - -} // namespace internal -#endif // !defined(FLATBUFFERS_SPAN_MINIMAL) - -// T - element type; must be a complete type that is not an abstract -// class type. -// Extent - the number of elements in the sequence, or dynamic. -template<class T, std::size_t Extent = dynamic_extent> -class span FLATBUFFERS_FINAL_CLASS { - public: - typedef T element_type; - typedef T& reference; - typedef const T& const_reference; - typedef T* pointer; - typedef const T* const_pointer; - typedef std::size_t size_type; - - static FLATBUFFERS_CONSTEXPR size_type extent = Extent; - - // Returns the number of elements in the span. - FLATBUFFERS_CONSTEXPR_CPP11 size_type size() const FLATBUFFERS_NOEXCEPT { - return count_; - } - - // Returns the size of the sequence in bytes. - FLATBUFFERS_CONSTEXPR_CPP11 - size_type size_bytes() const FLATBUFFERS_NOEXCEPT { - return size() * sizeof(element_type); - } - - // Checks if the span is empty. - FLATBUFFERS_CONSTEXPR_CPP11 bool empty() const FLATBUFFERS_NOEXCEPT { - return size() == 0; - } - - // Returns a pointer to the beginning of the sequence. - FLATBUFFERS_CONSTEXPR_CPP11 pointer data() const FLATBUFFERS_NOEXCEPT { - return data_; - } - - // Returns a reference to the idx-th element of the sequence. - // The behavior is undefined if the idx is greater than or equal to size(). - FLATBUFFERS_CONSTEXPR_CPP11 reference operator[](size_type idx) const { - return data()[idx]; - } - - FLATBUFFERS_CONSTEXPR_CPP11 span(const span &other) FLATBUFFERS_NOEXCEPT - : data_(other.data_), count_(other.count_) {} - - FLATBUFFERS_CONSTEXPR_CPP14 span &operator=(const span &other) - FLATBUFFERS_NOEXCEPT { - data_ = other.data_; - count_ = other.count_; - } - - // Limited implementation of - // `template <class It> constexpr std::span(It first, size_type count);`. - // - // Constructs a span that is a view over the range [first, first + count); - // the resulting span has: data() == first and size() == count. - // The behavior is undefined if [first, first + count) is not a valid range, - // or if (extent != flatbuffers::dynamic_extent && count != extent). - FLATBUFFERS_CONSTEXPR_CPP11 - explicit span(pointer first, size_type count) FLATBUFFERS_NOEXCEPT - : data_ (Extent == dynamic_extent ? first : (Extent == count ? first : nullptr)), - count_(Extent == dynamic_extent ? count : (Extent == count ? Extent : 0)) { - // Make span empty if the count argument is incompatible with span<T,N>. - } - - // Exclude this code if MSVC2010 is active. The MSVC2010 isn't C++11 - // compliant, it doesn't support default template arguments for functions. - #if defined(FLATBUFFERS_SPAN_MINIMAL) - FLATBUFFERS_CONSTEXPR_CPP11 span() FLATBUFFERS_NOEXCEPT : data_(nullptr), - count_(0) { - static_assert(extent == 0 || extent == dynamic_extent, "invalid span"); - } - - #else - // Constructs an empty span whose data() == nullptr and size() == 0. - // This overload only participates in overload resolution if - // extent == 0 || extent == flatbuffers::dynamic_extent. - // A dummy template argument N is need dependency for SFINAE. - template<std::size_t N = 0, - typename internal::is_span_convertable<element_type, Extent, element_type, (N - N)>::type = 0> - FLATBUFFERS_CONSTEXPR_CPP11 span() FLATBUFFERS_NOEXCEPT : data_(nullptr), - count_(0) { - static_assert(extent == 0 || extent == dynamic_extent, "invalid span"); - } - - // Constructs a span that is a view over the array arr; the resulting span - // has size() == N and data() == std::data(arr). These overloads only - // participate in overload resolution if - // extent == std::dynamic_extent || N == extent is true and - // std::remove_pointer_t<decltype(std::data(arr))>(*)[] - // is convertible to element_type (*)[]. - template<std::size_t N, - typename internal::is_span_convertable<element_type, Extent, element_type, N>::type = 0> - FLATBUFFERS_CONSTEXPR_CPP11 span(element_type (&arr)[N]) FLATBUFFERS_NOEXCEPT - : data_(arr), count_(N) {} - - template<class U, std::size_t N, - typename internal::is_span_convertable<element_type, Extent, U, N>::type = 0> - FLATBUFFERS_CONSTEXPR_CPP11 span(std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT - : data_(arr.data()), count_(N) {} - - //template<class U, std::size_t N, - // int = 0> - //FLATBUFFERS_CONSTEXPR_CPP11 span(std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT - // : data_(arr.data()), count_(N) {} - - template<class U, std::size_t N, - typename internal::is_span_convertable<element_type, Extent, U, N>::type = 0> - FLATBUFFERS_CONSTEXPR_CPP11 span(const std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT - : data_(arr.data()), count_(N) {} - - // Converting constructor from another span s; - // the resulting span has size() == s.size() and data() == s.data(). - // This overload only participates in overload resolution - // if extent == std::dynamic_extent || N == extent is true and U (*)[] - // is convertible to element_type (*)[]. - template<class U, std::size_t N, - typename internal::is_span_convertable<element_type, Extent, U, N>::type = 0> - FLATBUFFERS_CONSTEXPR_CPP11 span(const flatbuffers::span<U, N> &s) FLATBUFFERS_NOEXCEPT - : span(s.data(), s.size()) { - } - - #endif // !defined(FLATBUFFERS_SPAN_MINIMAL) - - private: - // This is a naive implementation with 'count_' member even if (Extent != dynamic_extent). - pointer const data_; - const size_type count_; -}; - - #if !defined(FLATBUFFERS_SPAN_MINIMAL) - template<class U, std::size_t N> - FLATBUFFERS_CONSTEXPR_CPP11 - flatbuffers::span<U, N> make_span(U(&arr)[N]) FLATBUFFERS_NOEXCEPT { - return span<U, N>(arr); - } - - template<class U, std::size_t N> - FLATBUFFERS_CONSTEXPR_CPP11 - flatbuffers::span<const U, N> make_span(const U(&arr)[N]) FLATBUFFERS_NOEXCEPT { - return span<const U, N>(arr); - } - - template<class U, std::size_t N> - FLATBUFFERS_CONSTEXPR_CPP11 - flatbuffers::span<U, N> make_span(std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT { - return span<U, N>(arr); - } - - template<class U, std::size_t N> - FLATBUFFERS_CONSTEXPR_CPP11 - flatbuffers::span<const U, N> make_span(const std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT { - return span<const U, N>(arr); - } - - template<class U, std::size_t N> - FLATBUFFERS_CONSTEXPR_CPP11 - flatbuffers::span<U, dynamic_extent> make_span(U *first, std::size_t count) FLATBUFFERS_NOEXCEPT { - return span<U, dynamic_extent>(first, count); - } - - template<class U, std::size_t N> - FLATBUFFERS_CONSTEXPR_CPP11 - flatbuffers::span<const U, dynamic_extent> make_span(const U *first, std::size_t count) FLATBUFFERS_NOEXCEPT { - return span<const U, dynamic_extent>(first, count); - } -#endif - -#endif // defined(FLATBUFFERS_USE_STD_SPAN) - +#ifdef FLATBUFFERS_USE_STD_OPTIONAL +template<class T> +using Optional = std::optional<T>; +using nullopt_t = std::nullopt_t; +inline constexpr nullopt_t nullopt = std::nullopt; + +#else +// Limited implementation of Optional<T> type for a scalar T. +// This implementation limited by trivial types compatible with +// std::is_arithmetic<T> or std::is_enum<T> type traits. + +// A tag to indicate an empty flatbuffers::optional<T>. +struct nullopt_t { + explicit FLATBUFFERS_CONSTEXPR_CPP11 nullopt_t(int) {} +}; + +#if defined(FLATBUFFERS_CONSTEXPR_DEFINED) + namespace internal { + template <class> struct nullopt_holder { + static constexpr nullopt_t instance_ = nullopt_t(0); + }; + template<class Dummy> + constexpr nullopt_t nullopt_holder<Dummy>::instance_; + } + static constexpr const nullopt_t &nullopt = internal::nullopt_holder<void>::instance_; + +#else + namespace internal { + template <class> struct nullopt_holder { + static const nullopt_t instance_; + }; + template<class Dummy> + const nullopt_t nullopt_holder<Dummy>::instance_ = nullopt_t(0); + } + static const nullopt_t &nullopt = internal::nullopt_holder<void>::instance_; + +#endif + +template<class T> +class Optional FLATBUFFERS_FINAL_CLASS { + // Non-scalar 'T' would extremely complicated Optional<T>. + // Use is_scalar<T> checking because flatbuffers flatbuffers::is_arithmetic<T> + // isn't implemented. + static_assert(flatbuffers::is_scalar<T>::value, "unexpected type T"); + + public: + ~Optional() {} + + FLATBUFFERS_CONSTEXPR_CPP11 Optional() FLATBUFFERS_NOEXCEPT + : value_(), has_value_(false) {} + + FLATBUFFERS_CONSTEXPR_CPP11 Optional(nullopt_t) FLATBUFFERS_NOEXCEPT + : value_(), has_value_(false) {} + + FLATBUFFERS_CONSTEXPR_CPP11 Optional(T val) FLATBUFFERS_NOEXCEPT + : value_(val), has_value_(true) {} + + FLATBUFFERS_CONSTEXPR_CPP11 Optional(const Optional &other) FLATBUFFERS_NOEXCEPT + : value_(other.value_), has_value_(other.has_value_) {} + + FLATBUFFERS_CONSTEXPR_CPP14 Optional &operator=(const Optional &other) FLATBUFFERS_NOEXCEPT { + value_ = other.value_; + has_value_ = other.has_value_; + return *this; + } + + FLATBUFFERS_CONSTEXPR_CPP14 Optional &operator=(nullopt_t) FLATBUFFERS_NOEXCEPT { + value_ = T(); + has_value_ = false; + return *this; + } + + FLATBUFFERS_CONSTEXPR_CPP14 Optional &operator=(T val) FLATBUFFERS_NOEXCEPT { + value_ = val; + has_value_ = true; + return *this; + } + + void reset() FLATBUFFERS_NOEXCEPT { + *this = nullopt; + } + + void swap(Optional &other) FLATBUFFERS_NOEXCEPT { + std::swap(value_, other.value_); + std::swap(has_value_, other.has_value_); + } + + FLATBUFFERS_CONSTEXPR_CPP11 FLATBUFFERS_EXPLICIT_CPP11 operator bool() const FLATBUFFERS_NOEXCEPT { + return has_value_; + } + + FLATBUFFERS_CONSTEXPR_CPP11 bool has_value() const FLATBUFFERS_NOEXCEPT { + return has_value_; + } + + FLATBUFFERS_CONSTEXPR_CPP11 const T& operator*() const FLATBUFFERS_NOEXCEPT { + return value_; + } + + const T& value() const { + FLATBUFFERS_ASSERT(has_value()); + return value_; + } + + T value_or(T default_value) const FLATBUFFERS_NOEXCEPT { + return has_value() ? value_ : default_value; + } + + private: + T value_; + bool has_value_; +}; + +template<class T> +FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const Optional<T>& opt, nullopt_t) FLATBUFFERS_NOEXCEPT { + return !opt; +} +template<class T> +FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(nullopt_t, const Optional<T>& opt) FLATBUFFERS_NOEXCEPT { + return !opt; +} + +template<class T, class U> +FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const Optional<T>& lhs, const U& rhs) FLATBUFFERS_NOEXCEPT { + return static_cast<bool>(lhs) && (*lhs == rhs); +} + +template<class T, class U> +FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const T& lhs, const Optional<U>& rhs) FLATBUFFERS_NOEXCEPT { + return static_cast<bool>(rhs) && (lhs == *rhs); +} + +template<class T, class U> +FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const Optional<T>& lhs, const Optional<U>& rhs) FLATBUFFERS_NOEXCEPT { + return static_cast<bool>(lhs) != static_cast<bool>(rhs) + ? false + : !static_cast<bool>(lhs) ? false : (*lhs == *rhs); +} +#endif // FLATBUFFERS_USE_STD_OPTIONAL + + +// Very limited and naive partial implementation of C++20 std::span<T,Extent>. +#if defined(FLATBUFFERS_USE_STD_SPAN) + inline constexpr std::size_t dynamic_extent = std::dynamic_extent; + template<class T, std::size_t Extent = std::dynamic_extent> + using span = std::span<T, Extent>; + +#else // !defined(FLATBUFFERS_USE_STD_SPAN) +FLATBUFFERS_CONSTEXPR std::size_t dynamic_extent = static_cast<std::size_t>(-1); + +// Exclude this code if MSVC2010 or non-STL Android is active. +// The non-STL Android doesn't have `std::is_convertible` required for SFINAE. +#if !defined(FLATBUFFERS_SPAN_MINIMAL) +namespace internal { + // This is SFINAE helper class for checking of a common condition: + // > This overload only participates in overload resolution + // > Check whether a pointer to an array of U can be converted + // > to a pointer to an array of E. + // This helper is used for checking of 'U -> const U'. + template<class E, std::size_t Extent, class U, std::size_t N> + struct is_span_convertable { + using type = + typename std::conditional<std::is_convertible<U (*)[], E (*)[]>::value + && (Extent == dynamic_extent || N == Extent), + int, void>::type; + }; + +} // namespace internal +#endif // !defined(FLATBUFFERS_SPAN_MINIMAL) + +// T - element type; must be a complete type that is not an abstract +// class type. +// Extent - the number of elements in the sequence, or dynamic. +template<class T, std::size_t Extent = dynamic_extent> +class span FLATBUFFERS_FINAL_CLASS { + public: + typedef T element_type; + typedef T& reference; + typedef const T& const_reference; + typedef T* pointer; + typedef const T* const_pointer; + typedef std::size_t size_type; + + static FLATBUFFERS_CONSTEXPR size_type extent = Extent; + + // Returns the number of elements in the span. + FLATBUFFERS_CONSTEXPR_CPP11 size_type size() const FLATBUFFERS_NOEXCEPT { + return count_; + } + + // Returns the size of the sequence in bytes. + FLATBUFFERS_CONSTEXPR_CPP11 + size_type size_bytes() const FLATBUFFERS_NOEXCEPT { + return size() * sizeof(element_type); + } + + // Checks if the span is empty. + FLATBUFFERS_CONSTEXPR_CPP11 bool empty() const FLATBUFFERS_NOEXCEPT { + return size() == 0; + } + + // Returns a pointer to the beginning of the sequence. + FLATBUFFERS_CONSTEXPR_CPP11 pointer data() const FLATBUFFERS_NOEXCEPT { + return data_; + } + + // Returns a reference to the idx-th element of the sequence. + // The behavior is undefined if the idx is greater than or equal to size(). + FLATBUFFERS_CONSTEXPR_CPP11 reference operator[](size_type idx) const { + return data()[idx]; + } + + FLATBUFFERS_CONSTEXPR_CPP11 span(const span &other) FLATBUFFERS_NOEXCEPT + : data_(other.data_), count_(other.count_) {} + + FLATBUFFERS_CONSTEXPR_CPP14 span &operator=(const span &other) + FLATBUFFERS_NOEXCEPT { + data_ = other.data_; + count_ = other.count_; + } + + // Limited implementation of + // `template <class It> constexpr std::span(It first, size_type count);`. + // + // Constructs a span that is a view over the range [first, first + count); + // the resulting span has: data() == first and size() == count. + // The behavior is undefined if [first, first + count) is not a valid range, + // or if (extent != flatbuffers::dynamic_extent && count != extent). + FLATBUFFERS_CONSTEXPR_CPP11 + explicit span(pointer first, size_type count) FLATBUFFERS_NOEXCEPT + : data_ (Extent == dynamic_extent ? first : (Extent == count ? first : nullptr)), + count_(Extent == dynamic_extent ? count : (Extent == count ? Extent : 0)) { + // Make span empty if the count argument is incompatible with span<T,N>. + } + + // Exclude this code if MSVC2010 is active. The MSVC2010 isn't C++11 + // compliant, it doesn't support default template arguments for functions. + #if defined(FLATBUFFERS_SPAN_MINIMAL) + FLATBUFFERS_CONSTEXPR_CPP11 span() FLATBUFFERS_NOEXCEPT : data_(nullptr), + count_(0) { + static_assert(extent == 0 || extent == dynamic_extent, "invalid span"); + } + + #else + // Constructs an empty span whose data() == nullptr and size() == 0. + // This overload only participates in overload resolution if + // extent == 0 || extent == flatbuffers::dynamic_extent. + // A dummy template argument N is need dependency for SFINAE. + template<std::size_t N = 0, + typename internal::is_span_convertable<element_type, Extent, element_type, (N - N)>::type = 0> + FLATBUFFERS_CONSTEXPR_CPP11 span() FLATBUFFERS_NOEXCEPT : data_(nullptr), + count_(0) { + static_assert(extent == 0 || extent == dynamic_extent, "invalid span"); + } + + // Constructs a span that is a view over the array arr; the resulting span + // has size() == N and data() == std::data(arr). These overloads only + // participate in overload resolution if + // extent == std::dynamic_extent || N == extent is true and + // std::remove_pointer_t<decltype(std::data(arr))>(*)[] + // is convertible to element_type (*)[]. + template<std::size_t N, + typename internal::is_span_convertable<element_type, Extent, element_type, N>::type = 0> + FLATBUFFERS_CONSTEXPR_CPP11 span(element_type (&arr)[N]) FLATBUFFERS_NOEXCEPT + : data_(arr), count_(N) {} + + template<class U, std::size_t N, + typename internal::is_span_convertable<element_type, Extent, U, N>::type = 0> + FLATBUFFERS_CONSTEXPR_CPP11 span(std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT + : data_(arr.data()), count_(N) {} + + //template<class U, std::size_t N, + // int = 0> + //FLATBUFFERS_CONSTEXPR_CPP11 span(std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT + // : data_(arr.data()), count_(N) {} + + template<class U, std::size_t N, + typename internal::is_span_convertable<element_type, Extent, U, N>::type = 0> + FLATBUFFERS_CONSTEXPR_CPP11 span(const std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT + : data_(arr.data()), count_(N) {} + + // Converting constructor from another span s; + // the resulting span has size() == s.size() and data() == s.data(). + // This overload only participates in overload resolution + // if extent == std::dynamic_extent || N == extent is true and U (*)[] + // is convertible to element_type (*)[]. + template<class U, std::size_t N, + typename internal::is_span_convertable<element_type, Extent, U, N>::type = 0> + FLATBUFFERS_CONSTEXPR_CPP11 span(const flatbuffers::span<U, N> &s) FLATBUFFERS_NOEXCEPT + : span(s.data(), s.size()) { + } + + #endif // !defined(FLATBUFFERS_SPAN_MINIMAL) + + private: + // This is a naive implementation with 'count_' member even if (Extent != dynamic_extent). + pointer const data_; + const size_type count_; +}; + + #if !defined(FLATBUFFERS_SPAN_MINIMAL) + template<class U, std::size_t N> + FLATBUFFERS_CONSTEXPR_CPP11 + flatbuffers::span<U, N> make_span(U(&arr)[N]) FLATBUFFERS_NOEXCEPT { + return span<U, N>(arr); + } + + template<class U, std::size_t N> + FLATBUFFERS_CONSTEXPR_CPP11 + flatbuffers::span<const U, N> make_span(const U(&arr)[N]) FLATBUFFERS_NOEXCEPT { + return span<const U, N>(arr); + } + + template<class U, std::size_t N> + FLATBUFFERS_CONSTEXPR_CPP11 + flatbuffers::span<U, N> make_span(std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT { + return span<U, N>(arr); + } + + template<class U, std::size_t N> + FLATBUFFERS_CONSTEXPR_CPP11 + flatbuffers::span<const U, N> make_span(const std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT { + return span<const U, N>(arr); + } + + template<class U, std::size_t N> + FLATBUFFERS_CONSTEXPR_CPP11 + flatbuffers::span<U, dynamic_extent> make_span(U *first, std::size_t count) FLATBUFFERS_NOEXCEPT { + return span<U, dynamic_extent>(first, count); + } + + template<class U, std::size_t N> + FLATBUFFERS_CONSTEXPR_CPP11 + flatbuffers::span<const U, dynamic_extent> make_span(const U *first, std::size_t count) FLATBUFFERS_NOEXCEPT { + return span<const U, dynamic_extent>(first, count); + } +#endif + +#endif // defined(FLATBUFFERS_USE_STD_SPAN) + } // namespace flatbuffers #endif // FLATBUFFERS_STL_EMULATION_H_ diff --git a/contrib/libs/flatbuffers/include/flatbuffers/util.h b/contrib/libs/flatbuffers/include/flatbuffers/util.h index 979760e8b5..4493c561c2 100644 --- a/contrib/libs/flatbuffers/include/flatbuffers/util.h +++ b/contrib/libs/flatbuffers/include/flatbuffers/util.h @@ -20,7 +20,7 @@ #include <errno.h> #include "base.h" -#include "stl_emulation.h" +#include "stl_emulation.h" #ifndef FLATBUFFERS_PREFER_PRINTF # include <sstream> @@ -51,9 +51,9 @@ inline bool is_alpha(char c) { return check_ascii_range(c & 0xDF, 'a' & 0xDF, 'z' & 0xDF); } -// Check for uppercase alpha -inline bool is_alpha_upper(char c) { return check_ascii_range(c, 'A', 'Z'); } - +// Check for uppercase alpha +inline bool is_alpha_upper(char c) { return check_ascii_range(c, 'A', 'Z'); } + // Check (case-insensitive) that `c` is equal to alpha. inline bool is_alpha_char(char c, char alpha) { FLATBUFFERS_ASSERT(is_alpha(alpha)); @@ -76,14 +76,14 @@ inline bool is_xdigit(char c) { // Case-insensitive isalnum inline bool is_alnum(char c) { return is_alpha(c) || is_digit(c); } -inline char CharToUpper(char c) { - return static_cast<char>(::toupper(static_cast<unsigned char>(c))); -} - -inline char CharToLower(char c) { - return static_cast<char>(::tolower(static_cast<unsigned char>(c))); -} - +inline char CharToUpper(char c) { + return static_cast<char>(::toupper(static_cast<unsigned char>(c))); +} + +inline char CharToLower(char c) { + return static_cast<char>(::tolower(static_cast<unsigned char>(c))); +} + // @end-locale-independent functions for ASCII character set #ifdef FLATBUFFERS_PREFER_PRINTF @@ -335,9 +335,9 @@ inline bool StringToFloatImpl(T *val, const char *const str) { // - If the converted value falls out of range of corresponding return type, a // range error occurs. In this case value MAX(T)/MIN(T) is returned. template<typename T> inline bool StringToNumber(const char *s, T *val) { - // Assert on `unsigned long` and `signed long` on LP64. - // If it is necessary, it could be solved with flatbuffers::enable_if<B,T>. - static_assert(sizeof(T) < sizeof(int64_t), "unexpected type T"); + // Assert on `unsigned long` and `signed long` on LP64. + // If it is necessary, it could be solved with flatbuffers::enable_if<B,T>. + static_assert(sizeof(T) < sizeof(int64_t), "unexpected type T"); FLATBUFFERS_ASSERT(s && val); int64_t i64; // The errno check isn't needed, will return MAX/MIN on overflow. @@ -461,7 +461,7 @@ std::string StripPath(const std::string &filepath); // Strip the last component of the path + separator. std::string StripFileName(const std::string &filepath); -// Concatenates a path with a filename, regardless of whether the path +// Concatenates a path with a filename, regardless of whether the path // ends in a separator or not. std::string ConCatPathFileName(const std::string &path, const std::string &filename); diff --git a/contrib/libs/flatbuffers/ya.make b/contrib/libs/flatbuffers/ya.make index 9bdff33fba..4af01ae72c 100644 --- a/contrib/libs/flatbuffers/ya.make +++ b/contrib/libs/flatbuffers/ya.make @@ -1,14 +1,14 @@ -# Generated by devtools/yamaker from nixpkgs 28acaac96f0cc203c63a3d50634541feff7fc31c. +# Generated by devtools/yamaker from nixpkgs 28acaac96f0cc203c63a3d50634541feff7fc31c. LIBRARY() OWNER( - eeight + eeight kirillovs g:cpp-contrib ) -VERSION(2.0.0) +VERSION(2.0.0) ORIGINAL_SOURCE(https://github.com/google/flatbuffers/archive/v2.0.0.tar.gz) @@ -19,17 +19,17 @@ LICENSE( LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -ADDINCL( - contrib/libs/flatbuffers/include -) +ADDINCL( + contrib/libs/flatbuffers/include +) NO_COMPILER_WARNINGS() NO_UTIL() -CFLAGS( - -DFLATBUFFERS_LOCALE_INDEPENDENT=1 -) +CFLAGS( + -DFLATBUFFERS_LOCALE_INDEPENDENT=1 +) SRCS( src/idl_gen_text.cpp |