20 template <
typename T>
class Array {
26 void alloc(
size_t size,T* ptr=0,
bool handleDelete=
false)
43 _count= (handleDelete?
new int(1): 0);
61 void copy(
const Array& A)
80 Array(): _count(0), _data(0), _size(0) {}
87 explicit Array(
size_t size) { alloc(size); }
99 Array(T* ptr,
size_t size,
bool handleDelete=
false) { alloc(size,ptr,handleDelete); }
116 for (
size_t i=0;i<A.
size();i++) _data[i] = T(A[i]) ;
128 for (
typename std::list<T>::const_iterator it=L.begin();it!=L.end();++it,++i)
144 if (size==_size)
return;
166 for (
size_t i=0;i<A.
size();i++) _data[i] = T( A[i] );
187 bool empty()
const {
return (_size==0); }
194 size_t size()
const {
return _size; }
202 const T&
operator[](
size_t i)
const { assert(i<_size);
return _data[i]; }
210 T&
operator[](
size_t i) { assert(i<_size);
return _data[i]; }
224 const T*
data()
const {
return _data; }
238 const_iterator
begin()
const {
return _data; }
245 iterator
end() {
return _data+_size; }
252 const_iterator
end()
const {
return _data+_size; }
264 for (
size_t i=0;i<A.
size();i++) {
265 A[i] = (*this)[i+offset];
288 if (A.
size() !=
size())
return false;
289 for (
size_t i=0;i<
size();i++)
290 if (!(_data[i] == A[i]))
302 return !(*
this == A);
313 const_iterator it = A.
begin();
314 std::pair<T,T> r(*it,*it);
315 for ( ++it; it != A.
end() ; ++it) {
316 r.first=std::min(r.first,*it);
317 r.second=std::max(r.second,*it);
330 const_iterator it = A.
begin();
331 std::pair<T,T> r(*it,*it);
332 for ( ++it; it != A.
end() ; ++it) {
333 r.first=pmin(r.first,*it);
334 r.second=pmax(r.second,*it);
348 out.write((
const char*)&n,
sizeof(
size_t));
349 out.write((
const char*)A._data,(std::streamsize)A._size*
sizeof(T));
361 in.read((
char*)&n,
sizeof(
size_t));
363 in.read((
char*)A._data,(std::streamsize)A._size*
sizeof(T));
376 for (
size_t i=0;i<A.
size();i++) {
378 if (i<A.size()-1) out<<
" ";
395 for (
size_t i=0;i<A.
size();i++)
friend void read(std::istream &in, Array &A)
Binary read.
Definition: Array.h:359
const T & operator[](size_t i) const
Read access.
Definition: Array.h:202
Array clone() const
Cloning.
Definition: Array.h:175
friend std::ostream & operator<<(std::ostream &out, const Array &A)
ASCII write.
Definition: Array.h:374
Array(size_t size)
Constructor (known size).
Definition: Array.h:87
Array of variable size.
Definition: Array.h:20
Array & operator=(const Array &A)
Assignment.
Definition: Array.h:154
virtual ~Array()
Destructor.
Definition: Array.h:133
bool operator==(const Array &A) const
Equality test.
Definition: Array.h:287
size_t size() const
Size.
Definition: Array.h:194
Array()
Empty constructor.
Definition: Array.h:80
bool operator!=(const Array &A) const
Inequality test.
Definition: Array.h:301
friend std::pair< T, T > range(const Array &A)
Range.
Definition: Array.h:312
Array(T *ptr, size_t size, bool handleDelete=false)
Constructor (pre-allocated).
Definition: Array.h:99
friend std::istream & operator>>(std::istream &in, Array &A)
ASCII read.
Definition: Array.h:391
Array(const std::list< T > &L)
Constructor (from list).
Definition: Array.h:125
friend std::pair< T, T > prange(const Array &A)
Pointwise range.
Definition: Array.h:329
const_iterator end() const
End const iterator.
Definition: Array.h:252
const T * data() const
Data pointer (read).
Definition: Array.h:224
T * iterator
Iterator type.
Definition: Array.h:71
void setSize(size_t size)
Change size.
Definition: Array.h:143
T * data()
Data pointer (read/write).
Definition: Array.h:217
bool empty() const
Is empty.
Definition: Array.h:187
Array(const Array &A)
Copy constructor.
Definition: Array.h:106
Array & fill(const T &x)
Filling.
Definition: Array.h:276
Array getSubArray(size_t offset, size_t size) const
Sub array.
Definition: Array.h:262
T & operator[](size_t i)
Write access.
Definition: Array.h:210
iterator begin()
Begin iterator.
Definition: Array.h:231
Imagine++ namespace.
Definition: Array.h:7
const T * const_iterator
Const iterator type.
Definition: Array.h:73
const_iterator begin() const
Begin const iterator.
Definition: Array.h:238
iterator end()
End iterator.
Definition: Array.h:245
Array(const Array< T2 > &A)
Constructor (different type).
Definition: Array.h:114
friend void write(std::ostream &out, const Array &A)
Binary write.
Definition: Array.h:346