Home Libraries Author Links

Abstract Data Type StmDvec
[Dvec: Dynamic Vectors and Character Strings]

Collaboration diagram for Abstract Data Type StmDvec:

Detailed Description

StmDvec is an abstract data type for dynamic type vectors.

A StmDvec object realizes a vector of concepually arbitrary dimension of elements of a fixed type configured during creation of the vector by stmDvecAlloc(), stmDvecResize(), stmDvecIns(), stmDvecElIns(), stmDvecnElIns(), stmDvecApp(), stmDvecElApp() and stmDvecnElApp(). Elements of such a dynamic type vector can be accessed exactly like normal type arrays, that is to say the ith type element of a dynamic type vector dvec is dvec [i] or * (dvec + i).

Dynamic type vectors cannot be obtained by other means as by the functions mentioned above and have to be deallocated by stmDvecFree().


Defines

#define stmDvecAlloc(type, dim)   ((type *) stmValloc_ (dim, sizeof (type)))
 Creation of a new dynamic type vector.
#define stmDvecResize(type, dvec, dim)   ((type *) stmVrealloc_ ((char *) (dvec), dim, sizeof (type)))
 Resize the dynamic vector dvec.
#define stmDvecFree(dvec)   (stmVfree_ ((char *) (dvec)))
 Destroy the dynamic vector dvec.
#define stmDvecDim(dvec)   (stmVdim_ ((char *) (dvec)))
 Return the element count of the dynamic vector dvec.
#define stmDvecDel(type, dvec, start, count)   ((type *) stmVdelete_ ((char *) (dvec), start, count, sizeof (type)))
 Delete elements of the dynamic vector dvec.
#define stmDvecIns(type, dvec, start, pelem, count)
 Insert elements into the dynamic vector dvec.
#define stmDvecElIns(type, dvec, start, elem)   stmDvecnElIns_ (type, dvec, start, 1, elem)
 Insert one element into the dynamic vector dvec.
#define stmDvecnElIns(type, dvec, start, count, elem)   stmDvecnElIns_ (type, dvec, start, count, elem)
 Insert multiple copies of one element into the dynamic vector dvec.
#define stmDvecApp(type, dvec, pelem, count)
 Append elements to the dynamic vector dvec.
#define stmDvecElApp(type, dvec, elem)   stmDvecnElApp_ (type, dvec, 1, elem)
 Append one element to the dynamic vector dvec.
#define stmDvecnElApp(type, dvec, count, elem)   stmDvecnElApp_ (type, dvec, count, elem)
 Append multiple copies of one element to the dynamic vector dvec.


Define Documentation

#define stmDvecAlloc ( type,
dim   )     ((type *) stmValloc_ (dim, sizeof (type)))

Creation of a new dynamic type vector.

The function stmDvecAlloc allocates a dynamic vector consisting of dim elements of type type initialized with null bytes and returns a type pointer to the 0th element of the vector.

On error the NULL pointer is returned in which case the variable errno reflects the error's cause.

Definition at line 120 of file dvec.h.

#define stmDvecResize ( type,
dvec,
dim   )     ((type *) stmVrealloc_ ((char *) (dvec), dim, sizeof (type)))

Resize the dynamic vector dvec.

The function stmDvecResize adjusts the element count of the dynamic type vector dvec to dim. If dim is less than the current element count, the vector is shotened, if it is greater, elements initialized with 0 bytes are appended. If dvec is the NULL pointer, a new dynamic vector is allocated. On success a type pointer to the 0th element of the (possibly relocated) vector is returned and the original pointer dvec is invalid.

On error the NULL pointer is returned in which case the variable errno reflects the error's cause.

Definition at line 135 of file dvec.h.

#define stmDvecFree ( dvec   )     (stmVfree_ ((char *) (dvec)))

Destroy the dynamic vector dvec.

The function stmDvecFree deallocates the dynamic vector dvec. It is no error to call the function with the NULL pointer in which case no operation takes place.

Examples:
matchtst.c.

Definition at line 145 of file dvec.h.

#define stmDvecDim ( dvec   )     (stmVdim_ ((char *) (dvec)))

Return the element count of the dynamic vector dvec.

The function stmDvecDim returns the element count of the dynamic vector dvec. If dvec is the NULL pointer, 0 is returned.

On error -1 is returned in which case the variable errno reflects the error's cause.

Definition at line 156 of file dvec.h.

#define stmDvecDel ( type,
dvec,
start,
count   )     ((type *) stmVdelete_ ((char *) (dvec), start, count, sizeof (type)))

Delete elements of the dynamic vector dvec.

The function stmDvecDel deletes count elements of the dynamic type vector dvec beginning at index position start. Trailing elements are moved count index positions in direction to the beginning of the vector. If count is 0, all elements beginning with index position start to the end of the vector are deleted. On error, or if dvec is the NULL pointer, the NULL pointer is returned, else a type pointer to the 0th element of the (possibly relocated) vector. On return the original pointer dvec is invalid.

On error the variable errno reflects the error's cause.

Definition at line 172 of file dvec.h.

#define stmDvecIns ( type,
dvec,
start,
pelem,
count   ) 

Value:

((type *) stmVinsert_ ((char *) (dvec), start,                                 \
                       (const char *) (pelem), count, sizeof (type)))
Insert elements into the dynamic vector dvec.

The function stmDvecIns copies, beginning at index position start, len - start elements of the dynamic type vector dvec of dimension len n index positions towards the vector's rear end prolongating the vector by n elements. The value len - start must not be negative. If pelem is the NULL pointer or if count is greater than 0, count is the number n of index positions. Otherwise, that is to say, if pelem is not the NULL pointer but count is 0, it is assumed that pelem points to a dynamic type vector whose dimension determines the number n of index positions. If pelem is not the NULL pointer, then the first n elements of the vector pelem are copied to the n elements of vector dvec beginning at index position start. Else the

                            min (n, len - \a start)
elements beginning at index position start remain unchanged and the
                            max (0, n - len + \a start)
elements folowing them are initialized with 0 bytes. If dvec is the NULL pointer and start is 0, a new dynamic type vector is allocated. Either none of the elements to be copied to dvec shall be originated in dvec or else all these elements shall stem from dvec.

On success a type pointer to the 0th element of the (possibly relocated) dynamic vector is returned. On error the NULL pointer is returned and the variable errno reflects the error's cause. On return the original pointer dvec is invalid.

Definition at line 206 of file dvec.h.

#define stmDvecElIns ( type,
dvec,
start,
elem   )     stmDvecnElIns_ (type, dvec, start, 1, elem)

Insert one element into the dynamic vector dvec.

The function stmDvecElIns inserts the element elem into the dynamic type vector dvec at index position start. If dvec is the NULL pointer and start is 0, a new vector is allocated. All original elements from beginning at index position start are moved one index position towards the rear end of the vector.

On success a type pointer to the 0th element of the (possibly relocated) dynamic vector is returned. On error the NULL pointer is returned and the variable errno reflects the error's cause. On return the original pointer dvec is invalid.

Definition at line 224 of file dvec.h.

#define stmDvecnElIns ( type,
dvec,
start,
count,
elem   )     stmDvecnElIns_ (type, dvec, start, count, elem)

Insert multiple copies of one element into the dynamic vector dvec.

The function stmDvecnElIns inserts count copies of the element elem into the dynamic type vector beginning at index position start. If dvec is the NULL pointer and start is 0, a new vector is allocated. All original elements beginning at index position start are moved count index position towards the rear end of the vector.

On success a type pointer to the 0th element of the (possibly relocated) dynamic vector is returned. On error the NULL pointer is returned and the variable errno reflects the error's cause. On return the original pointer dvec is invalid.

Definition at line 241 of file dvec.h.

#define stmDvecApp ( type,
dvec,
pelem,
count   ) 

Value:

((type *) stmVappend_ ((char *) (dvec),                                        \
                       (const char *) (pelem), count, sizeof (type)))
Append elements to the dynamic vector dvec.

The function stmDvecApp extends the dimension of the dynamic type vector dvec by a number n of elements. If pelem is the NULL pointer, or if count is greater than 0, count determines the number n of elements. Otherwise, that is to say if pelem is not the NULL pointer but count is 0, it is assumed that pelem points to a dynamic type vector whose dimension determines the number n of elements. If pelem is not the NULL pointer, then the first n elements of the vector pelem are copied to the appended elements of dvec. Else these elements are initialized with 0 bytes. If dvec is the NULL pointer, a new dynamic type vector of dimension n is allocated. Either none of the elements to be copied to dvec shall be originated in dvec or else all these elements shall stem from dvec.

On success a type pointer to the 0th element of the (possibly relocated) dynamic vector is returned. On error the NULL pointer is returned and the variable errno reflects the error's cause. On return the original pointer dvec is invalid.

Definition at line 265 of file dvec.h.

#define stmDvecElApp ( type,
dvec,
elem   )     stmDvecnElApp_ (type, dvec, 1, elem)

Append one element to the dynamic vector dvec.

The function stmDvecElApp appends the element elem to the dynamic type vector dvec increasing its dimension by 1. If dvec is the NULL pointer, a new vector is allocated.

On success a type pointer to the 0th element of the (possibly relocated) dynamic vector is returned. On error the NULL pointer is returned and the variable errno reflects the error's cause. On return the original pointer dvec is invalid.

Definition at line 281 of file dvec.h.

#define stmDvecnElApp ( type,
dvec,
count,
elem   )     stmDvecnElApp_ (type, dvec, count, elem)

Append multiple copies of one element to the dynamic vector dvec.

The function stmDvecnElApp appends count copies of the element elem to the dynamic type vector dvec increasing its dimension by count. If dvec is the NULL pointer, a new vector is allocated.

On success a type pointer to the 0th element of the (possibly relocated) dynamic vector is returned. On error the NULL pointer is returned and the variable errno reflects the error's cause. On return the original pointer dvec is invalid.

Definition at line 295 of file dvec.h.


© Copyright Tom Michaelis 2002-2007

Distributed under the SysToMath Software License (See the accompanying file license.txt or a copy at www.SysToMath.com).