42 #ifndef TEUCHOS_TWODARRAY_HPP
43 #define TEUCHOS_TWODARRAY_HPP
230 static const std::string metaSeperator =
":";
231 return metaSeperator;
238 static const std::string dimensionsDelimiter =
"x";
239 return dimensionsDelimiter;
263 template<
class T>
inline
265 return _data.view(_numCols*i, _numCols);
268 template<
class T>
inline
270 return _data.view(_numCols*i, _numCols);
275 _data.resize(_numCols*numberOfRows);
276 _numRows = numberOfRows;
282 Array<T> newData(numberOfCols*_numRows);
283 size_type colLimit = (numberOfCols < _numCols ? numberOfCols : _numCols);
286 newData[i*numberOfCols+j] = _data[i*_numCols+j];
290 _numCols=numberOfCols;
296 std::stringstream numColsStream;
297 std::stringstream numRowsStream;
302 numRowsStream.str() +
304 numColsStream.str() +
312 std::string curString = string_in;
314 size_t curPos = curString.find(metaSeperator);
315 std::string dimString = curString.substr(0, curPos);
316 curString = curString.substr(curPos+1);
321 std::istringstream numRowsStream(dimString.substr(0,dimCharPos));
322 std::istringstream numColsStream(dimString.substr(dimCharPos+1));
323 size_t numRows, numCols;
324 numRowsStream >> numRows;
325 numColsStream >> numCols;
328 bool symmetrical =
false;
329 curPos = curString.find(metaSeperator);
330 if(curPos != std::string::npos){
332 curString = curString.substr(curPos+1);
336 Array<T> array = fromStringToArray<T>(curString);
340 "Error: You've specified an TwoDArray as having the dimensions of "
341 << numRows <<
"x" << numCols <<
". This means you should have " <<
342 (numRows*numCols) <<
" entries specified in your array. However you "
343 "only specified " << array.
size() <<
" entries."
348 toReturn.setSymmetrical(symmetrical);
364 template<
class T>
inline
365 std::ostream& operator<<(std::ostream& os, const TwoDArray<T>& array){
370 namespace TwoDDetails {
391 if(a1(i,j) != a2(i,j)){
443 return "TwoDArray(*)";
451 std::string formatString = getTwoDArrayTypeNameTraitsFormat();
452 size_t starPos = formatString.find(
"*");
453 std::string prefix = formatString.substr(0,starPos);
454 std::string postFix = formatString.substr(starPos+1);
464 #endif // TEUCHOS_TWODARRAY_H
TwoDArray(size_type numRows, size_type numCols, Array< T > data)
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
static std::string concreteName(const TwoDArray< T > &)
static std::string name()
static std::string toString(const TwoDArray< T > array)
Converts a given TwoDArray to a valid string representation.
std::istringstream & operator>>(std::istringstream &in, TwoDArray< T > &array)
A thin wrapper around the Array class which causes it to be interpreted as a 2D Array.
Ordinal size_type
The type of Array sizes and capacities.
#define TEUCHOSCORE_LIB_DLL_EXPORT
std::string toString(const HashSet< Key > &h)
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...
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 columns with each entry being populated with...
Partial specialization of ArrayView for const T.
bool operator==(BigUInt< n > const &a, BigUInt< n > const &b)
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.
bool symmetricCompare(const TwoDArray< T > &a1, const TwoDArray< T > &a2)
A function for comparing symmetrical arrarys.
static std::string name()
T & operator()(size_type i, size_type j)
Returns the element located at i,j.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...