The vector package provides ways to define vectors or stacks of objects of any type by using the macro expansion capability of the DEC C++ preprocessor.
To declare a generic vector:
<vector.hxx> in your program
and declare the vector class as follows:
declare(vector, TYPE)
TYPE may be any valid C++ type name. Make sure you
define the declare macro in every file that
references this new vector data type.
implement(vector, TYPE)
This implement macro must appear once in a program.
vector and TYPE
and use the index operator to reference these objects. The
following is an example of declaration and referencing:
class MyType {/* . . . */};
declare(vector,MyType)
implement(vector,MyType)
vector(MyType) vec1(100), vec2(5);
MyType x,y;
// . . .
if(vec2[4] == y) vec1[98] = x;
The TYPE parameter must be an identifier. If it is not a
class name, a fundamental type, or a type name, create a name for
the type using a typedef declaration. For example:
typedef char *PCHAR;
declare(vector, PCHAR)
implement(vector, PCHAR)
implement(vector, PCHAR)
void f()
{
vector(PCHAR) ptrvec(10);
char *p = "Text";
ptrvec[0] = p;
// ...
}
The generation of error messages within the vector package
is not thread safe; the package relies on static members to
handle the current error message and there is no synchonization
between threads. If this creates a problem for your application,
Digital recommends that you define a single Mutex
object to synchronize all use of the vector package. For more
information on synchronizing access to user-defined objects, see
Chapter 6.
Provides a generic (parameterized) data abstraction for a fixed- sized stack of objects of some given type.
#include <vector.hxx>
#include <vector.h>
class stack(TYPE): private vector(TYPE)
{
public:
stack(TYPE)(int); // objection size_error
stack(TYPE)(stack(TYPE) &);
void push(TYPE); // objection overflow_error
TYPE pop(); // objection underflow_error
TYPE &top(); // objection no_top_error
int full();
int empty();
int size();
int size_used();
static Objection overflow_error;
static Objection underflow_error;
static Objection no_top_error;
};
Before a stack object can be declared or implemented,
the base class, a vector object with the same type
parameter, must also be declared and implemented. To declare a
stack object you need to both declare and implement
the base vector class and the stack class.
cerr and calls abort() .
stack object with room for
size elements in the stack. If size is less than
or equal to 0, the objection vector(TYPE)::size_error
is raised. stack object that takes the initial
values of the elements from another stack object of the
same type and size. TRUE if the stack is empty; otherwise, it
returns FALSE . TRUE if the stack is full; otherwise, it
returns FALSE . stack(TYPE)::underflow_error
is raised. stack(TYPE)::overflow_error is raised.
stack(TYPE)::no_top_
error is raised.
declare(vector, int)
implement(vector, int)
declare(stack, int)
implement(stack, int)
void f()
{
stack(int) st(20);
st.push(17);
// ...
}
This example shows the four steps required to declare and implement
the base vector class and to declare and implement the
stack class. vector(TYPE) class
Provides the (parameterized) data abstraction for a fixed-sized vector of objects of some given type.
#include <vector.hxx>
#include <vector.h>
class vector(TYPE)
{
public:
vector(TYPE)(int); // objection size_error
vector(TYPE)(vector(TYPE) &);
~vector(TYPE)();
vector(TYPE) &operator=(vector(TYPE) &); // objection copy_size_error
TYPE &elem(int);
TYPE &operator[](int); // objection index_error
int size();
void set_size(int);
static Objection size_error;
static Objection copy_size_error;
static Objection index_error;
};
cerr and calls abort() .
vector object with the integer
argument representing the number of elements in the vector.
If the number of elements is less than or equal to 0, the
objection vector(TYPE)::size_error is raised.
vector object that takes initial
values of the elements from another vector object of
the same type and size. vector object. vector(TYPE)::copy_size_
error is raised. size() -1. If the subscript is out of bounds, the
objection vector(TYPE)::index_error is raised.