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

#include <vector_downward.h>

Public Member Functions

 vector_downward (size_t initial_size, Allocator *allocator, bool own_allocator, size_t buffer_minalign, const SizeT max_size=FLATBUFFERS_MAX_BUFFER_SIZE)
 
 vector_downward (vector_downward &&other) noexcept
 
vector_downwardoperator= (vector_downward &&other) noexcept
 
 ~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 ()
 
size_t offset () const
 
SizeT size () const
 
SizeT unused_buffer_size () const
 
SizeT 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

template<typename SizeT = uoffset_t>
class flatbuffers::vector_downward< SizeT >

Definition at line 35 of file vector_downward.h.

Constructor & Destructor Documentation

◆ vector_downward() [1/2]

template<typename SizeT = uoffset_t>
flatbuffers::vector_downward< SizeT >::vector_downward ( size_t  initial_size,
Allocator allocator,
bool  own_allocator,
size_t  buffer_minalign,
const SizeT  max_size = FLATBUFFERS_MAX_BUFFER_SIZE 
)
inlineexplicit

Definition at line 37 of file vector_downward.h.

40 : allocator_(allocator),
41 own_allocator_(own_allocator),
42 initial_size_(initial_size),
43 max_size_(max_size),
44 buffer_minalign_(buffer_minalign),
45 reserved_(0),
46 size_(0),
47 buf_(nullptr),
48 cur_(nullptr),
49 scratch_(nullptr) {}
src_tensor allocator() -> init(p.src_info< NHWC >())

◆ vector_downward() [2/2]

template<typename SizeT = uoffset_t>
flatbuffers::vector_downward< SizeT >::vector_downward ( vector_downward< SizeT > &&  other)
inlinenoexcept

Definition at line 51 of file vector_downward.h.

53 : allocator_(other.allocator_),
54 own_allocator_(other.own_allocator_),
55 initial_size_(other.initial_size_),
56 max_size_(other.max_size_),
57 buffer_minalign_(other.buffer_minalign_),
58 reserved_(other.reserved_),
59 size_(other.size_),
60 buf_(other.buf_),
61 cur_(other.cur_),
62 scratch_(other.scratch_) {
63 // No change in other.allocator_
64 // No change in other.initial_size_
65 // No change in other.buffer_minalign_
66 other.own_allocator_ = false;
67 other.reserved_ = 0;
68 other.buf_ = nullptr;
69 other.cur_ = nullptr;
70 other.scratch_ = nullptr;
71 }

◆ ~vector_downward()

Member Function Documentation

◆ capacity()

template<typename SizeT = uoffset_t>
size_t flatbuffers::vector_downward< SizeT >::capacity ( ) const
inline

◆ clear()

template<typename SizeT = uoffset_t>
void flatbuffers::vector_downward< SizeT >::clear ( )
inline

◆ clear_allocator()

template<typename SizeT = uoffset_t>
void flatbuffers::vector_downward< SizeT >::clear_allocator ( )
inline

Definition at line 103 of file vector_downward.h.

103 {
104 if (own_allocator_ && allocator_) { delete allocator_; }
105 allocator_ = nullptr;
106 own_allocator_ = false;
107 }

Referenced by flatbuffers::vector_downward< SizeT >::~vector_downward().

◆ clear_buffer()

template<typename SizeT = uoffset_t>
void flatbuffers::vector_downward< SizeT >::clear_buffer ( )
inline

Definition at line 109 of file vector_downward.h.

109 {
110 if (buf_) Deallocate(allocator_, buf_, reserved_);
111 buf_ = nullptr;
112 }
void Deallocate(Allocator *allocator, uint8_t *p, size_t size)

References flatbuffers::Deallocate().

Referenced by flatbuffers::vector_downward< SizeT >::reset(), and flatbuffers::vector_downward< SizeT >::~vector_downward().

◆ clear_scratch()

template<typename SizeT = uoffset_t>
void flatbuffers::vector_downward< SizeT >::clear_scratch ( )
inline

◆ data()

◆ data_at()

template<typename SizeT = uoffset_t>
uint8_t * flatbuffers::vector_downward< SizeT >::data_at ( size_t  offset) const
inline

◆ ensure_space()

template<typename SizeT = uoffset_t>
size_t flatbuffers::vector_downward< SizeT >::ensure_space ( size_t  len)
inline

Definition at line 141 of file vector_downward.h.

141 {
142 FLATBUFFERS_ASSERT(cur_ >= scratch_ && scratch_ >= buf_);
143 // If the length is larger than the unused part of the buffer, we need to
144 // grow.
145 if (len > unused_buffer_size()) { reallocate(len); }
146 FLATBUFFERS_ASSERT(size() < max_size_);
147 return len;
148 }

References FLATBUFFERS_ASSERT, flatbuffers::vector_downward< SizeT >::size(), and flatbuffers::vector_downward< SizeT >::unused_buffer_size().

Referenced by flatbuffers::FlatBufferBuilderImpl< Is64Aware >::CreateVectorOfStrings(), flatbuffers::vector_downward< SizeT >::make_space(), and flatbuffers::vector_downward< SizeT >::scratch_push_small().

◆ fill()

template<typename SizeT = uoffset_t>
void flatbuffers::vector_downward< SizeT >::fill ( size_t  zero_pad_bytes)
inline

Definition at line 213 of file vector_downward.h.

213 {
214 make_space(zero_pad_bytes);
215 for (size_t i = 0; i < zero_pad_bytes; i++) cur_[i] = 0;
216 }
uint8_t * make_space(size_t len)

References flatbuffers::vector_downward< SizeT >::make_space().

◆ fill_big()

template<typename SizeT = uoffset_t>
void flatbuffers::vector_downward< SizeT >::fill_big ( size_t  zero_pad_bytes)
inline

Definition at line 220 of file vector_downward.h.

220 {
221 memset(make_space(zero_pad_bytes), 0, zero_pad_bytes);
222 }

References flatbuffers::vector_downward< SizeT >::make_space().

◆ get_custom_allocator()

template<typename SizeT = uoffset_t>
Allocator * flatbuffers::vector_downward< SizeT >::get_custom_allocator ( )
inline

Definition at line 160 of file vector_downward.h.

160{ return allocator_; }

◆ make_space()

template<typename SizeT = uoffset_t>
uint8_t * flatbuffers::vector_downward< SizeT >::make_space ( size_t  len)
inline

◆ offset()

template<typename SizeT = uoffset_t>
size_t flatbuffers::vector_downward< SizeT >::offset ( ) const
inline

Definition at line 163 of file vector_downward.h.

163{ return cur_ - buf_; }

Referenced by flatbuffers::vector_downward< SizeT >::data_at(), and flatbuffers::vector_downward< SizeT >::release_raw().

◆ operator=()

template<typename SizeT = uoffset_t>
vector_downward & flatbuffers::vector_downward< SizeT >::operator= ( vector_downward< SizeT > &&  other)
inlinenoexcept

Definition at line 73 of file vector_downward.h.

73 {
74 // Move construct a temporary and swap idiom
75 vector_downward temp(std::move(other));
76 swap(temp);
77 return *this;
78 }
vector_downward(size_t initial_size, Allocator *allocator, bool own_allocator, size_t buffer_minalign, const SizeT max_size=FLATBUFFERS_MAX_BUFFER_SIZE)
void swap(vector_downward &other)

References flatbuffers::vector_downward< SizeT >::swap().

◆ pop()

template<typename SizeT = uoffset_t>
void flatbuffers::vector_downward< SizeT >::pop ( size_t  bytes_to_remove)
inline

Definition at line 224 of file vector_downward.h.

224 {
225 cur_ += bytes_to_remove;
226 size_ -= static_cast<SizeT>(bytes_to_remove);
227 }

Referenced by flatbuffers::FlatBufferBuilderImpl< Is64Aware >::CreateSharedString().

◆ push()

template<typename SizeT = uoffset_t>
void flatbuffers::vector_downward< SizeT >::push ( const uint8_t *  bytes,
size_t  num 
)
inline

Definition at line 195 of file vector_downward.h.

195 {
196 if (num > 0) { memcpy(make_space(num), bytes, num); }
197 }

References flatbuffers::vector_downward< SizeT >::make_space().

◆ push_small()

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

Definition at line 200 of file vector_downward.h.

200 {
201 make_space(sizeof(T));
202 *reinterpret_cast<T *>(cur_) = little_endian_t;
203 }

References flatbuffers::vector_downward< SizeT >::make_space().

Referenced by flatbuffers::FlatBufferBuilderImpl< Is64Aware >::CreateStruct().

◆ release()

template<typename SizeT = uoffset_t>
DetachedBuffer flatbuffers::vector_downward< SizeT >::release ( )
inline

Definition at line 128 of file vector_downward.h.

128 {
129 // allocator ownership (if any) is transferred to DetachedBuffer.
130 DetachedBuffer fb(allocator_, own_allocator_, buf_, reserved_, cur_,
131 size());
132 if (own_allocator_) {
133 allocator_ = nullptr;
134 own_allocator_ = false;
135 }
136 buf_ = nullptr;
137 clear();
138 return fb;
139 }

References flatbuffers::vector_downward< SizeT >::clear(), and flatbuffers::vector_downward< SizeT >::size().

Referenced by flatbuffers::FlatBufferBuilderImpl< Is64Aware >::FLATBUFFERS_ATTRIBUTE(), and flatbuffers::FlatBufferBuilderImpl< Is64Aware >::Release().

◆ release_raw()

template<typename SizeT = uoffset_t>
uint8_t * flatbuffers::vector_downward< SizeT >::release_raw ( size_t &  allocated_bytes,
size_t &  offset 
)
inline

Definition at line 115 of file vector_downward.h.

115 {
116 auto *buf = buf_;
117 allocated_bytes = reserved_;
119
120 // release_raw only relinquishes the buffer ownership.
121 // Does not deallocate or reset the allocator. Destructor will do that.
122 buf_ = nullptr;
123 clear();
124 return buf;
125 }

References flatbuffers::vector_downward< SizeT >::clear(), and flatbuffers::vector_downward< SizeT >::offset().

Referenced by flatbuffers::FlatBufferBuilderImpl< Is64Aware >::ReleaseRaw().

◆ reset()

template<typename SizeT = uoffset_t>
void flatbuffers::vector_downward< SizeT >::reset ( )
inline

◆ scratch_data()

template<typename SizeT = uoffset_t>
uint8_t * flatbuffers::vector_downward< SizeT >::scratch_data ( ) const
inline

Definition at line 183 of file vector_downward.h.

183 {
184 FLATBUFFERS_ASSERT(buf_);
185 return buf_;
186 }

References FLATBUFFERS_ASSERT.

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

◆ scratch_end()

template<typename SizeT = uoffset_t>
uint8_t * flatbuffers::vector_downward< SizeT >::scratch_end ( ) const
inline

Definition at line 188 of file vector_downward.h.

188 {
189 FLATBUFFERS_ASSERT(scratch_);
190 return scratch_;
191 }

References FLATBUFFERS_ASSERT.

Referenced by flatbuffers::FlatBufferBuilderImpl< Is64Aware >::CreateVectorOfStrings().

◆ scratch_pop()

template<typename SizeT = uoffset_t>
void flatbuffers::vector_downward< SizeT >::scratch_pop ( size_t  bytes_to_remove)
inline

Definition at line 229 of file vector_downward.h.

229{ scratch_ -= bytes_to_remove; }

Referenced by flatbuffers::FlatBufferBuilderImpl< Is64Aware >::CreateVectorOfStrings().

◆ scratch_push_small()

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

Definition at line 205 of file vector_downward.h.

205 {
206 ensure_space(sizeof(T));
207 *reinterpret_cast<T *>(scratch_) = t;
208 scratch_ += sizeof(T);
209 }

References flatbuffers::vector_downward< SizeT >::ensure_space().

Referenced by flatbuffers::FlatBufferBuilderImpl< Is64Aware >::CreateVectorOfStrings().

◆ scratch_size()

template<typename SizeT = uoffset_t>
SizeT flatbuffers::vector_downward< SizeT >::scratch_size ( ) const
inline

Definition at line 174 of file vector_downward.h.

174{ return static_cast<SizeT>(scratch_ - buf_); }

◆ size()

◆ swap()

template<typename SizeT = uoffset_t>
void flatbuffers::vector_downward< SizeT >::swap ( vector_downward< SizeT > &  other)
inline

Definition at line 231 of file vector_downward.h.

231 {
232 using std::swap;
233 swap(allocator_, other.allocator_);
234 swap(own_allocator_, other.own_allocator_);
235 swap(initial_size_, other.initial_size_);
236 swap(buffer_minalign_, other.buffer_minalign_);
237 swap(reserved_, other.reserved_);
238 swap(size_, other.size_);
239 swap(max_size_, other.max_size_);
240 swap(buf_, other.buf_);
241 swap(cur_, other.cur_);
242 swap(scratch_, other.scratch_);
243 }

References flatbuffers::vector_downward< SizeT >::swap().

Referenced by flatbuffers::vector_downward< SizeT >::operator=(), flatbuffers::FlatBufferBuilderImpl< Is64Aware >::Swap(), flatbuffers::vector_downward< SizeT >::swap(), and flatbuffers::vector_downward< SizeT >::swap_allocator().

◆ swap_allocator()

template<typename SizeT = uoffset_t>
void flatbuffers::vector_downward< SizeT >::swap_allocator ( vector_downward< SizeT > &  other)
inline

Definition at line 245 of file vector_downward.h.

245 {
246 using std::swap;
247 swap(allocator_, other.allocator_);
248 swap(own_allocator_, other.own_allocator_);
249 }

References flatbuffers::vector_downward< SizeT >::swap().

Referenced by flatbuffers::grpc::MessageBuilder::Swap(), and flatbuffers::FlatBufferBuilderImpl< Is64Aware >::SwapBufAllocator().

◆ unused_buffer_size()

template<typename SizeT = uoffset_t>
SizeT flatbuffers::vector_downward< SizeT >::unused_buffer_size ( ) const
inline

Definition at line 169 of file vector_downward.h.

169 {
170 return static_cast<SizeT>(cur_ - scratch_);
171 }

Referenced by flatbuffers::vector_downward< SizeT >::ensure_space().


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