OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
10 #ifndef FIXEDSIZEARRAY_HPP
11 #define FIXEDSIZEARRAY_HPP
13 #include "../core/alloc_func.hpp"
21 template <
class T, u
int C>
32 static const uint
Tsize =
sizeof(T);
42 inline ArrayHeader&
Hdr()
48 inline const ArrayHeader&
Hdr()
const
90 if ((--
RefCnt()) > 0)
return;
104 for (T *pItem = this->data + this->
Length() - 1; pItem >= this->
data; pItem--) {
FixedSizeArray()
Default constructor.
uint & RefCnt()
return reference to the block reference counter
void Clear()
Clear (destroy) all items.
static const uint HeaderSize
size of header
static const uint Tsize
size of item
T * data
the only member of fixed size array is pointer to the block of C array of items.
FixedSizeArray(const FixedSizeArray< T, C > &src)
Copy constructor.
T & operator[](uint index)
return item by index (non-const version)
bool IsEmpty() const
return true if array is empty
const ArrayHeader & Hdr() const
return reference to the array header (const)
uint & SizeRef()
return reference to number of used items
T * Append()
add (allocate), but don't construct item
bool IsFull() const
return true if array is full
fixed size array Upon construction it preallocates fixed size block of memory for all items,...
~FixedSizeArray()
destroy remaining items and free the memory block
uint Length() const
return number of used items
ArrayHeader & Hdr()
return reference to the array header (non-const)
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
T * AppendC()
add and construct item using default constructor