42 #ifndef TEUCHOS_TWODARRAY_HPP 43 #define TEUCHOS_TWODARRAY_HPP 86 TwoDArray(size_type numRows, size_type numCols, T value=T()):
89 _data(
Array<T>(numCols*numRows, value)),
96 _numRows(0),_numCols(0),_data(
Array<T>()),_symmetrical(false){}
129 return _data[(i*_numCols)+j];
134 return _data[(i*_numCols)+j];
144 inline bool isEmpty(){
145 return _numRows == 0 &&
183 _symmetrical = symmetrical;
230 static const std::string metaSeperator =
":";
231 return metaSeperator;
238 static const std::string dimensionsDelimiter =
"x";
239 return dimensionsDelimiter;
251 size_type _numRows,_numCols;
254 _numRows(numRows),_numCols(numCols),_data(data){}
258 template<
class T>
inline 260 return _data.view(_numCols*i, _numCols);
263 template<
class T>
inline 265 return _data.view(_numCols*i, _numCols);
270 _data.resize(_numCols*numberOfRows);
271 _numRows = numberOfRows;
277 Array<T> newData(numberOfCols*_numRows);
278 size_type colLimit = (numberOfCols < _numCols ? numberOfCols : _numCols);
279 for(size_type i = 0; i<_numRows; i++){
280 for(size_type j = 0; j<colLimit; j++){
281 newData[i*numberOfCols+j] = _data[i*_numCols+j];
285 _numCols=numberOfCols;
291 std::stringstream numColsStream;
292 std::stringstream numRowsStream;
297 numRowsStream.str() +
299 numColsStream.str() +
307 std::string curString = string_in;
309 size_t curPos = curString.find(metaSeperator);
310 std::string dimString = curString.substr(0, curPos);
311 curString = curString.substr(curPos+1);
316 std::istringstream numRowsStream(dimString.substr(0,dimCharPos));
317 std::istringstream numColsStream(dimString.substr(dimCharPos+1));
318 size_t numRows, numCols;
319 numRowsStream >> numRows;
320 numColsStream >> numCols;
323 bool symmetrical =
false;
324 curPos = curString.find(metaSeperator);
325 if(curPos != std::string::npos){
327 curString = curString.substr(curPos+1);
331 Array<T> array = fromStringToArray<T>(curString);
335 "Error: You've specified an TwoDArray as having the dimensions of " 336 << numRows <<
"x" << numCols <<
". This means you should have " <<
337 (numRows*numCols) <<
" entries specified in your array. However you " 338 "only specified " << array.
size() <<
" entries." 343 toReturn.setSymmetrical(symmetrical);
351 std::istringstream& operator>> (std::istringstream& in,
TwoDArray<T>& array){
359 template<
class T>
inline 360 std::ostream& operator<<(std::ostream& os, const TwoDArray<T>& array){
361 return os << TwoDArray<T>::toString(array);
365 namespace TwoDDetails {
386 if(a1(i,j) != a2(i,j)){
418 return TwoDDetails::symmetricCompare(a1,a2);
438 return "TwoDArray(*)";
445 static std::string name(){
447 size_t starPos = formatString.find(
"*");
448 std::string prefix = formatString.substr(0,starPos);
449 std::string postFix = formatString.substr(starPos+1);
459 #endif // TEUCHOS_TWODARRAY_H std::string getTwoDArrayTypeNameTraitsFormat()
Get the format that is used for the specialization of the TypeName traits class for TwoDArray...
const Array< T > & getDataArray() const
Returns the 1D array that is backing this TwoDArray.
void setSymmetrical(bool symmetrical)
Sets whether or not the the TwoDArray should be interpurted as symetric.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
void clear()
delets all the entries from the TwoDArray
bool symmetricCompare(const TwoDArray< T > &a1, const TwoDArray< T > &a2)
A function for comparing symmetrical arrarys.
static std::string toString(const TwoDArray< T > array)
Converts a given TwoDArray to a valid string representation.
A thin wrapper around the Array class which causes it to be interpurted as a 2D Array.
size_type getNumCols() const
returns the number of columns in the TwoDArray.
void resizeCols(size_type numberOfCols)
Changes the number of rows in the matrix.
void resizeRows(size_type numberOfRows)
Changes the number of rows in the matrix.
size_type getNumRows() const
returns the number of rows in the TwoDArray.
Templated array class derived from the STL std::vector.
Default traits class that just returns typeid(T).name().
static const std::string & getMetaSeperator()
returns the string used to seperate meta information from actual data information when converting a T...
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
static const std::string & getDimensionsDelimiter()
returns the string used as the dimension dilimeter when convering the TwoDArray to a string...
ArrayView< T > operator[](size_type i)
Returns an ArrayView containing the contents of row i.
TwoDArray()
Constructs an empty TwoDArray.
const T & operator()(size_type i, size_type j) const
Returns the element located at i,j.
TwoDArray(size_type numRows, size_type numCols, T value=T())
Constructs a TwoDArray with the given number of rows and colums with each entry being populated with ...
static TwoDArray< T > fromString(const std::string &string)
Converts a valid string to it's corresponding TwoDArray.
bool isSymmetrical() const
A simple flag indicating whether or not this TwoDArray should be interpurted as symmetrical.
static std::string name()
T & operator()(size_type i, size_type j)
Returns the element located at i,j.
Memory-safe templated array class that encapsulates std::vector.