2
// artem.h --- template for the Array class
4
// Copyright (C) 1996 Limit Point Systems, Inc.
6
// Author: Curtis Janssen <cljanss@limitpt.com>
9
// This file is part of the SC Toolkit.
11
// The SC Toolkit is free software; you can redistribute it and/or modify
12
// it under the terms of the GNU Library General Public License as published by
13
// the Free Software Foundation; either version 2, or (at your option)
16
// The SC Toolkit is distributed in the hope that it will be useful,
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
// GNU Library General Public License for more details.
21
// You should have received a copy of the GNU Library General Public License
22
// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23
// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25
// The U.S. Government is granted a limited license as per AL 91-7.
29
#pragma implementation
41
Array():_length(0),_managed(0),_array(0) {}
42
Array(const Array<Type>&a):_length(0),_managed(0),_array(0) {operator=(a);}
43
Array(Type* data,int size):_length(size),_managed(0),_array(data){}
44
Array(int size):_length(0),_managed(0),_array(0) { set_length(size); }
46
//int length() const { return _length; };
47
int size() const { return _length; };
48
void clear() { set_length(0); }
49
void set_length(int size) {
50
if (_array && _managed) delete[] _array;
52
if (size) _array = new Type [ size ];
56
void resize(int size) {
58
if (size) _array = new Type [ size ];
61
if (size < _length) maxi = size;
63
for (int i=0; i<maxi; i++) _array[i] = tmp[i];
64
if (_managed && tmp) delete[] tmp;
68
Array<Type>& operator = (const Array<Type> & s) {
69
if (_managed && _array) delete[] _array;
72
if (_length) _array = new Type [ _length ];
74
for (int i=0; i<_length; i++) {
75
_array[i] = s._array[i];
79
Type& operator[] (int i) const {
80
if (i<0 || i>=_length) {
81
ExEnv::err0() << "Array::operator[](" << i << ") "
82
<< "out of range (" << _length << "0" << std::endl;
87
Type& operator() (int i) const {
88
if (i<0 || i>=_length) {
89
ExEnv::err0() << "Array::operator()(" << i << ") "
90
<< "out of range (" << _length << "0" << std::endl;
95
void push_back(const Type &d) {
97
_array[_length-1] = d;
106
// ///////////////////////////////////////////////////////////////////////////
110
// c-file-style: "CLJ"