torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::architecture::Array< T > Class Template Reference

Encapsulation of a static array. More...

#include <Array.hpp>

+ Inheritance diagram for torc::architecture::Array< T >:
+ Collaboration diagram for torc::architecture::Array< T >:

Public Types

typedef const T * const_iterator
 Constant T iterator type. More...
 
typedef T * iterator
 Non-constant T iterator type. More...
 

Public Member Functions

 Array (void)
 Null constructor. More...
 
 Array (uint32_t inSize)
 Public constructor. More...
 
 ~Array (void)
 Non-virtual destructor. More...
 
T * begin (void)
 Returns the non-constant begin iterator. More...
 
T * end (void)
 Returns the non-constant end iterator. More...
 
const T * begin (void) const
 Returns the constant begin iterator. More...
 
const T * end (void) const
 Returns the constant end iterator. More...
 
uint32_t getSize (void) const
 Returns the array size. More...
 
void setSize (uint32_t inSize)
 Discards all contents and resizes the array. More...
 
T & operator[] (uint32_t inIndex)
 Non-constant subscript operator. More...
 
const T & operator[] (uint32_t inIndex) const
 Constant subscript operator. More...
 

Protected Types

typedef boost::uint32_t uint32_t
 Imported type name. More...
 
typedef boost::remove_const< T >
::type 
T_non_const
 A type identical to template parameter T, but with any 'const' trait removed. More...
 

Protected Attributes

T * mArray
 The internal array. More...
 
uint32_t mSize
 The logical and actual size of the array. More...
 

Private Member Functions

void allocate (uint32_t inSize)
 Allocate an array of the specified size. More...
 
void deallocate (void)
 Deallocate the array. More...
 

Detailed Description

template<class T>
class torc::architecture::Array< T >

Encapsulation of a static array.

Arrays are intended for fixed-size operation without frills, and are used extensively to represent device wiring data. Although this class could be used more broadly, it is likely that most code would be better served by raw arrays or by STL containers.

Arrays can be resized, but their contents are not retained when resized, nor are the contents cleared upon initialization.

Definition at line 39 of file Array.hpp.

Member Typedef Documentation

template<class T>
typedef const T* torc::architecture::Array< T >::const_iterator

Constant T iterator type.

Definition at line 83 of file Array.hpp.

template<class T>
typedef T* torc::architecture::Array< T >::iterator

Non-constant T iterator type.

Definition at line 85 of file Array.hpp.

template<class T>
typedef boost::remove_const<T>::type torc::architecture::Array< T >::T_non_const
protected

A type identical to template parameter T, but with any 'const' trait removed.

Definition at line 45 of file Array.hpp.

template<class T>
typedef boost::uint32_t torc::architecture::Array< T >::uint32_t
protected

Imported type name.

Definition at line 43 of file Array.hpp.

Constructor & Destructor Documentation

template<class T>
torc::architecture::Array< T >::Array ( void  )
inline

Null constructor.

Definition at line 88 of file Array.hpp.

88 : mArray(0), mSize(0) {}
T * mArray
The internal array.
Definition: Array.hpp:48
uint32_t mSize
The logical and actual size of the array.
Definition: Array.hpp:50
template<class T>
torc::architecture::Array< T >::Array ( uint32_t  inSize)
inline

Public constructor.

Definition at line 90 of file Array.hpp.

90 : mArray(0), mSize(0) { allocate(inSize); }
T * mArray
The internal array.
Definition: Array.hpp:48
void allocate(uint32_t inSize)
Allocate an array of the specified size.
Definition: Array.hpp:53
uint32_t mSize
The logical and actual size of the array.
Definition: Array.hpp:50
template<class T>
torc::architecture::Array< T >::~Array ( void  )
inline

Non-virtual destructor.

Definition at line 92 of file Array.hpp.

92 { deallocate(); }
void deallocate(void)
Deallocate the array.
Definition: Array.hpp:62

Member Function Documentation

template<class T>
void torc::architecture::Array< T >::allocate ( uint32_t  inSize)
inlineprivate

Allocate an array of the specified size.

Definition at line 53 of file Array.hpp.

53  {
54  if(mArray != 0) deallocate();
55  if(inSize > 0) {
56  // T might be a const type, so we get Boost to remove the const trait
57  mArray = new T_non_const[inSize];
58  mSize = inSize;
59  }
60  }
T * mArray
The internal array.
Definition: Array.hpp:48
boost::remove_const< T >::type T_non_const
A type identical to template parameter T, but with any 'const' trait removed.
Definition: Array.hpp:45
uint32_t mSize
The logical and actual size of the array.
Definition: Array.hpp:50
void deallocate(void)
Deallocate the array.
Definition: Array.hpp:62

+ Here is the caller graph for this function:

template<class T>
T* torc::architecture::Array< T >::begin ( void  )
inline

Returns the non-constant begin iterator.

Definition at line 95 of file Array.hpp.

95 { return mArray; }
T * mArray
The internal array.
Definition: Array.hpp:48

+ Here is the caller graph for this function:

template<class T>
const T* torc::architecture::Array< T >::begin ( void  ) const
inline

Returns the constant begin iterator.

Definition at line 99 of file Array.hpp.

99 { return mArray; }
T * mArray
The internal array.
Definition: Array.hpp:48
template<class T>
void torc::architecture::Array< T >::deallocate ( void  )
inlineprivate

Deallocate the array.

Definition at line 62 of file Array.hpp.

62  {
63  if(mArray != 0) delete[] mArray;
64  mArray = 0;
65  mSize = 0;
66  }
T * mArray
The internal array.
Definition: Array.hpp:48
uint32_t mSize
The logical and actual size of the array.
Definition: Array.hpp:50

+ Here is the caller graph for this function:

template<class T>
T* torc::architecture::Array< T >::end ( void  )
inline

Returns the non-constant end iterator.

Definition at line 97 of file Array.hpp.

97 { return mArray + mSize; }
T * mArray
The internal array.
Definition: Array.hpp:48
uint32_t mSize
The logical and actual size of the array.
Definition: Array.hpp:50

+ Here is the caller graph for this function:

template<class T>
const T* torc::architecture::Array< T >::end ( void  ) const
inline

Returns the constant end iterator.

Definition at line 101 of file Array.hpp.

101 { return mArray + mSize; }
T * mArray
The internal array.
Definition: Array.hpp:48
uint32_t mSize
The logical and actual size of the array.
Definition: Array.hpp:50
template<class T>
uint32_t torc::architecture::Array< T >::getSize ( void  ) const
inline

Returns the array size.

Definition at line 104 of file Array.hpp.

104 { return mSize; }
uint32_t mSize
The logical and actual size of the array.
Definition: Array.hpp:50

+ Here is the caller graph for this function:

template<class T>
T& torc::architecture::Array< T >::operator[] ( uint32_t  inIndex)
inline

Non-constant subscript operator.

Definition at line 110 of file Array.hpp.

110  {
111  enforceBounds(inIndex);
112  return mArray[inIndex];
113  }
#define enforceBounds(index)
Enforce array bounds if so requested.
Definition: Array.hpp:78
T * mArray
The internal array.
Definition: Array.hpp:48
template<class T>
const T& torc::architecture::Array< T >::operator[] ( uint32_t  inIndex) const
inline

Constant subscript operator.

Definition at line 115 of file Array.hpp.

115  {
116  enforceBounds(inIndex);
117  return mArray[inIndex];
118  }
#define enforceBounds(index)
Enforce array bounds if so requested.
Definition: Array.hpp:78
T * mArray
The internal array.
Definition: Array.hpp:48
template<class T>
void torc::architecture::Array< T >::setSize ( uint32_t  inSize)
inline

Discards all contents and resizes the array.

Definition at line 107 of file Array.hpp.

107 { allocate(inSize); }
void allocate(uint32_t inSize)
Allocate an array of the specified size.
Definition: Array.hpp:53

+ Here is the caller graph for this function:

Field Documentation

template<class T>
T* torc::architecture::Array< T >::mArray
protected

The internal array.

Definition at line 48 of file Array.hpp.

template<class T>
uint32_t torc::architecture::Array< T >::mSize
protected

The logical and actual size of the array.

Definition at line 50 of file Array.hpp.


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