/*
$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 <iostream>
using namespace std;
template<class T> Vector<T>:: ~Vector() { v+=l; delete[] v; }
template<class T> void Vector<T>:: 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<class T> void Vector<T>:: resize(int newl, int newh)
{
if ( l==newl && h==newh ) return;
v += l; delete[] v;
allocate (newl,newh);
}
template<class T> void Vector<T>:: resize(int newh) { resize (1,newh); }
template<class T> void Vector<T>:: extendAndCopy(int newh)
{
if (newh == h) return;
if (newh < h) {
cout << "\n*** Vector extend: newh < h ("<<newh<<" < "<<h<< ")\n";
cout.flush(); abort();
}
T* vNew = new T[newh-l+1];
vNew -= l;
for (int i=l; i<=h; ++i) vNew[i] = v[i];
v += l;
delete[] v;
h = newh;
v = vNew;
}
template<class T> int Vector<T>:: size() const { return (h-l+1); }
template<class T> int Vector<T>:: memSpace() const { return (h-l+1)*sizeof(T); }
template<class T> void Vector<T>:: checkBounds(int i) const
{
if (i<l || i>h)
{
cout << "\n*** Vector index " << i << " out of range\n";
cout.flush(); abort();
}
}
template<class T> void Vector<T>:: print() const
{
int i;
for (i=l; i<=h; ++i) cout << v[i] << " ";
cout << "\n";
}
/*
template<class T> ostream& operator<< (ostream& s, const Vector<T>& vec)
{
int i;
for (i=vec.l; i<=vec.h; ++i) s << vec.v[i] << " ";
s << "\n";
return s;
}
*/
//-------------------------------------------------------------------------
template<class T> Vector<T>:: Vector(Vector<T>& /*vec*/)
{
notImplemented("Vector:: copy constructor! Check function arguments");
}
template<class T> Vector<T>& Vector<T>:: operator= (Vector<T>& /*vec*/)
{
notImplemented("Vector:: operator=(Vector<T>& vec)");
return *this;
// int i; for(i=l; i<=h; ++i) v[i]= vec.v[i]; return *this;
}
template<class T> Vector<T>& Vector<T>:: operator= (T /*a*/)
{
notImplemented("Vector:: operator=(T a)");
return *this;
//int i; for(i=l; i<=h; ++i) v[i]= a; return *this;
}
template<class T> void Vector<T>:: notImplemented(const char* s) const
{
cout << "\n*** Class Vector: called function "
<< s << " not implemented\n";
cout.flush(); abort();
}
syntax highlighted by Code2HTML, v. 0.9.1