Logo Search packages:      
Sourcecode: ragel version File versions

SVector< T, Resize > Class Template Reference
[Vector]

#include <svector.h>

Inheritance diagram for SVector< T, Resize >:

STable< T >

List of all members.


Detailed Description

template<class T, class Resize = ResizeExpn>
class SVector< T, Resize >

Copy-on-write dynamic array for classes with non-trivial initialization.

SVector is a variant of Vector that employs copy-on-write behaviour. The SVector copy constructor and = operator make shallow copies. If a vector that references shared data is modified with insert, replace, append, prepend, setAs or remove, a new copy is made so as not to interfere with the shared data. However, shared individual elements may be modified by bypassing the SVector interface.

SVector is a dynamic array that can be used to contain complex data structures that have constructors and destructors as well as simple types such as integers and pointers.

SVector supports inserting, overwriting, and removing single or multiple elements at once. Constructors and destructors are called wherever appropriate. For example, before an element is overwritten, it's destructor is called.

SVector provides automatic resizing of allocated memory as needed and offers different allocation schemes for controlling how the automatic allocation is done. Two senses of the the length of the data is maintained: the amount of raw memory allocated to the vector and the number of actual elements in the vector. The various allocation schemes control how the allocated space is changed in relation to the number of elements in the vector.

Definition at line 36 of file svectcommon.h.


Public Member Functions

void deepCopy (const SVector &v)
 Deep copy another vector into this vector.
void empty ()
 Free all memory used by the vector.
IterFirst first ()
 Return first element.
STabHead * header () const
 Get header of the shared vector.
IterLast last ()
 Return last element.
long length () const
 Get the length of the shared vector.
SVectoroperator= (STabHead *head)
 Shallow copy another vector into this vector from only the header.
SVectoroperator= (const SVector &v)
 Shallow copy another vector into this vector.
T & operator[] (int i) const
long size () const
 SVector (STabHead *head)
 Perform a shallow copy of the vector from only the header.
 SVector (const SVector &v)
 Perform a shallow copy of the vector.
 SVector (long size, long allocLen)
 Create a vector with a specified number of initial elements and allocation.
 SVector (long size)
 Create a vector with a specified number of initial elements.
 SVector ()
 Initialize an empty vector with no space allocated.
 ~SVector ()
 Free all memory used by the vector.
void append (const SVector &v)
 Append the contents of another vector.
void append (const T *val, long len)
 Append len elements to the end of the vector.
void append (const T &val)
 Append one elment to the end of the vector.
void appendDup (const T &item, long len)
 Append len copies of item.
void appendNew (long len)
 Append len newly created items.
void appendNew ()
 Append a single newly created item.
void insert (long pos, const SVector &v)
 Insert all the elements from another vector at position pos.
void insert (long pos, const T *val, long len)
 Insert len elements at position pos.
void insert (long pos, const T &val)
 Insert one element at position pos.
void insertDup (long pos, const T &val, long len)
 Insert len copies of item at position pos.
void insertNew (long pos, long len)
 Insert len new elements using the default constructor.
void insertNew (long pos)
 Insert one new element using the default constrcutor.
void prepend (const SVector &v)
 Prepend the contents of another vector.
void prepend (const T *val, long len)
 Prepend len elements to the front of the vector.
void prepend (const T &val)
 Prepend one elment to the front of the vector.
void prependDup (const T &item, long len)
 Prepend len copies of item.
void prependNew (long len)
 Prepend len newly created items.
void prependNew ()
 Prepend a single newly created item.
void remove (long pos, long len)
 Remove len elements at position pos.
void remove (long pos)
 Remove one element at position pos.
void replace (long pos, const SVector &v)
 Replace at position pos with all the elements of another vector.
void replace (long pos, const T *val, long len)
 Replace len elements at position pos.
void replace (long pos, const T &val)
 Replace one element at position pos.
void replaceDup (long pos, const T &val, long len)
 Replace at position pos with len copies of an item.
void replaceNew (long pos, long len)
 Replace at position pos with len new elements.
void replaceNew (long pos)
 Replace at position pos with one new element.
void setAs (const SVector &v)
 Set the vector to exactly the contents of another vector.
void setAs (const T *val, long len)
 Set the contents of the vector to be len elements exactly.
void setAs (const T &val)
 Set the contents of the vector to be val exactly.
void setAsDup (const T &item, long len)
 Set the vector to len copies of item.
void setAsNew (long len)
 Set the vector to exactly len new items.
void setAsNew ()
 Set the vector to exactly one new item.

Public Attributes

T * data
 Table data.

Protected Member Functions

void downResize (long len)
void downResizeDup (long len)
long insertCommon (long pos, long len)
long replaceCommon (long pos, long len)
void setAsCommon (long len)
void upResize (long len)
void upResizeDup (long len)
void upResizeFromEmpty (long len)

Private Types

typedef STable< T > BaseTable

Classes

struct  Iter
 Shared Vector Iterator. More...
struct  IterFirst
struct  IterLast
struct  IterNext
struct  IterPrev

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index