The Array1D class is a templated container. The container has a 1 dimensional behavior,
and defines only 1D [index] access operators. Array1D is considered a static
container. Indeed, it does not have on demand resizing functions. The Array1D
container has a resizing method, but the resizing logic must be programmed
externally. Plus the resizing often needs item copying, which is far from performant.
People needing more dynamic containers will be better served with List and its
derivate.
Synopsis
#include <lyric/Array1D.hpp>
template <class AIT>
class Array1D : public Memory1D<AIT>
{
public:
~Array1D ()
throw ();
Array1D ()
throw ();
Array1D (Size size)
throw (Exception::Memory::Alloc);
Array1D (const Array1D& array)
throw (Exception::Memory::Alloc);
Array1D& operator = (const AIT& val)
throw ();
Array1D& operator = (const Array1D& array)
throw (Exception::Memory::Alloc);
Array1D& operator = (const Memory1D<AIT>& block)
throw (Exception::Memory::Alloc);
void create (Size size)
throw (Exception::Memory::Alloc);
void create (const AIT* block, Size size)
throw (Exception::Memory::Alloc);
void resize (Size newsize)
throw (Exception::Memory::Alloc);
void move (Size size, Size src, Size dest)
throw (Exception::Memory::Move);
void destroy ()
throw ();
// Inherited from Memory1D, see Section 10.1
Size size () const
throw ();
AIT& operator [] (Size index)
throw (Exception::Memory::Range);
const AIT& operator [] (Size index) const
throw (Exception::Memory::Range);
};
Description
-
˜Array1D () -
Destroys this container. Releases all memory resources used by this container
and the stored items.
-
Array1D () -
Constructs this container as an empty container. Its size is set to zero and
no space to store items is allocated.
-
Array1D (Size size) -
Constructs this container with the given size. The size is set and space to store size
items is allocated.
-
Exception::Memory::Alloc - is thrown if not enough memory is found to store
size items.
-
Array1D (const Array1D& array) -
Clones the given array into this container. All properties and items stored in array
are copied into this container.
-
Exception::Memory::Alloc - is thrown if not enough memory is found to store
array.size() items.
-
Array1D& operator = (const AIT& val) - Sets
all items stored in this container to the given value, and returns a reference to this
for assignment operation chaining.
-
Array1D& operator = (const Array1D& array) -
Assigns this container from the given array, and returns a reference to this for
assignment operation chaining. All properties and items stored in array are copied
into this container.
-
Exception::Memory::Alloc - is thrown if not enough memory is found to store
array.size() items.
-
Array1D& operator = (const Memory1D<AIT>& block) -
Assigns this container from the given memory block, and returns a reference to this
for assignment operation chaining. All properties and items stored in the memory
block are copied into this container.
-
Exception::Memory::Alloc - is thrown if not enough memory is found to store
block.size() items.
-
void create (Size size) -
Creates this container with the new given size. This operation is destructive in the
sense that items previously stored in this are deleted.
-
Exception::Memory::Alloc - is thrown if not enough memory is found to store
size items.
-
void create (const AIT* block, Size size) -
Creates this container from a given memory block, with a given size. This function
first reserves memory for size items, then copies size items from the given memory
block into this container. This function is provided to clone C like containers into
LYRIC like containers.
-
Exception::Memory::Alloc - is thrown if not enough memory is found to store
size items.
-
void resize (Size newsize) -
Resizes this container such that it can store newsize items. This method is only
destructive as far as the new size is smaller than the size this container was
before the call. In this case only items from zero to newsize are kept in this
container. During execution of this method items are eventually copied
around. However LYRIC’s implementation is optimized with fast memory
copies when it can thanks to the fastmemops function, it will copy items
in C++ fashion, eventually using a lot of temporary memory and CPU
resources.
-
Exception::Memory::Alloc - is thrown if not enough memory is found to store
newsize items.
-
void move (Size size, Size src, Size dest) -
Moves size items from the src index to the dest index in this container. LYRIC
checks if dest>src or src>dest to decide if it does a left-to-right or a right-to-left
copy, in order to not loose items during the move process.
-
Exception::Memory::Move - is thrown if dest+size>this.size(), or if
src+size>this.size(), depending whether dest>src or src>dest.
-
void destroy () -
Destroys all items stored in this container. This method releases memory resources
and sets the size to zero. The C++ object itself is not destroyed, and can be reused
after having called the create method.
-
Size size () const -
Returns the number of items this container can store.
-
AIT& operator [...] (Size index) -
Returns a reference to the item stored at position index in this container. This
operator can be used as left or right hand value. This means one can as well read as
write an item in this container.
-
Exception::Memory::Range - is thrown if the given index is out of this
container’s size, and only if the -DO_RANGE_CHECK is given to the
compiler, resp. if O_RANGE_CHECK is defined.
-
const AIT& operator [...] (Size index) const -
Returns an immutable reference to the item stored at position index in this
container. This operator can only be used as right hand value. This means one can
only read an item from this container.
-
Exception::Memory::Range - is thrown if the given index is out of this
container’s size, and only if the -DO_RANGE_CHECK is given to the
compiler, resp. if O_RANGE_CHECK is defined.