140 const T&
operator[](
const int pos)
const {
return m_ptr[pos-m_first];}
149 int Last()
const {
return m_last;}
152 void Init(
const int len);
154 void Init(
const Range& r);
189 m_length = m_last - m_first + 1;
194 Init(
Range(m_first , m_last));
196 memcpy( m_ptr , cpy.
m_ptr , m_length *
sizeof( T ) );
212 Init(
Range(m_first , m_last));
214 memcpy( m_ptr , rhs.
m_ptr , m_length *
sizeof( T ) );
248 m_length = m_last - m_first + 1;
252 m_ptr =
new T[ m_length ];
300 TwoDArray(
const int height ,
const int width ){Init(height , width);}
307 TwoDArray(
const int height ,
const int width , T val);
345 void Resize(
const int height,
const int width);
352 inline element_type&
operator[](
const int pos){
return m_array_of_rows[pos];}
359 inline const element_type&
operator[](
const int pos)
const {
return m_array_of_rows[pos];}
374 int LastX()
const {
return m_last_x; }
377 int LastY()
const {
return m_last_y; }
381 void Init(
const int height,
const int width);
404 Init( height , width );
405 std::fill_n( m_array_of_rows[0], m_length_x*m_length_y, val);
416 m_length_x = m_last_x - m_first_x + 1;
417 m_length_y = m_last_y - m_first_y + 1;
419 if (m_first_x == 0 && m_first_y == 0)
420 Init(m_length_y , m_length_x);
425 memcpy( m_array_of_rows[0] , (Cpy.
m_array_of_rows)[0] , m_length_x * m_length_y *
sizeof( T ) );
442 m_length_x = m_last_x - m_first_x + 1;
443 m_length_y = m_last_y - m_first_y + 1;
445 if (m_first_x == 0 && m_first_y == 0)
446 Init(m_length_y , m_length_x);
452 memcpy( m_array_of_rows[0], (rhs.
m_array_of_rows)[0], m_length_x * m_length_y *
sizeof( T ) );
465 int rows = std::min (m_length_y, out.
m_length_y);
466 int cols = std::min (m_length_x, out.
m_length_x);
467 for (
int j = 0; j < rows; ++j)
469 memcpy( out.
m_array_of_rows[j], m_array_of_rows[j], cols *
sizeof( T )) ;
484 if (m_length_x && m_length_y)
485 std::fill_n( m_array_of_rows[0], m_length_x*m_length_y, val);
491 if (height != m_length_y || width != m_length_x)
494 Init(height , width);
509 m_last_x = m_length_x-1;
510 m_last_y = m_length_y-1;
515 m_array_of_rows =
new element_type[ m_length_y ];
520 m_array_of_rows[0] =
new T[ m_length_x * m_length_y ];
523 for (
int j=1 ; j<m_length_y ; ++j)
524 m_array_of_rows[j] = m_array_of_rows[0] + j * m_length_x;
541 m_array_of_rows = NULL;
552 delete[] m_array_of_rows[0];
555 m_length_y = m_length_x = 0;
557 delete[] m_array_of_rows;
565 std::ostream & operator<< (std::ostream & stream, TwoDArray<T> & array)
567 for (
int j=0 ; j<array.LengthY() ; ++j)
569 for (
int i=0 ; i<array.LengthX() ; ++i)
571 stream << array[j][i] <<
" ";
583 for (
int j=0 ; j<array.
LengthY() ; ++j)
585 for (
int i=0 ; i<array.
LengthX() ; ++i)
587 stream >> array[j][i];
Definition of class SequenceHeaderByteIO.
Definition: accessunit_byteio.h:51
element_type & operator[](const int pos)
Element access.
Definition: arrays.h:352
A template class for two-dimensional arrays.
Definition: arrays.h:284
void Init(const int len)
Definition: arrays.h:234
int LastY() const
Returns the index of the first element of a column.
Definition: arrays.h:377
int m_last_y
Definition: arrays.h:390
int m_last_x
Definition: arrays.h:389
std::istream & operator>>(std::istream &stream, TwoDArray< T > &array)
A function for inserting array data.
Definition: arrays.h:581
int m_fst
Definition: arrays.h:76
void Resize(const int height, const int width)
Resizes the array, deleting the current data.
Definition: arrays.h:489
int m_length
Definition: arrays.h:159
int First() const
Returns the start of the range.
Definition: arrays.h:70
int Length() const
Returns the length of the array.
Definition: arrays.h:143
bool CopyContents(TwoDArray< T > &out) const
Copy Contents.
Definition: arrays.h:461
int First() const
Returns the index of the first element.
Definition: arrays.h:146
int Last() const
Returns the index of the last element.
Definition: arrays.h:149
void Fill(T val)
Fill contents.
Definition: arrays.h:482
TwoDArray< T > & operator=(const TwoDArray< T > &rhs)
Assignment =.
Definition: arrays.h:430
A template class for one-dimensional arrays.
Definition: arrays.h:89
int m_first_x
Definition: arrays.h:386
Range(int s, int e)
Constructor.
Definition: arrays.h:67
int m_last
Definition: arrays.h:158
void Resize(int l)
Resize the array, throwing away the current data.
Definition: arrays.h:221
int LastX() const
Returns the index of the last element of a row.
Definition: arrays.h:374
const T & operator[](const int pos) const
Element access.
Definition: arrays.h:140
int FirstY() const
Returns the index of the first element of a column.
Definition: arrays.h:371
TwoDArray(const int height, const int width)
Constructor.
Definition: arrays.h:300
element_type * m_array_of_rows
Definition: arrays.h:395
int m_lst
Definition: arrays.h:76
const element_type & operator[](const int pos) const
Element access.
Definition: arrays.h:359
int m_length_y
Definition: arrays.h:393
T * m_ptr
Definition: arrays.h:160
int FirstX() const
Returns the index of the first element of a row.
Definition: arrays.h:368
int Last() const
Returns the end point of the range.
Definition: arrays.h:73
int m_length_x
Definition: arrays.h:392
OneDArray< T > & operator=(const OneDArray< T > &rhs)
Assignment=.
Definition: arrays.h:200
T * element_type
Definition: arrays.h:286
int LengthY() const
Returns the height.
Definition: arrays.h:365
void FreeData()
Free all the allocated data.
Definition: arrays.h:546
int m_first_y
Definition: arrays.h:387
T & operator[](const int pos)
Element access.
Definition: arrays.h:137
void Init(const int height, const int width)
Initialise the array.
Definition: arrays.h:502
int m_first
Definition: arrays.h:158
OneDArray()
Default constructor.
Definition: arrays.h:167
int LengthX() const
Returns the width.
Definition: arrays.h:362
void FreePtr()
Definition: arrays.h:264
Range type.
Definition: arrays.h:60
~OneDArray()
Destructor.
Definition: arrays.h:116
TwoDArray()
Default constructor.
Definition: arrays.h:294
virtual ~TwoDArray()
Destructor.
Definition: arrays.h:313