38 template<
class Form,
class Type>
51 template<
class Form,
class Type>
61 is.
fatalCheck(
"readMatrix : reading first token");
63 if (firstToken.isLabel())
65 mRows_ = firstToken.labelToken();
70 const label len = size();
78 Detail::readContiguous<Type>
85 is.fatalCheck(
"readMatrix : reading the binary block");
96 if (listDelimiter == token::BEGIN_LIST)
101 for (label i = 0; i < mRows_; ++i)
105 for (label j = 0; j < nCols_; ++j)
119 is.
fatalCheck(
"readMatrix : reading the single entry");
133 <<
"incorrect first token, expected <int>, found " 134 << firstToken.info() <<
nl 141 template<
class Form,
class Type>
151 const label len = mat.
size();
170 const Type* v = mat.
cdata();
173 if (len > 1 && is_contiguous<Type>::value && mat.
uniform())
176 os << token::BEGIN_BLOCK << v[0] << token::END_BLOCK;
178 else if (len < shortLen && is_contiguous<Type>::value)
181 os << token::BEGIN_LIST;
186 for (label i = 0; i < mat.
nRows(); ++i)
188 os << token::BEGIN_LIST;
191 for (label j = 0; j < mat.
nCols(); ++j)
193 if (j)
os << token::SPACE;
197 os << token::END_LIST;
201 os << token::END_LIST;
206 os <<
nl << token::BEGIN_LIST;
211 for (label i=0; i < mat.
nRows(); ++i)
213 os <<
nl << token::BEGIN_LIST;
216 for (label j = 0; j < mat.
nCols(); ++j)
218 os <<
nl << v[idx++];
221 os <<
nl << token::END_LIST;
225 os <<
nl << token::END_LIST <<
nl;
231 os << token::BEGIN_LIST << token::END_LIST <<
nl;
errorManipArg< error, int > exit(error &err, const int errNo=1)
char readEndList(const char *funcName)
End read of list data, ends with ')' or '}'.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
A token holds an item read from Istream.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
bool readMatrix(Istream &is)
Read Matrix from Istream, discarding existing contents.
label nCols() const noexcept
The number of columns - same as n()
Ostream & writeMatrix(Ostream &os, const label shortLen=0) const
Write Matrix, with line-breaks in ASCII when length exceeds shortLen.
label size() const
The number of elements in Matrix (m*n)
label nRows() const noexcept
The number of rows - same as m()
bool uniform() const
True if all entries have identical values, and Matrix is non-empty.
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{'.
const Type * cdata() const noexcept
Return const pointer to the first data element, which can also be used to address into Matrix content...
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order: ...
An Ostream is an abstract base class for all output systems (streams, files, token lists...
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the Matrix data, no runtime check that the type is actually contiguous...
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
OBJstream os(runTime.globalPath()/outputName)
const char * cdata_bytes() const noexcept
Return pointer to the underlying array serving as data storage, reinterpreted as byte data...
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
A template class to specify that a data type can be considered as being contiguous in memory...
Matrix() noexcept
Default construct (empty matrix)
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
streamFormat format() const noexcept
Get the current stream format.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...