source: git/factory/templates/ftmpl_array.cc @ 6881f9b

spielwiese
Last change on this file since 6881f9b was 6881f9b, checked in by Jens Schmidt <schmidt@…>, 27 years ago
o #include <templates/config.h>, #include <templates/assetr.h> changed to #include <factoryconf> (without MAKEHEADER now) git-svn-id: file:///usr/local/Singular/svn/trunk@215 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.0 KB
Line 
1// emacs edit mode for this file is -*- C++ -*-
2// $Id: ftmpl_array.cc,v 1.4 1997-04-30 13:08:23 schmidt Exp $
3
4/*
5$Log: not supported by cvs2svn $
6Revision 1.3  1997/04/15 09:56:36  schmidt
7#include <config.h> added
8the headers config.h and assert.h will be included
9  be makeheader now
10
11Revision 1.2  1997/03/27 10:28:51  schmidt
12error check changed to ASSERT
13
14Revision 1.1  1996/07/16 12:24:56  stobbe
15"operators += and *= deleted sincethey are not needed in an general
16array class als well as the functions sum, prod, crossprod.
17"
18
19Revision 1.0  1996/05/17 11:06:32  stobbe
20Initial revision
21
22*/
23
24#include <factoryconf.h>
25
26#include <templates/array.h>
27
28template <class T>
29Array<T>::Array() : data(0), _min(0), _max(-1), _size(0)
30{
31}
32
33template <class T>
34Array<T>::Array( const Array<T> & a )
35{
36    if ( a._size > 0 ) {
37        _min = a._min;
38        _max = a._max;
39        _size = a._size;
40        data = new T[_size];
41        for ( int i = 0; i < _size; i++ )
42            data[i] = a.data[i];
43    }
44    else {
45        data = 0;
46        _min = _size = 0;
47        _max = -1;
48    }
49}
50
51template <class T>
52Array<T>::Array( int i )
53{
54    _min = 0;
55    _max = i-1;
56    _size = i;
57    if ( i == 0 )
58        data = 0;
59    else
60        data = new T[_size];
61}
62
63template <class T>
64Array<T>::Array( int min, int max )
65{
66    if ( max < min ) {
67        _min = _size = 0;
68        _max = -1;
69        data = 0;
70    }
71    else {
72        _min = min;
73        _max = max;
74        _size = _max - _min + 1;
75        data = new T[_size];
76    }
77}
78
79template <class T>
80Array<T>::~Array()
81{
82    delete [] data;
83}
84
85template <class T>
86Array<T>& Array<T>::operator= ( const Array<T> & a )
87{
88    if ( this != &a ) {
89        delete [] data;
90        _min = a._min;
91        _max = a._max;
92        _size = a._size;
93        if ( a._size > 0 ) {
94            _size = a._size;
95            data = new T[_size];
96            for ( int i = 0; i < _size; i++ )
97                data[i] = a.data[i];
98        }
99        else {
100            data = 0;
101            _size = 0;
102        }
103    }
104    return *this;
105}
106
107template <class T>
108T& Array<T>::operator[] ( int i ) const
109{
110    ASSERT( i >= _min && i <= _max, "warning: array size mismatch." );
111    return data[i-_min];
112}
113
114template <class T>
115int Array<T>::size() const
116{
117    return _size;
118}
119
120template <class T>
121int Array<T>::min() const
122{
123    return _min;
124}
125
126template <class T>
127int Array<T>::max() const
128{
129    return _max;
130}
131
132/*
133template <class T>
134Array<T>& Array<T>::operator*= ( const T & t )
135{
136    for ( int i = 0; i < _size; i++ )
137        data[i] *= t;
138    return *this;
139}
140
141template <class T>
142Array<T>& Array<T>::operator+= ( const T & t )
143{
144    for ( int i = 0; i < _size; i++ )
145        data[i] += t;
146    return *this;
147}
148
149template <class T>
150Array<T>& Array<T>::operator+= ( const Array<T> & a )
151{
152    ASSERT ( _size == a._size, "warning: array size mismatch." );
153    for ( int i = 0; i < _size; i++ )
154        data[i] += a.data[i];
155    return *this;
156}
157*/
158
159#ifndef NOSTREAMIO
160template <class T>
161void Array<T>::print ( ostream & os ) const
162{
163    if ( _size == 0 )
164        os << "( )";
165    else {
166        os << "( " << data[0];
167        for ( int i = 1; i < _size; i++ )
168            os << ", " << data[i];
169        os << " )";
170    }
171}
172
173template <class T>
174ostream& operator<< ( ostream & os, const Array<T> & a )
175{
176    a.print( os );
177    return os;
178}
179#endif /* NOSTREAMIO */
Note: See TracBrowser for help on using the repository browser.