#include <OTC/collctn/vector.hh> template<class T> class OTC_Vector {
public:
static os_typespec* get_os_typespec();
inline ~OTC_Vector();
OTC_Vector(u_int theSize);
OTC_Vector(OTC_Vector<T> const& theVector);
OTC_Vector( OTC_Vector<T> const& theVector, OTC_Range const& theRange );
OTC_Vector( OTC_Vector<T> const& theVector, u_int theStart, u_int theLength );
OTC_Vector(T const* theVector, u_int theSize);
OTC_Vector<T>& operator=(OTC_Vector<T> const& theVector);
inline operator T*();
inline operator T const*() const;
inline T* buffer();
inline T const* buffer() const;
inline u_int size() const;
inline T& operator[](u_int theIndex);
inline T const& operator[](u_int theIndex) const;
void resize(u_int theSize);
};
OTC_Vector
is a wrapper around a conventional C style
vector. As with the traditional vector, indexes into the vector
commence at 0
and extend up to one less than the size of the
vector.
If the vector is to hold a data type possessing a constructor,
the data type must have a constructor which accepts no arguments.
If the data type being held, doesn't automatically initialise
itself through a constructor, it is the user's responsibility
to initialise the vector. For example, if the vector is to hold
pointers, the user will have to initialise each location in
the vector to 0
before use. In addition to having to initialise
the vector when holding pointers, it is also the user's
responsibility to delete each object pointed at, when the vector is
destroyed, if those objects would no longer be referenced.
OTC_Vector(u_int theSize);
theSize
.
theSize
must be greater than zero.
OTC_Vector(OTC_Vector<T> const& theVector);
theVector
.
OTC_Vector(OTC_Vector<T> const& theVector, OTC_Range const& theRange);
theVector
described by
theRange
. The length of the region
described by theRange
must be greater
than zero.
OTC_Vector(
OTC_Vector<T> const& theVector,
u_int theStart,
u_int theLength
);
theVector
described by
theStart
and theLength
. theLength
must be greater than zero.
OTC_Vector(T const* theVector, u_int theSize);
theSize
which contains a copy of the items
in theVector
. theSize
must
be greater than zero.
OTC_Vector<T>& operator=(OTC_Vector<T> const& theVector);
theVector
. Except
in the case of self assignment, new memory
will always be allocated to hold the
new data. The old memory held by this
vector will be deleted. If the vector holds
pointers to objects, the objects being
pointed at are not deleted.
inline operator T*();
inline operator T const*() const;
inline T* buffer();
buffer()
will only be used on a
non-const instance of this class, and will
allow modification of the underlying
buffer using the pointer returned.
inline T const* buffer() const;
buffer()
will always be used for a const
object, or a non-const instance of this
class, when the conversion is to a pointer
to a vector of const objects. It is not
possible to modify the underlying vector
using the pointer returned.
inline u_int size() const;
inline T& operator[](u_int theIndex);
theIndex
. This
version of operator[]()
will only be
used on a non-const instance of this
class. The reference to the object held,
will allow modification of the actual
object. theIndex
must be less than the
size of the vector.
inline T const& operator[](u_int theIndex) const;
theIndex
. This
version of operator[]()
will only be
used on a const instance of this
class, or a non-const instance, when
a reference to a const object is required.
The reference to the object held will not
allow modification of the actual object.
theIndex
must be less than the size of
the vector.
void resize(u_int theSize);
theSize
. Unless
theSize
is the same as the current size,
a new block of memory is always allocated,
even when the size of the vector is being
decreased. If the size of the vector is
increased, the new section is not
explicitly initialised, thus unless the
vector holds class objects which perform
their own initialisation you will need to
initialise it yourself.