24 template <
typename T, u
int64 S = 32>
43 FArray(std::initializer_list<T> l);
49 template <u
int64 S2>
bool operator==(
const FArray<T,S2> &f)
const;
60 bool empty()
const {
return end_ == begin_; }
63 T *
data() {
return begin_; }
66 const T *
data()
const {
return begin_; }
70 const T &
front()
const {
return *begin_; }
72 T &
back() {
return *(end_ - 1); }
74 const T &
back()
const {
return *(end_ - 1); }
82 void push_back(
const T &t) { checkAllocated(
size() + 1);
new(end_) T(t); ++end_; ++size_; }
103 template <
class C>
void append(
const C &in);
163 T
value(
int i,
const T &t = T())
const {
if (i < 0)
return t;
if (to<size_type>(i) >=
size())
return t;
return at(i); }
167 T
value(uint32 i,
const T &t = T())
const {
if (to<size_type>(i) >=
size())
return t;
return at(i); }
171 T
value(uint64 i,
const T &t = T())
const {
if (to<size_type>(i) >=
size())
return t;
return at(i); }
177 std::array<T, S> arr_;
178 char buffer[
sizeof(T)*S];
180 T *begin_ =
reinterpret_cast<T *
>(buffer);
190 class FArray<T, 0> :
public std::vector<T> {
192 using std::vector<T>::vector;
201 template <
typename T,u
int64 S>
205 for (T *b = begin_; b < end_; ++b)
210 template <
typename T,u
int64 S>
212 for (
auto it = l.begin(); it != l.end(); ++it)
216 template <
typename T,u
int64 S>
218 return operator=<S>(f);
229 template <
typename T,u
int64 S>
232 if (size()!=f.
size())
return false;
233 for (uint64 i=0;i<size();++i) {
234 if (
operator[](i)!=f[i])
240 template <
typename T,u
int64 S>
244 checkAllocated(f.
size());
245 end_ = begin_ + f.
size();
248 for (
auto br = f.
begin(); bl < end(); ++bl, ++br)
253 template <
typename T,u
int64 S>
256 if (at(i) == t)
return i;
261 template <
typename T,u
int64 S>
263 checkAllocated(size() + n);
270 template <
typename T,u
int64 S>
272 if (size() == i)
return;
276 for (T *p = e - 1; p >= end_; --p)
285 for (T *p = begin_ + s; p < end_; ++p)
289 template <
typename T,u
int64 S>
291 i = std::min(size(), i);
292 if (i + 1 > size()) push_back(t);
295 for (
iterator p = end_ - 2; p > begin_ + i; --p)
302 template <
typename T,u
int64 S>
311 template <
typename T,u
int64 S>
314 for (
auto i = in.begin(); i != in.end(); ++i)
318 template <
typename T,u
int64 S>
321 i = std::min(size(), i);
322 if (i + 1 > size()) push_back(t);
325 for (
iterator p = end_ - 2; p > begin_ + i; --p)
332 template <
typename T,u
int64 S>
334 if (i >= size())
return false;
335 for (
iterator it = begin_ + i; it + 1 < end_; ++it)
341 template <
typename T,u
int64 S>
354 template <
typename T,u
int64 S>
357 if (!std::is_trivially_copyable<T>::value)
358 for (T *b = begin_; b < end_; ++b)
364 template <
typename T,u
int64 S>
367 if (begin_ !=
reinterpret_cast<T *
>(arr_.data()))
369 end_ = begin_ =
reinterpret_cast<T *
>(arr_.data());
373 template <
typename T,u
int64 S>
375 static const size_type max_increase = 1000000;
376 if (target <= allocated_)
return;
377 size_type newsize = std::max<size_type>(allocated_, 8);
378 while (newsize < target)
379 newsize += to<size_type>(std::min(max_increase, newsize));
380 changeAllocated(newsize);
383 template <
typename T,u
int64 S>
385 size_type old_size = size();
386 assert(old_size <= newSize);
387 T *newBegin =
reinterpret_cast<T *
>(arr_.data());
390 newBegin =
reinterpret_cast<T *
>(itasca::memory::imalloc(newSize *
sizeof(T), __FILE__, __LINE__));
392 newBegin =
reinterpret_cast<T *
>(std::malloc(newSize *
sizeof(T)));
395 for (T *tr = begin_; tr < end_; ++tl, ++tr) {
396 new(tl) T(std::move(*tr));
399 if (begin_ !=
reinterpret_cast<T *
>(arr_.data()))
402 end_ = begin_ + old_size;
403 allocated_ = newSize;
Combines base interface with Qt – allows Qt to interact with other Base types transparently.
An array class that attempts to minimize unnecessary heap access.
Definition: farray.h:25
T * data()
Definition: farray.h:63
void push_back(const T &t)
Adds a new element to the end of the array, increasing the array size by one.
Definition: farray.h:82
bool empty() const
Definition: farray.h:60
size_type stackSize() const
Returns the size of the array pre-allocated on the stack.
Definition: farray.h:55
const T & back() const
Definition: farray.h:74
T value_type
Typedef to assist in STL compatibility.
Definition: farray.h:28
FArray()
Default constructor - the array size is zero.
Definition: farray.h:33
T & back()
Definition: farray.h:72
iterator begin()
Definition: farray.h:128
T & operator[](size_type i)
Definition: farray.h:155
T & front()
Definition: farray.h:68
FArray(const FArray< T, S2 > &f)
Copy constructor, valid for FArrays of the same data type but different stack lengths.
Definition: farray.h:40
const_iterator constEnd() const
Definition: farray.h:143
uint64 size_type
Typedef to assist in STL compatibility.
Definition: farray.h:27
const T & front() const
Definition: farray.h:70
void clip()
Definition: farray.h:123
T value(uint64 i, const T &t=T()) const
Definition: farray.h:171
const_iterator begin() const
Definition: farray.h:131
FArray(const FArray< T, S > &f)
Specialized copy constructor, for the special case of when the stack lengths are the same.
Definition: farray.h:42
const T * data() const
Definition: farray.h:66
~FArray()
Destructor.
Definition: farray.h:45
const T & operator[](size_type i) const
Definition: farray.h:159
const_iterator end() const
Definition: farray.h:140
size_type allocated() const
Definition: farray.h:58
iterator end()
Definition: farray.h:137
void pop_back()
Removes the last element in the array. The results are undefined if the array is of zero length.
Definition: farray.h:91
T value(int i, const T &t=T()) const
Definition: farray.h:163
T value(uint32 i, const T &t=T()) const
Definition: farray.h:167
const_iterator constBegin() const
Definition: farray.h:134
const T & at(size_type i) const
Definition: farray.h:151
T * iterator
Typedef to assist in STL compatibility.
Definition: farray.h:29
size_type size() const
Definition: farray.h:53
const T * const_iterator
Typedef to assist in STL compatibility.
Definition: farray.h:30
T * emplace_back()
Definition: farray.h:86
T & at(size_type i)
Definition: farray.h:147
debug checked shorthand for std::numeric_limits<T>::
Definition: limit.h:25
bool remove(size_type i)
Definition: farray.h:333
iterator insert(iterator it, const T &t)
Definition: farray.h:319
const FArray< T, S > & operator=(const FArray< T, S2 > &f)
Assignment operator, valid for FArrays of the same data type but different stack lengths.
Definition: farray.h:242
iterator insert(size_type i, const T &t)
Definition: farray.h:290
void resize(size_type i, const T &t=T())
Definition: farray.h:271
void append(const C &in)
Appends the contents of one FArray onto another.
Definition: farray.h:313
size_type find(const T &t) const
Definition: farray.h:254
void reset()
Definition: farray.h:365
void clear()
Definition: farray.h:355
void put(size_type i, const T &t)
Adds a value to the array, first making certain it is big enough to hold it.
Definition: farray.h:303
FArray(size_type s, const T &t=T())
Definition: farray.h:202
size_type removeAll(const T &t)
Definition: farray.h:342
T * emplace_n_back(uint64 n)
Definition: farray.h:262