#include <cel_memory.h>
Public Member Functions | |
SimpleArray (size_t inSize=0, size_t inReserve=AUTO_SIZE, MemoryAllocator *inAllocator=NULL, size_t inAllocationUnit=0) | |
SimpleArray (const SimpleArray &inSa) | |
~SimpleArray () | |
void | init (size_t inSize=0, size_t inReserve=0, MemoryAllocator *inAllocator=NULL, size_t inAllocationUnit=0) |
SimpleArray & | operator= (const SimpleArray &inSa) |
void | strictCleanup (bool doIt=true) |
void | setAllocationUnit (size_t inAllocationUnit) |
size_t | getAllocationUnit () |
MemoryAllocator * | getAllocator () const |
T * | getPtr () |
const T * | getPtr () const |
size_t | getSize () const |
size_t | getReservedSize () const |
bool | isValid () const |
T & | operator[] (size_t inPos) |
const T & | operator[] (size_t inPos) const |
void | allocate (size_t inSize, size_t inReserve=AUTO_SIZE) |
void | reserve (size_t inSize) |
void | reallocate (size_t inSize) |
void | resize (size_t inSize) |
void | compact () |
void | free () |
void | clear () |
void | remove (size_t inPos, size_t inCount) |
void | insertEmptyElementsAt (size_t inPos, size_t inCount) |
T & | insertAt (size_t inIndex, const T &inElement) |
T & | insert (const T *it, const T &inElement) |
void | insert (const T *it, size_t inCount, const T *inElements) |
void | insertAt (size_t inPos, size_t inCount, const T *inElements) |
void | insertAt (size_t inPos, const SimpleArray &inElements) |
void | prepend (size_t inCount, const T *inElements) |
void | prepend (const SimpleArray &inElements) |
void | append (size_t inCount, const T *inElements) |
void | append (const SimpleArray &inElements) |
void | duplicate (const SimpleArray &inSa, bool inNeedCompaction=false) |
void | duplicate (const T *inBuffer, size_t inSize) |
void | duplicate (const T *inBuffer, size_t inSize, Endian inEndian) |
void | fill (const T &t) |
template<typename U > | |
void | fill (const U &u) |
void | zeroClear () |
int | indexOf (const T &t) const |
template<typename U > | |
int | indexOf (const U &u) const |
void | swap (SimpleArray &inSa) |
void | push_back (const T &t) |
template<typename U > | |
void | push_back (const U &t) |
T | pop_back () |
void | push_front (const T &t) |
template<typename U > | |
void | push_front (const U &t) |
T | pop_front () |
T * | begin () |
T * | end () |
T * | last () |
const T * | begin () const |
const T * | end () const |
const T * | last () const |
T & | front () |
const T & | front () const |
T & | back () |
const T & | back () const |
SimpleArray is a simplified substitution to std::vector
. This class does not need T
(const T&
t
) type constructor but T()
.
The second template parameter copyPolicy is one of the CopyPolicy enumeration and it specifies how to copy the instance if needed. The default for this value is DataTraits::copyPolicy for T.
If copyPolicy is byConstructor, SimpleArray copies the instance in the usual way, using copy-constuctor. Although this scheme is normal and simple enough, it may down the performance of array operations if the T
is simple types such as int, long, ... In these cases, copyPolicy should be changed into byMemcpy. With byMemcpy , copy operations are done with std::memcpy
and it may increases the performance of the array operations. byMemcpy is default for the type like int, long ... (types which are called POD).
Another option, named noCopy is to deal with the structs/classes that do not have copy-constructor, with such data, SimpleArray could not resize the array and it only can allocate and free.
Although SimpleArray class itself is thread-safe, you should synchronize the operations if an instance is used between threads.
|
inlineexplicit |
This constructor initializes the SimpleArray instance by the specified size; it does almost same as init method.
inSize | Specifies the size of the array in number of entries. |
inReserve | Specifies the reservation size of the array in number of entries. The reservation size is a parameter that controls relocation of the array. Although the larger reservation size assures you of the better speed performance of array resizing until the size surpasses the reservation size, it firstly request the reservation size of memory to the operating system. |
inAllocator | Specifies the MemoryAllocator instance that is used to allocate/deallocate memory blocks. It can be NULL and then SimpleArray uses the default allocator. |
inAllocationUnit | Specifies the unit size for allocation. For more information, see setAllocationUnit. |
|
inline |
This constructor initializes the SimpleArray instance with the data copied from the other instance.
inSa | An array to be duplicated. This constructor really copies the memory block held by the instance. |
|
inline |
Deletes the array.
|
inline |
This method allocates the array.
This method firstly frees all the contents on the array and renew the array itself; if you want to keep the contents during the reconstruction of the array, use reallocate or resize.
inSize | Specifies the size of the array in number of entries. |
inReserve | Specifies the reservation size of the array in number of entries. The reservation size is a parameter that controls relocation of the array. Although the larger reservation size assures you of the better speed performance of array resizing until the size surpasses the reservation size, it firstly request the reservation size of memory to the operating system. |
Referenced by Celartem::DjVu::PackedBitmap::allocate(), Celartem::DataArray< T >::allocate(), Celartem::DataArray< T >::deserialize(), Celartem::SimpleArray< AutoPtr< Bookmark > >::duplicate(), Celartem::SimpleArray< AutoPtr< Bookmark > >::init(), and Celartem::SimpleArray< AutoPtr< Bookmark > >::SimpleArray().
|
inline |
This method inserts the specified number of elements to the end of the array.
inCount | The number of the elements in inElements. |
inElements | The elements to insert. |
|
inline |
This method inserts the specified number of elements to the end of the array.
inElements | The elements to insert. |
|
inline |
This method is for the compatibility with STL algorithms.
array
[getSize() - 1] .
|
inline |
This method is for the compatibility with STL algorithms.
array
[getSize() - 1] .
|
inline |
This method is for the compatibility with STL algorithms.
&array
[0] . Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::front().
|
inline |
This method is for the compatibility with STL algorithms.
&array
[0] .
|
inline |
This method release the memory.
This is just an alias of free method.
|
inline |
This method reduces memory consumption by deallocating the unused reserved area.
Please note that compaction actually moves the location of the array and it may take relatively long time.
Referenced by Celartem::DjVu::MemoryData::compact().
|
inline |
This method duplicates the specified array.
inSa | An array to be duplicated. |
inNeedCompaction | Whether compaction (removing reserved area) is needed or not. |
Referenced by Celartem::DataArray< T >::duplicate(), Celartem::SimpleArray< AutoPtr< Bookmark > >::operator=(), and Celartem::SimpleArray< AutoPtr< Bookmark > >::SimpleArray().
|
inline |
This method duplicates the specified array.
inBuffer | An array to be duplicated. |
inSize | The size of the array. |
|
inline |
This method duplicates the specified array.
inBuffer | An array to be duplicated. |
inSize | The size of the array. |
inEndian | The endianness of the specified buffer. |
|
inline |
This method is for the compatibility with STL algorithms.
&array
[array.getSize()] . Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::remove().
|
inline |
This method is for the compatibility with STL algorithms.
&array
[array.getSize()] .
|
inline |
This method is a general version of fill function; fill(0)
fills all array with 0.
t | The value to fill with. |
Referenced by Celartem::DataArray< T >::fill().
|
inline |
This method is a general version of fill function; fill(0)
fills all array with 0.
t | The value to fill with. |
|
inline |
This method releases the memory.
Please note that since this method really deallocates the memory block associated with this SimpleArray instance, it does not keep the reservation size after the call. If you want to preserve the allocated memory for it, use reallocate (0) rather than this method.
Please note that this method keeps the current memory allocation unit. To revert the value to the default, use setAllocationUnit method.
Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::allocate(), Celartem::SimpleArray< AutoPtr< Bookmark > >::clear(), Celartem::SimpleArray< AutoPtr< Bookmark > >::compact(), Celartem::SimpleArray< AutoPtr< Bookmark > >::duplicate(), Celartem::DataArray< T >::free(), Celartem::DjVu::IFF::Layout::init(), Celartem::SimpleArray< AutoPtr< Bookmark > >::init(), Celartem::SimpleArray< AutoPtr< Bookmark > >::insertEmptyElementsAt(), and Celartem::SimpleArray< AutoPtr< Bookmark > >::~SimpleArray().
|
inline |
This method is for the compatibility with STL algorithms.
array
[0] .
|
inline |
This method is for the compatibility with STL algorithms.
array
[0] .
|
inline |
This method is to obtain the current memory allocation unit.
|
inline |
This method is to get MemoryAllocator instance used within the instance.
Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::free(), and Celartem::SimpleArray< AutoPtr< Bookmark > >::getReservedSize().
|
inline |
This method returns raw pointer to the array.
Referenced by Celartem::DataArray< T >::getPtr(), Celartem::DjVu::MemoryData::getRawPtr(), and Celartem::DataArray< T >::getVoidPtr().
|
inline |
This method returns const raw pointer to the array.
|
inline |
This method returns the reserved size of array in number of entries.
Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::duplicate(), Celartem::SimpleArray< AutoPtr< Bookmark > >::insertEmptyElementsAt(), Celartem::SimpleArray< AutoPtr< Bookmark > >::reallocate(), and Celartem::SimpleArray< AutoPtr< Bookmark > >::swap().
|
inline |
This method returns the size of array in number of entries.
Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::append(), Celartem::DataArray< T >::getSize(), Celartem::DjVu::MemoryData::getSize(), Celartem::SimpleArray< AutoPtr< Bookmark > >::indexOf(), Celartem::SimpleArray< AutoPtr< Bookmark > >::insertAt(), Celartem::SimpleArray< AutoPtr< Bookmark > >::pop_back(), Celartem::SimpleArray< AutoPtr< Bookmark > >::push_back(), and Celartem::DataArray< T >::serialize().
|
inline |
This method returns the index of the specified item.
|
inline |
This method returns the index of the specified item.
|
inline |
This method initializes the SimpleArray instance by the specified size. No other method can replace the allocator except the constructor.
inSize | Specifies the size of the array in number of entries. |
inReserve | Specifies the reservation size of the array in number of entries. The reservation size is a parameter that controls relocation of the array. Although the larger reservation size assures you of the better speed performance of array resizing until the size surpasses the reservation size, it firstly request the reservation size of memory to the operating system. |
inAllocator | Specifies the MemoryAllocator instance that is used to allocate/deallocate memory blocks. It can be NULL and then SimpleArray uses the default allocator. |
inAllocationUnit | Specifies the unit size for allocation. For more information, see setAllocationUnit. |
|
inline |
This method inserts the specified number of elements to the specified position.
it | It indicates the position on which new elements are inserted. |
inElement | The element to insert. |
|
inline |
This method inserts the specified number of elements to the specified position.
it | It indicates the position on which new elements are inserted. |
inCount | The number of the elements in inElements. |
inElements | The elements to insert. |
|
inline |
This method inserts the specified number of elements to the specified position.
inIndex | It indicates the position on which new elements are inserted. |
inElement | The element to insert. |
Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::append(), Celartem::SimpleArray< AutoPtr< Bookmark > >::insert(), Celartem::SimpleArray< AutoPtr< Bookmark > >::insertAt(), Celartem::SimpleArray< AutoPtr< Bookmark > >::prepend(), and Celartem::SimpleArray< AutoPtr< Bookmark > >::push_front().
|
inline |
This method inserts the specified number of elements to the specified position.
inPos | It indicates the position on which new elements are inserted. |
inCount | The number of the elements in inElements. |
inElements | The elements to insert. |
|
inline |
This method inserts the specified number of elements to the specified position.
inPos | It indicates the position on which new elements are inserted. |
inElements | The elements to insert. |
|
inline |
This method inserts the specified number of elements to the specified position.
inPos | It indicates the position on which new elements are inserted. |
inCount | The number of the new elements. |
Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::insert(), and Celartem::SimpleArray< AutoPtr< Bookmark > >::insertAt().
|
inline |
This method checks whether the array is valid or not.
true
if the array is valid, otherwise false
. Referenced by Celartem::DataArray< T >::isValid().
|
inline |
This method is for the compatibility with STL algorithms.
&array
[array.getSize() - 1] . Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::back().
|
inline |
This method is for the compatibility with STL algorithms.
&array
[array.getSize() - 1] .
|
inline |
This method copies the specified instance.
inSa | An array to be duplicated. This constructor really copies the memory block held by the instance. |
|
inline |
This method provides the array interface.
inPos | Index to an entry. |
|
inline |
This method provides the array interface (for read).
inPos | Index to an entry. |
|
inline |
This method is almost identical to vector::pop_back
.
Referenced by Celartem::DataArray< T >::pop_back().
|
inline |
This method is almost identical to deque::pop_front
.
Please note that this method is much slower than pop_back.
|
inline |
This method inserts the specified number of elements to the beginning of the array.
inCount | The number of the elements in inElements. |
inElements | The elements to insert. |
|
inline |
This method inserts the specified number of elements to the beginning of the array.
inElements | The elements to insert. |
|
inline |
This method is almost identical to vector::push_back
.
t | Value to add. |
Referenced by Celartem::DataArray< T >::push_back(), and Celartem::SimpleArray< AutoPtr< Bookmark > >::push_back().
|
inline |
This method is almost identical to vector::push_back
.
t | Value to add. |
|
inline |
This method is almost identical to deque::push_front
.
t | Value to add. |
Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::push_front().
|
inline |
This method is almost identical to deque::push_front
.
t | Value to add. |
|
inline |
This method reallocates the array. This method keeps the contents on the array during the reconstruction of the array and it is slower than allocate method; if you don't want to keep the contents, use allocate instead.
resize is just an alias of this method and the behavior is identical to this method.
inSize | Specifies the new size of the array in number of entries. |
Referenced by Celartem::DataArray< T >::resize(), and Celartem::SimpleArray< AutoPtr< Bookmark > >::resize().
|
inline |
This method removes elements of the specified range and moves the elements after them toward the front of the array.
inPos | The index of the first element to remove. |
inCount | The number of elements to remove. |
|
inline |
This method changes the reservation size of the array.
inSize | Specifies the reservation size of the array in number of entries. The reservation size is a parameter that controls relocation of the array. Although the larger reservation size assures you of the better speed performance of array resizing until the size surpasses the reservation size, it firstly request the reservation size of memory to the operating system. |
Referenced by Celartem::DataArray< T >::reserve().
|
inline |
This method reallocates the array. This method is identical to reallocate method. See reallocate for more information.
This method is provided for the compatibility with std::vector
.
inSize | Specifies the new size of the array in number of entries. |
Referenced by Celartem::Base64T< Base64Traits >::decode(), Celartem::SimpleArray< AutoPtr< Bookmark > >::pop_back(), and Celartem::SimpleArray< AutoPtr< Bookmark > >::push_back().
|
inline |
This method is to set the memory allocation unit which is used during reallocation calls.
inAllocationUnit | Specifies the unit size for allocation. This is not the size in bytes but the count of elements. A large value makes reallocate calls faster but result in the larger memory consumption. For use with MemoryStorage, we recommend you should choose a large value for it. 0 means using the default. |
Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::init(), and Celartem::SimpleArray< AutoPtr< Bookmark > >::SimpleArray().
|
inline |
This method is to control whether the array will be zero-cleared or not in the destruction/reallocation phase. You should do zero-clear of the memory block if you store some sensitive information such as user credential.
doIt | true to do zero-clear in the destruction/reallocation phase. false to disable zero-clear. |
Referenced by Celartem::DataArray< T >::duplicate(), Celartem::DataArray< T >::swap(), and Celartem::SimpleArray< AutoPtr< Bookmark > >::swap().
|
inline |
This method swaps the contents of the array with the specified array instance.
inSa | The SimpleArray instance with which this instance will exchange the contents. |
Referenced by Celartem::DjVu::PackedBitmap::swap(), and Celartem::DataArray< T >::swap().
|
inline |
This method zero-clears the array in the way of std::memset
. This is very dangerous method and you should consider that you should use fill instead of it.
Referenced by Celartem::DjVu::PackedBitmap::zeroClear(), and Celartem::DataArray< T >::zeroClear().