/* $Id: vector.c,v 1.1 1996/10/10 10:01:35 roitzsch Exp $ (C)opyright 1996 by Konrad-Zuse-Center, Berlin All rights reserved. Part of the Kaskade distribution */ #include using namespace std; template Vector:: ~Vector() { v+=l; delete[] v; } template void Vector:: allocate (int l1, int h1) { l=l1; h=h1; if (h < l) { cout << "\n*** Class vector: wrong indices: l,h = " << l << " " << h << "\n"; cout.flush(); abort(); } v = new T[h-l+1]; if (!v) { cout << "\n*** Class vector: allocation failure: l,h = " << l << " " << h << "\n"; cout.flush(); abort(); } v -= l; } template void Vector:: resize(int newl, int newh) { if ( l==newl && h==newh ) return; v += l; delete[] v; allocate (newl,newh); } template void Vector:: resize(int newh) { resize (1,newh); } template void Vector:: extendAndCopy(int newh) { if (newh == h) return; if (newh < h) { cout << "\n*** Vector extend: newh < h ("< int Vector:: size() const { return (h-l+1); } template int Vector:: memSpace() const { return (h-l+1)*sizeof(T); } template void Vector:: checkBounds(int i) const { if (ih) { cout << "\n*** Vector index " << i << " out of range\n"; cout.flush(); abort(); } } template void Vector:: print() const { int i; for (i=l; i<=h; ++i) cout << v[i] << " "; cout << "\n"; } /* template ostream& operator<< (ostream& s, const Vector& vec) { int i; for (i=vec.l; i<=vec.h; ++i) s << vec.v[i] << " "; s << "\n"; return s; } */ //------------------------------------------------------------------------- template Vector:: Vector(Vector& /*vec*/) { notImplemented("Vector:: copy constructor! Check function arguments"); } template Vector& Vector:: operator= (Vector& /*vec*/) { notImplemented("Vector:: operator=(Vector& vec)"); return *this; // int i; for(i=l; i<=h; ++i) v[i]= vec.v[i]; return *this; } template Vector& Vector:: operator= (T /*a*/) { notImplemented("Vector:: operator=(T a)"); return *this; //int i; for(i=l; i<=h; ++i) v[i]= a; return *this; } template void Vector:: notImplemented(const char* s) const { cout << "\n*** Class Vector: called function " << s << " not implemented\n"; cout.flush(); abort(); }