/* $Id: vector.h,v 1.3 1996/11/06 11:37:50 roitzsch Exp $ */
#ifndef VECTOR_TEMPLATE_H
#define VECTOR_TEMPLATE_H
#define CheckBoundsFlag 0
#define FORALL(x,i) for (i=(x).l; i<=(x).h; ++i)
#define FORALL_DOWNWARD(x,i) for (i=(x).h; i>=(x).l; --i)
//-------------------------------------------------------------------------
#include <iostream>
#include <stdlib.h>
//----------------------------------------------------------------------------
template<class T>
class Vector
{
public:
T* v;
int l, h;
Vector(int l1, int h1) { allocate(l1, h1); }
Vector(int h1) { allocate( 1, h1); }
Vector() { allocate( 1, 1); }
virtual ~Vector();
int low() const { return l; }
int high() const { return h; }
virtual T Top() const { return v[h]; }
int memSpace() const;
int size() const;
virtual void resize(int newh);
virtual void resize(int newl, int newh);
void extendAndCopy (int newh);
T& operator[] (int i)
{
if (CheckBoundsFlag) checkBounds(i);
return v[i];
}
const T& operator[] (int i) const
{
if (CheckBoundsFlag) checkBounds(i);
return v[i];
}
// friend ostream& operator<< (ostream& s, const Vector<T>& vec);
void print() const;
protected:
void allocate(int l1, int h1);
void checkBounds(int i) const;
void notImplemented(const char* s) const;
private:
Vector(Vector<T>& vec); // disallowed!
Vector<T>& operator= (Vector<T>& vec); // disallowed!
Vector<T>& operator= (T a); // disallowed!
};
//-------------------------------------------------------------------------
#if INCLUDE_TEMPLATE_DEFS
#include "vector.c"
#endif
#endif
syntax highlighted by Code2HTML, v. 0.9.1