My Project
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
Array< T > Class Template Reference

#include <ftmpl_array.h>

Public Member Functions

 Array ()
 
 Array (const Array< T > &)
 
 Array (int size)
 
 Array (int min, int max)
 
 ~Array ()
 
Array< T > & operator= (const Array< T > &)
 
Toperator[] (int i) const
 
int size () const
 
int min () const
 
int max () const
 
void print (OSTREAM &) const
 

Private Attributes

Tdata
 
int _min
 
int _max
 
int _size
 

Detailed Description

template<class T>
class Array< T >

Definition at line 17 of file ftmpl_array.h.

Constructor & Destructor Documentation

◆ Array() [1/4]

template<class T >
Array< T >::Array

Definition at line 6 of file ftmpl_array.cc.

6 : data(0), _min(0), _max(-1), _size(0)
7{
8}
T * data
Definition: ftmpl_array.h:19
int _min
Definition: ftmpl_array.h:20
int _max
Definition: ftmpl_array.h:21
int _size
Definition: ftmpl_array.h:22

◆ Array() [2/4]

template<class T >
Array< T >::Array ( const Array< T > &  a)

Definition at line 11 of file ftmpl_array.cc.

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 }
26}
int i
Definition: cfEzgcd.cc:132
STATIC_VAR jList * T
Definition: janet.cc:30

◆ Array() [3/4]

template<class T >
Array< T >::Array ( int  size)

Definition at line 29 of file ftmpl_array.cc.

30{
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}

◆ Array() [4/4]

template<class T >
Array< T >::Array ( int  min,
int  max 
)

Definition at line 41 of file ftmpl_array.cc.

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}
int max() const
Definition: ftmpl_array.cc:104
int min() const
Definition: ftmpl_array.cc:98

◆ ~Array()

template<class T >
Array< T >::~Array

Definition at line 57 of file ftmpl_array.cc.

58{
59 delete [] data;
60}

Member Function Documentation

◆ max()

template<class T >
int Array< T >::max

Definition at line 104 of file ftmpl_array.cc.

105{
106 return _max;
107}

◆ min()

template<class T >
int Array< T >::min

Definition at line 98 of file ftmpl_array.cc.

99{
100 return _min;
101}

◆ operator=()

template<class T >
Array< T > & Array< T >::operator= ( const Array< T > &  a)

Definition at line 63 of file ftmpl_array.cc.

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}

◆ operator[]()

template<class T >
T & Array< T >::operator[] ( int  i) const

Definition at line 85 of file ftmpl_array.cc.

86{
87 ASSERT( i >= _min && i <= _max, "warning: array size mismatch." );
88 return data[i-_min];
89}
#define ASSERT(expression, message)
Definition: cf_assert.h:99

◆ print()

template<class T >
void Array< T >::print ( OSTREAM os) const

Definition at line 138 of file ftmpl_array.cc.

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}

◆ size()

template<class T >
int Array< T >::size

Definition at line 92 of file ftmpl_array.cc.

93{
94 return _size;
95}

Field Documentation

◆ _max

template<class T >
int Array< T >::_max
private

Definition at line 21 of file ftmpl_array.h.

◆ _min

template<class T >
int Array< T >::_min
private

Definition at line 20 of file ftmpl_array.h.

◆ _size

template<class T >
int Array< T >::_size
private

Definition at line 22 of file ftmpl_array.h.

◆ data

template<class T >
T* Array< T >::data
private

Definition at line 19 of file ftmpl_array.h.


The documentation for this class was generated from the following files: