jengelh-datetimespielwiese
Last change
on this file since b1dfaf was
b1dfaf,
checked in by Frank Seelisch <seelisch@…>, 13 years ago
|
patch from Kai (checked for problems under Windows OS: no problems)
git-svn-id: file:///usr/local/Singular/svn/trunk@13210 2c84dea3-7e68-4137-9b89-c4e89433aadc
|
-
Property mode set to
100644
|
File size:
2.5 KB
|
Rev | Line | |
---|
[6ab5981] | 1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
[341696] | 2 | /* $Id$ */ |
---|
[684544] | 3 | |
---|
[b1dfaf] | 4 | #include <factory/templates/ftmpl_array.h> |
---|
[684544] | 5 | |
---|
| 6 | template <class T> |
---|
| 7 | Array<T>::Array() : data(0), _min(0), _max(-1), _size(0) |
---|
| 8 | { |
---|
| 9 | } |
---|
| 10 | |
---|
| 11 | template <class T> |
---|
| 12 | Array<T>::Array( const Array<T> & a ) |
---|
| 13 | { |
---|
| 14 | if ( a._size > 0 ) { |
---|
| 15 | _min = a._min; |
---|
| 16 | _max = a._max; |
---|
| 17 | _size = a._size; |
---|
| 18 | data = new T[_size]; |
---|
| 19 | for ( int i = 0; i < _size; i++ ) |
---|
| 20 | data[i] = a.data[i]; |
---|
| 21 | } |
---|
| 22 | else { |
---|
| 23 | data = 0; |
---|
| 24 | _min = _size = 0; |
---|
| 25 | _max = -1; |
---|
| 26 | } |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | template <class T> |
---|
| 30 | Array<T>::Array( int i ) |
---|
| 31 | { |
---|
| 32 | _min = 0; |
---|
| 33 | _max = i-1; |
---|
| 34 | _size = i; |
---|
| 35 | if ( i == 0 ) |
---|
| 36 | data = 0; |
---|
| 37 | else |
---|
| 38 | data = new T[_size]; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | template <class T> |
---|
| 42 | Array<T>::Array( int min, int max ) |
---|
| 43 | { |
---|
| 44 | if ( max < min ) { |
---|
| 45 | _min = _size = 0; |
---|
| 46 | _max = -1; |
---|
| 47 | data = 0; |
---|
| 48 | } |
---|
| 49 | else { |
---|
| 50 | _min = min; |
---|
| 51 | _max = max; |
---|
| 52 | _size = _max - _min + 1; |
---|
| 53 | data = new T[_size]; |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | template <class T> |
---|
| 58 | Array<T>::~Array() |
---|
| 59 | { |
---|
| 60 | delete [] data; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | template <class T> |
---|
| 64 | Array<T>& Array<T>::operator= ( const Array<T> & a ) |
---|
| 65 | { |
---|
| 66 | if ( this != &a ) { |
---|
| 67 | delete [] data; |
---|
| 68 | _min = a._min; |
---|
| 69 | _max = a._max; |
---|
| 70 | _size = a._size; |
---|
| 71 | if ( a._size > 0 ) { |
---|
| 72 | _size = a._size; |
---|
| 73 | data = new T[_size]; |
---|
| 74 | for ( int i = 0; i < _size; i++ ) |
---|
| 75 | data[i] = a.data[i]; |
---|
| 76 | } |
---|
| 77 | else { |
---|
| 78 | data = 0; |
---|
| 79 | _size = 0; |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | return *this; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | template <class T> |
---|
| 86 | T& Array<T>::operator[] ( int i ) const |
---|
| 87 | { |
---|
[0bf9a2] | 88 | ASSERT( i >= _min && i <= _max, "warning: array size mismatch." ); |
---|
| 89 | return data[i-_min]; |
---|
[684544] | 90 | } |
---|
| 91 | |
---|
| 92 | template <class T> |
---|
| 93 | int Array<T>::size() const |
---|
| 94 | { |
---|
| 95 | return _size; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | template <class T> |
---|
| 99 | int Array<T>::min() const |
---|
| 100 | { |
---|
| 101 | return _min; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | template <class T> |
---|
| 105 | int Array<T>::max() const |
---|
| 106 | { |
---|
| 107 | return _max; |
---|
| 108 | } |
---|
| 109 | |
---|
[9f2b6f] | 110 | /* |
---|
[684544] | 111 | template <class T> |
---|
| 112 | Array<T>& Array<T>::operator*= ( const T & t ) |
---|
| 113 | { |
---|
| 114 | for ( int i = 0; i < _size; i++ ) |
---|
| 115 | data[i] *= t; |
---|
| 116 | return *this; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | template <class T> |
---|
| 120 | Array<T>& Array<T>::operator+= ( const T & t ) |
---|
| 121 | { |
---|
| 122 | for ( int i = 0; i < _size; i++ ) |
---|
| 123 | data[i] += t; |
---|
| 124 | return *this; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | template <class T> |
---|
| 128 | Array<T>& Array<T>::operator+= ( const Array<T> & a ) |
---|
| 129 | { |
---|
[0bf9a2] | 130 | ASSERT ( _size == a._size, "warning: array size mismatch." ); |
---|
| 131 | for ( int i = 0; i < _size; i++ ) |
---|
| 132 | data[i] += a.data[i]; |
---|
[684544] | 133 | return *this; |
---|
| 134 | } |
---|
[9f2b6f] | 135 | */ |
---|
[684544] | 136 | |
---|
[0bf9a2] | 137 | #ifndef NOSTREAMIO |
---|
[684544] | 138 | template <class T> |
---|
[181148] | 139 | void Array<T>::print ( OSTREAM & os ) const |
---|
[684544] | 140 | { |
---|
| 141 | if ( _size == 0 ) |
---|
| 142 | os << "( )"; |
---|
| 143 | else { |
---|
| 144 | os << "( " << data[0]; |
---|
| 145 | for ( int i = 1; i < _size; i++ ) |
---|
| 146 | os << ", " << data[i]; |
---|
| 147 | os << " )"; |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | template <class T> |
---|
[181148] | 152 | OSTREAM& operator<< ( OSTREAM & os, const Array<T> & a ) |
---|
[684544] | 153 | { |
---|
| 154 | a.print( os ); |
---|
| 155 | return os; |
---|
| 156 | } |
---|
[0bf9a2] | 157 | #endif /* NOSTREAMIO */ |
---|
Note: See
TracBrowser
for help on using the repository browser.