#include <cel_memory.h>
List of all members.
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 | insert (size_t inPos, size_t inCount) |
| void | insert (size_t inPos, size_t inCount, const T *inElements) |
| void | insert (size_t inPos, 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 |
Detailed Description
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
class Celartem::SimpleArray< T, copyPolicy >
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.
- See also:
- CopyPolicy, DataTraits.
Constructor & Destructor Documentation
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This constructor initializes the SimpleArray instance by the specified size; it does almost same as init method.
- Parameters:
-
| 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. |
- See also:
- MemoryAllocator, init, setAllocationUnit, MemoryStorage
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This constructor initializes the SimpleArray instance with the data copied from the other instance.
- Parameters:
-
| inSa | An array to be duplicated. This constructor really copies the memory block held by the instance. |
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
Member Function Documentation
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
| void Celartem::SimpleArray< T, copyPolicy >::allocate |
( |
size_t |
inSize, |
|
|
size_t |
inReserve = AUTO_SIZE | |
|
) |
| | [inline] |
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method inserts the specified number of elements to the end of the array.
- Parameters:
-
| inCount | The number of the elements in inElements. |
| inElements | The elements to insert. |
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method inserts the specified number of elements to the end of the array.
- Parameters:
-
| inElements | The elements to insert. |
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method is for the compatibility with STL algorithms.
- Returns:
- Reference to the last element in the array. This reference is identical to
array[getSize() - 1] .
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method is for the compatibility with STL algorithms.
- Returns:
- Reference to the last element in the array. This reference is identical to
array[getSize() - 1] .
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method is for the compatibility with STL algorithms.
- Returns:
- Pointer to the first element in the array. This pointer is identical to
&array[0] .
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method release the memory.
This is just an alias of free method.
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method duplicates the specified array.
- Parameters:
-
| inBuffer | An array to be duplicated. |
| inSize | The size of the array. |
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method duplicates the specified array.
- Parameters:
-
| inBuffer | An array to be duplicated. |
| inSize | The size of the array. |
| inEndian | The endianness of the specified buffer. |
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method is for the compatibility with STL algorithms.
- Returns:
- Pointer to the end of the array. This pointer is identical to
&array[array.getSize()] .
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method is a general version of fill function; fill(0) fills all array with 0.
- Parameters:
-
| t | The value to fill with. |
- See also:
- zeroClear
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<typename U >
This method is a general version of fill function; fill(0) fills all array with 0.
- Parameters:
-
| t | The value to fill with. |
- See also:
- zeroClear
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
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.
- See also:
- reserve, allocate, reallocate
Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::allocate(), Celartem::SimpleArray< AutoPtr< Bookmark > >::clear(), Celartem::SimpleArray< AutoPtr< Bookmark > >::compact(), Celartem::SimpleArray< AutoPtr< Bookmark > >::duplicate(), Celartem::DjVu::IFF::Layout::init(), Celartem::SimpleArray< AutoPtr< Bookmark > >::init(), Celartem::SimpleArray< AutoPtr< Bookmark > >::insert(), and Celartem::SimpleArray< AutoPtr< Bookmark > >::~SimpleArray().
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method is for the compatibility with STL algorithms.
- Returns:
- Reference to the first element in the array. This reference is identical to
array[0] .
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method is for the compatibility with STL algorithms.
- Returns:
- Reference to the first element in the array. This reference is identical to
array[0] .
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method is to obtain the current memory allocation unit.
- Returns:
- The current memory allocation unit.
- See also:
- setAllocationUnit, reallocate
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method returns const raw pointer to the array.
- Returns:
- Raw pointer (read-only) to the array.
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method returns the index of the specified item.
- Returns:
- 0-based index of the first found item. If none is found, returns -1.
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<typename U >
This method returns the index of the specified item.
- Returns:
- 0-based index of the first found item. If none is found, returns -1.
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method initializes the SimpleArray instance by the specified size. No other method can replace the allocator except the constructor.
- Parameters:
-
| 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. |
- See also:
- MemoryAllocator, SimpleArray, setAllocationUnit
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
| void Celartem::SimpleArray< T, copyPolicy >::insert |
( |
size_t |
inPos, |
|
|
size_t |
inCount, |
|
|
const T * |
inElements | |
|
) |
| | [inline] |
This method inserts the specified number of elements to the specified position.
- Parameters:
-
| inPos | It indicates the position on which new elements are inserted. |
| inCount | The number of the elements in inElements. |
| inElements | The elements to insert. |
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method inserts the specified number of elements to the specified position.
- Parameters:
-
| inPos | It indicates the position on which new elements are inserted. |
| inElements | The elements to insert. |
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method checks whether the array is valid or not.
- Returns:
true if the array is valid, otherwise false.
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method is for the compatibility with STL algorithms.
- Returns:
- Pointer to the last element in the array. This pointer is identical to
&array[array.getSize() - 1] .
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method copies the specified instance.
- Parameters:
-
| inSa | An array to be duplicated. This constructor really copies the memory block held by the instance. |
- Returns:
- Reference to this instance (*this).
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method provides the array interface (for read).
- Parameters:
-
- Returns:
- A const reference to the specified entry.
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method provides the array interface.
- Parameters:
-
- Returns:
- The reference to the specified entry.
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method is almost identical to vector::pop_back .
- Returns:
- The value that was on the tail of the array.
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method is almost identical to deque::pop_front .
Please note that this method is much slower than pop_back.
- Returns:
- The value that was on the tail of the array.
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<typename U >
This method is almost identical to vector::push_back .
- Parameters:
-
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<typename U >
This method is almost identical to deque::push_front .
- Parameters:
-
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
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.
- Parameters:
-
| inSize | Specifies the new size of the array in number of entries. |
- See also:
- resize, allocate
Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::resize().
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method removes elements of the specified range and moves the elements after them toward the front of the array.
- Parameters:
-
| inPos | The index of the first element to remove. |
| inCount | The number of elements to remove. |
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
This method changes the reservation size of the array.
- Parameters:
-
| 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. |
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
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.
- Parameters:
-
| doIt | true to do zero-clear in the destruction/reallocation phase. false to disable zero-clear. |
Referenced by Celartem::SimpleArray< AutoPtr< Bookmark > >::swap().
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
template<class T, CopyPolicy copyPolicy = DataTraits<T>::copyPolicy>
The documentation for this class was generated from the following file: