ONE - On-device Neural Engine
Loading...
Searching...
No Matches
flatbuffers::vector_downward Class Reference

#include <flatbuffers.h>

Public Member Functions

 vector_downward (size_t initial_size, Allocator *allocator, bool own_allocator, size_t buffer_minalign)
 
 vector_downward (vector_downward &&other)
 
vector_downwardoperator= (vector_downward &&other)
 
 ~vector_downward ()
 
void reset ()
 
void clear ()
 
void clear_scratch ()
 
void clear_allocator ()
 
void clear_buffer ()
 
uint8_t * release_raw (size_t &allocated_bytes, size_t &offset)
 
DetachedBuffer release ()
 
size_t ensure_space (size_t len)
 
uint8_t * make_space (size_t len)
 
Allocatorget_custom_allocator ()
 
uoffset_t size () const
 
uoffset_t scratch_size () const
 
size_t capacity () const
 
uint8_t * data () const
 
uint8_t * scratch_data () const
 
uint8_t * scratch_end () const
 
uint8_t * data_at (size_t offset) const
 
void push (const uint8_t *bytes, size_t num)
 
template<typename T >
void push_small (const T &little_endian_t)
 
template<typename T >
void scratch_push_small (const T &t)
 
void fill (size_t zero_pad_bytes)
 
void fill_big (size_t zero_pad_bytes)
 
void pop (size_t bytes_to_remove)
 
void scratch_pop (size_t bytes_to_remove)
 
void swap (vector_downward &other)
 
void swap_allocator (vector_downward &other)
 

Detailed Description

Definition at line 875 of file flatbuffers.h.

Constructor & Destructor Documentation

◆ vector_downward() [1/2]

flatbuffers::vector_downward::vector_downward ( size_t  initial_size,
Allocator allocator,
bool  own_allocator,
size_t  buffer_minalign 
)
inlineexplicit

Definition at line 878 of file flatbuffers.h.

880 : allocator_(allocator), own_allocator_(own_allocator), initial_size_(initial_size),
881 buffer_minalign_(buffer_minalign), reserved_(0), buf_(nullptr), cur_(nullptr),
882 scratch_(nullptr)
883 {
884 }

◆ vector_downward() [2/2]

flatbuffers::vector_downward::vector_downward ( vector_downward &&  other)
inline

Definition at line 887 of file flatbuffers.h.

892 : allocator_(other.allocator_), own_allocator_(other.own_allocator_),
893 initial_size_(other.initial_size_), buffer_minalign_(other.buffer_minalign_),
894 reserved_(other.reserved_), buf_(other.buf_), cur_(other.cur_), scratch_(other.scratch_)
895 {
896 // No change in other.allocator_
897 // No change in other.initial_size_
898 // No change in other.buffer_minalign_
899 other.own_allocator_ = false;
900 other.reserved_ = 0;
901 other.buf_ = nullptr;
902 other.cur_ = nullptr;
903 other.scratch_ = nullptr;
904 }

◆ ~vector_downward()

flatbuffers::vector_downward::~vector_downward ( )
inline

Definition at line 918 of file flatbuffers.h.

References clear_allocator(), and clear_buffer().

Member Function Documentation

◆ capacity()

size_t flatbuffers::vector_downward::capacity ( ) const
inline

Definition at line 1022 of file flatbuffers.h.

1022{ return reserved_; }

Referenced by flatbuffers::grpc::MessageBuilder::GetMessage(), and flatbuffers::grpc::MessageBuilder::MessageBuilder().

◆ clear()

void flatbuffers::vector_downward::clear ( )
inline

Definition at line 930 of file flatbuffers.h.

931 {
932 if (buf_)
933 {
934 cur_ = buf_ + reserved_;
935 }
936 else
937 {
938 reserved_ = 0;
939 cur_ = nullptr;
940 }
942 }

References clear_scratch().

Referenced by flatbuffers::FlatBufferBuilder::Clear(), release(), release_raw(), and reset().

◆ clear_allocator()

void flatbuffers::vector_downward::clear_allocator ( )
inline

Definition at line 946 of file flatbuffers.h.

947 {
948 if (own_allocator_ && allocator_)
949 {
950 delete allocator_;
951 }
952 allocator_ = nullptr;
953 own_allocator_ = false;
954 }

Referenced by ~vector_downward().

◆ clear_buffer()

void flatbuffers::vector_downward::clear_buffer ( )
inline

Definition at line 956 of file flatbuffers.h.

957 {
958 if (buf_)
959 Deallocate(allocator_, buf_, reserved_);
960 buf_ = nullptr;
961 }
void Deallocate(Allocator *allocator, uint8_t *p, size_t size)

References flatbuffers::Deallocate().

Referenced by reset(), and ~vector_downward().

◆ clear_scratch()

void flatbuffers::vector_downward::clear_scratch ( )
inline

Definition at line 944 of file flatbuffers.h.

944{ scratch_ = buf_; }

Referenced by clear(), and flatbuffers::FlatBufferBuilder::Finish().

◆ data()

uint8_t * flatbuffers::vector_downward::data ( ) const
inline

◆ data_at()

uint8_t * flatbuffers::vector_downward::data_at ( size_t  offset) const
inline

Definition at line 1042 of file flatbuffers.h.

1042{ return buf_ + reserved_ - offset; }
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540

References offset().

Referenced by flatbuffers::FlatBufferBuilder::CreateUninitializedVector(), and flatbuffers::FlatBufferBuilder::StringOffsetCompare::operator()().

◆ ensure_space()

size_t flatbuffers::vector_downward::ensure_space ( size_t  len)
inline

Definition at line 992 of file flatbuffers.h.

993 {
994 FLATBUFFERS_ASSERT(cur_ >= scratch_ && scratch_ >= buf_);
995 if (len > static_cast<size_t>(cur_ - scratch_))
996 {
997 reallocate(len);
998 }
999 // Beyond this, signed offsets may not have enough range:
1000 // (FlatBuffers > 2GB not supported).
1001 FLATBUFFERS_ASSERT(size() < FLATBUFFERS_MAX_BUFFER_SIZE);
1002 return len;
1003 }

References FLATBUFFERS_ASSERT, and size().

Referenced by make_space(), and scratch_push_small().

◆ fill()

void flatbuffers::vector_downward::fill ( size_t  zero_pad_bytes)
inline

Definition at line 1068 of file flatbuffers.h.

1069 {
1070 make_space(zero_pad_bytes);
1071 for (size_t i = 0; i < zero_pad_bytes; i++)
1072 cur_[i] = 0;
1073 }
uint8_t * make_space(size_t len)

References make_space().

Referenced by flatbuffers::FlatBufferBuilder::CreateString().

◆ fill_big()

void flatbuffers::vector_downward::fill_big ( size_t  zero_pad_bytes)
inline

Definition at line 1077 of file flatbuffers.h.

1077{ memset(make_space(zero_pad_bytes), 0, zero_pad_bytes); }

References make_space().

◆ get_custom_allocator()

Allocator * flatbuffers::vector_downward::get_custom_allocator ( )
inline

Definition at line 1013 of file flatbuffers.h.

1013{ return allocator_; }

◆ make_space()

uint8_t * flatbuffers::vector_downward::make_space ( size_t  len)
inline

Definition at line 1005 of file flatbuffers.h.

1006 {
1007 size_t space = ensure_space(len);
1008 cur_ -= space;
1009 return cur_;
1010 }
size_t ensure_space(size_t len)

References ensure_space().

Referenced by flatbuffers::FlatBufferBuilder::CreateUninitializedVector(), fill(), fill_big(), push(), and push_small().

◆ operator=()

vector_downward & flatbuffers::vector_downward::operator= ( vector_downward &&  other)
inline

Definition at line 908 of file flatbuffers.h.

909 {
910 // Move construct a temporary and swap idiom
911 vector_downward temp(std::move(other));
912 swap(temp);
913 return *this;
914 }
void swap(vector_downward &other)
vector_downward(size_t initial_size, Allocator *allocator, bool own_allocator, size_t buffer_minalign)

References swap().

◆ pop()

void flatbuffers::vector_downward::pop ( size_t  bytes_to_remove)
inline

Definition at line 1079 of file flatbuffers.h.

1079{ cur_ += bytes_to_remove; }

Referenced by flatbuffers::FlatBufferBuilder::CreateSharedString().

◆ push()

void flatbuffers::vector_downward::push ( const uint8_t *  bytes,
size_t  num 
)
inline

Definition at line 1044 of file flatbuffers.h.

1045 {
1046 if (num > 0)
1047 {
1048 memcpy(make_space(num), bytes, num);
1049 }
1050 }

References make_space().

◆ push_small()

template<typename T >
void flatbuffers::vector_downward::push_small ( const T &  little_endian_t)
inline

Definition at line 1053 of file flatbuffers.h.

1054 {
1055 make_space(sizeof(T));
1056 *reinterpret_cast<T *>(cur_) = little_endian_t;
1057 }

References make_space().

Referenced by flatbuffers::FlatBufferBuilder::CreateStruct().

◆ release()

DetachedBuffer flatbuffers::vector_downward::release ( )
inline

Definition at line 978 of file flatbuffers.h.

979 {
980 // allocator ownership (if any) is transferred to DetachedBuffer.
981 DetachedBuffer fb(allocator_, own_allocator_, buf_, reserved_, cur_, size());
982 if (own_allocator_)
983 {
984 allocator_ = nullptr;
985 own_allocator_ = false;
986 }
987 buf_ = nullptr;
988 clear();
989 return fb;
990 }

References clear(), and size().

Referenced by flatbuffers::FlatBufferBuilder::FLATBUFFERS_ATTRIBUTE(), and flatbuffers::FlatBufferBuilder::Release().

◆ release_raw()

uint8_t * flatbuffers::vector_downward::release_raw ( size_t &  allocated_bytes,
size_t &  offset 
)
inline

Definition at line 964 of file flatbuffers.h.

965 {
966 auto *buf = buf_;
967 allocated_bytes = reserved_;
968 offset = static_cast<size_t>(cur_ - buf_);
969
970 // release_raw only relinquishes the buffer ownership.
971 // Does not deallocate or reset the allocator. Destructor will do that.
972 buf_ = nullptr;
973 clear();
974 return buf;
975 }

References clear(), and offset().

Referenced by flatbuffers::FlatBufferBuilder::ReleaseRaw().

◆ reset()

void flatbuffers::vector_downward::reset ( )
inline

Definition at line 924 of file flatbuffers.h.

925 {
926 clear_buffer();
927 clear();
928 }

References clear(), and clear_buffer().

Referenced by flatbuffers::FlatBufferBuilder::Reset().

◆ scratch_data()

uint8_t * flatbuffers::vector_downward::scratch_data ( ) const
inline

Definition at line 1030 of file flatbuffers.h.

1031 {
1032 FLATBUFFERS_ASSERT(buf_);
1033 return buf_;
1034 }

References FLATBUFFERS_ASSERT.

Referenced by flatbuffers::grpc::MessageBuilder::GetMessage(), and flatbuffers::grpc::MessageBuilder::MessageBuilder().

◆ scratch_end()

uint8_t * flatbuffers::vector_downward::scratch_end ( ) const
inline

Definition at line 1036 of file flatbuffers.h.

1037 {
1038 FLATBUFFERS_ASSERT(scratch_);
1039 return scratch_;
1040 }

References FLATBUFFERS_ASSERT.

◆ scratch_pop()

void flatbuffers::vector_downward::scratch_pop ( size_t  bytes_to_remove)
inline

Definition at line 1080 of file flatbuffers.h.

1080{ scratch_ -= bytes_to_remove; }

◆ scratch_push_small()

template<typename T >
void flatbuffers::vector_downward::scratch_push_small ( const T &  t)
inline

Definition at line 1059 of file flatbuffers.h.

1060 {
1061 ensure_space(sizeof(T));
1062 *reinterpret_cast<T *>(scratch_) = t;
1063 scratch_ += sizeof(T);
1064 }

References ensure_space().

◆ scratch_size()

uoffset_t flatbuffers::vector_downward::scratch_size ( ) const
inline

Definition at line 1020 of file flatbuffers.h.

1020{ return static_cast<uoffset_t>(scratch_ - buf_); }

◆ size()

uoffset_t flatbuffers::vector_downward::size ( ) const
inline

Definition at line 1015 of file flatbuffers.h.

1016 {
1017 return static_cast<uoffset_t>(reserved_ - static_cast<size_t>(cur_ - buf_));
1018 }

Referenced by flatbuffers::FlatBufferBuilder::CreateSharedString(), ensure_space(), flatbuffers::FlatBufferBuilder::GetBufferSpan(), flatbuffers::grpc::MessageBuilder::GetMessage(), flatbuffers::FlatBufferBuilder::GetSize(), and release().

◆ swap()

void flatbuffers::vector_downward::swap ( vector_downward other)
inline

Definition at line 1082 of file flatbuffers.h.

1083 {
1084 using std::swap;
1085 swap(allocator_, other.allocator_);
1086 swap(own_allocator_, other.own_allocator_);
1087 swap(initial_size_, other.initial_size_);
1088 swap(buffer_minalign_, other.buffer_minalign_);
1089 swap(reserved_, other.reserved_);
1090 swap(buf_, other.buf_);
1091 swap(cur_, other.cur_);
1092 swap(scratch_, other.scratch_);
1093 }

References swap().

Referenced by operator=(), flatbuffers::FlatBufferBuilder::Swap(), swap(), and swap_allocator().

◆ swap_allocator()

void flatbuffers::vector_downward::swap_allocator ( vector_downward other)
inline

Definition at line 1095 of file flatbuffers.h.

1096 {
1097 using std::swap;
1098 swap(allocator_, other.allocator_);
1099 swap(own_allocator_, other.own_allocator_);
1100 }

References swap().

Referenced by flatbuffers::grpc::MessageBuilder::Swap(), and flatbuffers::FlatBufferBuilder::SwapBufAllocator().


The documentation for this class was generated from the following file: