My Project
Loading...
Searching...
No Matches
ftmpl_array.cc
Go to the documentation of this file.
1/* emacs edit mode for this file is -*- C++ -*- */
2
4
5template <class T>
6Array<T>::Array() : data(0), _min(0), _max(-1), _size(0)
7{
8}
9
10template <class T>
12{
13 if ( a._size > 0 ) {
14 _min = a._min;
15 _max = a._max;
16 _size = a._size;
17 data = new T[_size];
18 for ( int i = 0; i < _size; i++ )
19 data[i] = a.data[i];
20 }
21 else {
22 data = 0;
23 _min = _size = 0;
24 _max = -1;
25 }
28template <class T>
31 _min = 0;
32 _max = i-1;
33 _size = i;
34 if ( i == 0 )
35 data = 0;
36 else
37 data = new T[_size];
38}
39
40template <class T>
42{
43 if ( max < min ) {
44 _min = _size = 0;
45 _max = -1;
46 data = 0;
47 }
48 else {
49 _min = min;
50 _max = max;
51 _size = _max - _min + 1;
52 data = new T[_size];
53 }
54}
55
56template <class T>
58{
59 delete [] data;
60}
61
62template <class T>
64{
65 if ( this != &a ) {
66 delete [] data;
67 _min = a._min;
68 _max = a._max;
69 _size = a._size;
70 if ( a._size > 0 ) {
71 _size = a._size;
72 data = new T[_size];
73 for ( int i = 0; i < _size; i++ )
74 data[i] = a.data[i];
75 }
76 else {
77 data = 0;
78 _size = 0;
79 }
80 }
81 return *this;
82}
83
84template <class T>
86{
87 ASSERT( i >= _min && i <= _max, "warning: array size mismatch." );
88 return data[i-_min];
89}
90
91template <class T>
92int Array<T>::size() const
93{
94 return _size;
95}
96
97template <class T>
98int Array<T>::min() const
99{
100 return _min;
101}
102
103template <class T>
104int Array<T>::max() const
105{
106 return _max;
107}
108
109/*
110template <class T>
111Array<T>& Array<T>::operator*= ( const T & t )
112{
113 for ( int i = 0; i < _size; i++ )
114 data[i] *= t;
115 return *this;
116}
117
118template <class T>
119Array<T>& Array<T>::operator+= ( const T & t )
120{
121 for ( int i = 0; i < _size; i++ )
122 data[i] += t;
123 return *this;
124}
125
126template <class T>
127Array<T>& Array<T>::operator+= ( const Array<T> & a )
128{
129 ASSERT ( _size == a._size, "warning: array size mismatch." );
130 for ( int i = 0; i < _size; i++ )
131 data[i] += a.data[i];
132 return *this;
133}
134*/
135
136#ifndef NOSTREAMIO
137template <class T>
138void Array<T>::print ( OSTREAM & os ) const
139{
140 if ( _size == 0 )
141 os << "( )";
142 else {
143 os << "( " << data[0];
144 for ( int i = 1; i < _size; i++ )
145 os << ", " << data[i];
146 os << " )";
147 }
148}
149
150template <class T>
152{
153 a.print( os );
154 return os;
155}
156#endif /* NOSTREAMIO */
#define OSTREAM
Definition: canonicalform.h:16
int i
Definition: cfEzgcd.cc:132
#define ASSERT(expression, message)
Definition: cf_assert.h:99
T * data
Definition: ftmpl_array.h:19
int size() const
Definition: ftmpl_array.cc:92
int _min
Definition: ftmpl_array.h:20
Array< T > & operator=(const Array< T > &)
Definition: ftmpl_array.cc:63
T & operator[](int i) const
Definition: ftmpl_array.cc:85
int _max
Definition: ftmpl_array.h:21
int max() const
Definition: ftmpl_array.cc:104
int min() const
Definition: ftmpl_array.cc:98
~Array()
Definition: ftmpl_array.cc:57
void print(OSTREAM &) const
Definition: ftmpl_array.cc:138
int _size
Definition: ftmpl_array.h:22
Array()
Definition: ftmpl_array.cc:6
static int min(int a, int b)
Definition: fast_mult.cc:268
static int max(int a, int b)
Definition: fast_mult.cc:264
OSTREAM & operator<<(OSTREAM &os, const Array< T > &a)
Definition: ftmpl_array.cc:151
STATIC_VAR jList * T
Definition: janet.cc:30