Teuchos::Array< T > Class Template Reference

Array is a templated array class derived from the STL std::vector, but with index boundschecking and an extended interface. More...

#include <Teuchos_Array.hpp>

List of all members.

Public Member Functions

 Array ()
 Empty constructor.
 Array (int n)
 Allocate an array with n elements.
 Array (int n, const T &t)
 Allocate n elements, and fill with value t.
Array< T > & append (const T &entry)
 Add a new entry at the end of the array. Resize to allow space for the new entry.
void remove (int i)
 Remove the i-th element from the array, with optional boundschecking.
int length () const
 Return number of elements in the array. Equivalent to size(), but included for backwards compatibility.
T & operator[] (int i)
 Read/Write access to a the i-th element, with optional boundschecking.
const T & operator[] (int i) const
 Read-only access to a the i-th element, with optional boundschecking.
std::string toString () const
 Write Array as a std::string.

Static Public Member Functions

static bool hasBoundsChecking ()
 Return true if Array has been compiled with boundschecking on.

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, const Array< T > &array)
 Write an Array to a stream.
int hashCode (const Array< T > &array)
std::string toString (const Array< T > &array)
Array< T > fromStringToArray (const std::string &arrayStr)
 Converts from std::string representation (as created by toString()) back into the array object.
Array< T > tuple (const T &a)
 Create an array with one entry.
Array< T > tuple (const T &a, const T &b)
 Create an array with two entries.
Array< T > tuple (const T &a, const T &b, const T &c)
 Create an array with three entries.
Array< T > tuple (const T &a, const T &b, const T &c, const T &d)
 Create an array with four entries.
Array< T > tuple (const T &a, const T &b, const T &c, const T &d, const T &e)
 Create an array with five entries.
Array< T > tuple (const T &a, const T &b, const T &c, const T &d, const T &e, const T &f)
 Create an array with six entries.
Array< T > tuple (const T &a, const T &b, const T &c, const T &d, const T &e, const T &f, const T &g)
 Create an array with seven entries.
Array< T > tuple (const T &a, const T &b, const T &c, const T &d, const T &e, const T &f, const T &g, const T &h)
 Create an array with eight entries.
Array< T > tuple (const T &a, const T &b, const T &c, const T &d, const T &e, const T &f, const T &g, const T &h, const T &i)
 Create an array with nine entries.
Array< T > tuple (const T &a, const T &b, const T &c, const T &d, const T &e, const T &f, const T &g, const T &h, const T &i, const T &j)
 Create an array with ten entries.


Detailed Description

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

Array is a templated array class derived from the STL std::vector, but with index boundschecking and an extended interface.
Examples:

ParameterList/cxx_main.cpp.

Definition at line 55 of file Teuchos_Array.hpp.


Constructor & Destructor Documentation

template<class T>
Teuchos::Array< T >::Array (  )  [inline]

Empty constructor.

Definition at line 109 of file Teuchos_Array.hpp.

template<class T>
Teuchos::Array< T >::Array ( int  n  )  [inline]

Allocate an array with n elements.

Definition at line 113 of file Teuchos_Array.hpp.

template<class T>
Teuchos::Array< T >::Array ( int  n,
const T &  t 
) [inline]

Allocate n elements, and fill with value t.

Definition at line 117 of file Teuchos_Array.hpp.


Member Function Documentation

template<class T>
Array<T>& Teuchos::Array< T >::append ( const T &  entry  )  [inline]

Add a new entry at the end of the array. Resize to allow space for the new entry.

Definition at line 68 of file Teuchos_Array.hpp.

template<class T>
void Teuchos::Array< T >::remove ( int  i  ) 

Remove the i-th element from the array, with optional boundschecking.

Definition at line 122 of file Teuchos_Array.hpp.

template<class T>
int Teuchos::Array< T >::length (  )  const [inline]

Return number of elements in the array. Equivalent to size(), but included for backwards compatibility.

Definition at line 76 of file Teuchos_Array.hpp.

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

Read/Write access to a the i-th element, with optional boundschecking.

Definition at line 131 of file Teuchos_Array.hpp.

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

Read-only access to a the i-th element, with optional boundschecking.

Definition at line 139 of file Teuchos_Array.hpp.

template<class T>
std::string Teuchos::Array< T >::toString (  )  const [inline]

Write Array as a std::string.

Definition at line 182 of file Teuchos_Array.hpp.

template<class T>
bool Teuchos::Array< T >::hasBoundsChecking (  )  [inline, static]

Return true if Array has been compiled with boundschecking on.

Definition at line 147 of file Teuchos_Array.hpp.


Friends And Related Function Documentation

template<class T>
std::ostream & operator<< ( std::ostream &  os,
const Array< T > &  array 
) [related]

Write an Array to a stream.

Definition at line 167 of file Teuchos_Array.hpp.

template<class T>
std::string toString ( const Array< T > &  array  )  [related]

Definition at line 199 of file Teuchos_Array.hpp.

template<class T>
Array< T > fromStringToArray ( const std::string &  arrayStr  )  [related]

Converts from std::string representation (as created by toString()) back into the array object.

Parameters:
arrayStr [in] The std::string representation of the array (see below).
Exceptions: If the std::string representation is not valid, then an std::exception of type InvalidArrayStringRepresentation with be thrown with a decent error message attached.

The formating of the std::string arrayStr must look like:

      {  val[0], val[1], val[2], val[3], ..., val[n-1] }

   

Currently operator>>() is used to convert the entries from their std::string representation to objects of type T. White space is unimportant and the parser keys off of ',', '{' and '}' so even newlines are allowed. In the future, a traits class might be defined that will allow for finer-grained control of how the conversion from strings to values is performed in cases where operator>>() does not exist for certain types.

Warning! Currently this function only supports reading in flat array objects for basic types like bool, int, and double and does not yet support nested arrays (i.e. no Array<Array<int> >) or other such fancy nested types. Support for nested arrays and other user defined types T can be added in the future with no impact on user code. Only the parser for the array needs to be improved. More specifically, the current implementation will not work for any types T who's std::string representation contains the characters ',' or '}'. This implementation can be modified to allow any such types by watching for the nesting of common enclosing structures like [...], {...} or (...) within each entry of the std::string representation. However, this should all just work fine on most machines for the types int, bool, float, double etc.

Warning! Trying to read in an array in std::string format of doubles in scientific notation such as {1e+2,3.53+6,...} into an array object such as Array<int> will not yield the correct results. If one wants to allow a neutral std::string representation to be read in as an Array<double> object or an Array<int> object, then general formating such as {100,3530000,...} should be used. This templated function is unable to deal std::complex type conversion issues.

Definition at line 256 of file Teuchos_Array.hpp.

template<class T>
Array< T > tuple ( const T &  a  )  [related]

Create an array with one entry.

Definition at line 333 of file Teuchos_Array.hpp.

template<class T>
Array< T > tuple ( const T &  a,
const T &  b 
) [related]

Create an array with two entries.

Definition at line 343 of file Teuchos_Array.hpp.

template<class T>
Array< T > tuple ( const T &  a,
const T &  b,
const T &  c 
) [related]

Create an array with three entries.

Definition at line 355 of file Teuchos_Array.hpp.

template<class T>
Array< T > tuple ( const T &  a,
const T &  b,
const T &  c,
const T &  d 
) [related]

Create an array with four entries.

Definition at line 368 of file Teuchos_Array.hpp.

template<class T>
Array< T > tuple ( const T &  a,
const T &  b,
const T &  c,
const T &  d,
const T &  e 
) [related]

Create an array with five entries.

Definition at line 382 of file Teuchos_Array.hpp.

template<class T>
Array< T > tuple ( const T &  a,
const T &  b,
const T &  c,
const T &  d,
const T &  e,
const T &  f 
) [related]

Create an array with six entries.

Definition at line 398 of file Teuchos_Array.hpp.

template<class T>
Array< T > tuple ( const T &  a,
const T &  b,
const T &  c,
const T &  d,
const T &  e,
const T &  f,
const T &  g 
) [related]

Create an array with seven entries.

Definition at line 415 of file Teuchos_Array.hpp.

template<class T>
Array< T > tuple ( const T &  a,
const T &  b,
const T &  c,
const T &  d,
const T &  e,
const T &  f,
const T &  g,
const T &  h 
) [related]

Create an array with eight entries.

Definition at line 433 of file Teuchos_Array.hpp.

template<class T>
Array< T > tuple ( const T &  a,
const T &  b,
const T &  c,
const T &  d,
const T &  e,
const T &  f,
const T &  g,
const T &  h,
const T &  i 
) [related]

Create an array with nine entries.

Definition at line 452 of file Teuchos_Array.hpp.

template<class T>
Array< T > tuple ( const T &  a,
const T &  b,
const T &  c,
const T &  d,
const T &  e,
const T &  f,
const T &  g,
const T &  h,
const T &  i,
const T &  j 
) [related]

Create an array with ten entries.

Definition at line 473 of file Teuchos_Array.hpp.


The documentation for this class was generated from the following file:
Generated on Tue Oct 20 12:45:26 2009 for Teuchos - Trilinos Tools Package by doxygen 1.4.7