10#ifndef TEUCHOS_TWODARRAY_HPP
11#define TEUCHOS_TWODARRAY_HPP
58 _data(
Array<T>(numCols*numRows, value)),
65 _numRows(0),_numCols(0),_data(
Array<T>()),_symmetrical(false){}
98 return _data[(i*_numCols)+j];
103 return _data[(i*_numCols)+j];
113 inline bool isEmpty(){
114 return _numRows == 0 &&
152 _symmetrical = symmetrical;
199 static const std::string metaSeperator =
":";
200 return metaSeperator;
207 static const std::string dimensionsDelimiter =
"x";
208 return dimensionsDelimiter;
232template<
class T>
inline
234 return _data.
view(_numCols*i, _numCols);
237template<
class T>
inline
239 return _data.
view(_numCols*i, _numCols);
244 _data.resize(_numCols*numberOfRows);
245 _numRows = numberOfRows;
251 Array<T> newData(numberOfCols*_numRows);
252 size_type colLimit = (numberOfCols < _numCols ? numberOfCols : _numCols);
255 newData[i*numberOfCols+j] = _data[i*_numCols+j];
259 _numCols=numberOfCols;
265 std::stringstream numColsStream;
266 std::stringstream numRowsStream;
271 numRowsStream.str() +
273 numColsStream.str() +
281 std::string curString = string_in;
283 size_t curPos = curString.find(metaSeperator);
284 std::string dimString = curString.substr(0, curPos);
285 curString = curString.substr(curPos+1);
290 std::istringstream numRowsStream(dimString.substr(0,dimCharPos));
291 std::istringstream numColsStream(dimString.substr(dimCharPos+1));
292 size_t numRows, numCols;
293 numRowsStream >> numRows;
294 numColsStream >> numCols;
297 bool symmetrical =
false;
298 curPos = curString.find(metaSeperator);
299 if(curPos != std::string::npos){
301 curString = curString.substr(curPos+1);
308 const size_t maxSize =
309 static_cast<size_t>(std::numeric_limits<typename Array<T>::size_type>::max());
312 "Error: TwoDArray dimensions " << numRows <<
"x" << numCols
313 <<
" exceed the maximum array size of " << maxSize <<
"."
318 "Error: You've specified an TwoDArray as having the dimensions of "
319 << numRows <<
"x" << numCols <<
". This means you should have " <<
320 expectedSize <<
" entries specified in your array. However you "
321 "only specified " << array.
size() <<
" entries."
334std::istringstream& operator>> (std::istringstream& in,
TwoDArray<T>& array){
342template<
class T>
inline
343std::ostream& operator<<(std::ostream& os,
const TwoDArray<T>& array){
344 return os << TwoDArray<T>::toString(array);
348namespace TwoDDetails {
369 if(a1(i,j) != a2(i,j)){
396bool operator==(
const TwoDArray<T> &a1,
const TwoDArray<T> &a2 ){
397 if(a1.isSymmetrical() != a2.isSymmetrical()){
400 if(a1.isSymmetrical()){
404 return a1.getDataArray() == a2.getDataArray() &&
405 a1.getNumRows() == a2.getNumRows() &&
406 a1.getNumCols() == a2.getNumCols();
421 return "TwoDArray(*)";
428 static std::string name(){
430 size_t starPos = formatString.find(
"*");
431 std::string prefix = formatString.substr(0,starPos);
432 std::string postFix = formatString.substr(starPos+1);
Templated array class derived from the STL std::vector.
bool symmetricCompare(const TwoDArray< T > &a1, const TwoDArray< T > &a2)
A function for comparing symmetrical arrarys.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
Ordinal size_type
The type of Array sizes and capacities.
Array< T > fromStringToArray(const std::string &arrayStr)
Converts from std::string representation (as created by toString()) back into the array object.
ArrayView< T > view(size_type offset, size_type size) const
Return a view of a contiguous range of elements.
A thin wrapper around the Array class which causes it to be interpreted as a 2D Array.
void resizeRows(size_type numberOfRows)
Changes the number of rows in the matrix.
const T & operator()(size_type i, size_type j) const
Returns the element located at i,j.
size_type getNumCols() const
returns the number of columns in the TwoDArray.
static const std::string & getDimensionsDelimiter()
returns the string used as the dimension dilimeter when convering the TwoDArray to a string.
T & operator()(size_type i, size_type j)
Returns the element located at i,j.
void resizeCols(size_type numberOfCols)
Changes the number of rows in the matrix.
void clear()
delets all the entries from the TwoDArray
size_type getNumRows() const
returns the number of rows in the TwoDArray.
std::string getTwoDArrayTypeNameTraitsFormat()
Get the format that is used for the specialization of the TypeName traits class for TwoDArray.
static const std::string & getMetaSeperator()
returns the string used to seperate meta information from actual data information when converting a T...
TwoDArray()
Constructs an empty TwoDArray.
static TwoDArray< T > fromString(const std::string &string)
Converts a valid string to it's corresponding TwoDArray.
const Array< T > & getDataArray() const
Returns the 1D array that is backing this TwoDArray.
bool isSymmetrical() const
A simple flag indicating whether or not this TwoDArray should be interpurted as symmetrical.
void setSymmetrical(bool symmetrical)
Sets whether or not the the TwoDArray should be interpurted as symetric.
static std::string toString(const TwoDArray< T > array)
Converts a given TwoDArray to a valid string representation.
TwoDArray(size_type numRows, size_type numCols, T value=T())
Constructs a TwoDArray with the given number of rows and columns with each entry being populated with...
ArrayView< T > operator[](size_type i)
Returns an ArrayView containing the contents of row i.
Default traits class that just returns typeid(T).name().
static std::string name()
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...