36 template<
class Form,
class Type>
47 template<
class Form,
class Type>
57 is.
fatalCheck(
"readMatrix : reading first token");
59 if (firstToken.isLabel())
61 mRows_ = firstToken.labelToken();
66 const label len = size();
68 if (is.
format() == IOstreamOption::BINARY && is_contiguous_v<Type>)
74 Detail::readContiguous<Type>
81 is.fatalCheck(
"readMatrix : reading the binary block");
91 if (listDelimiter == token::BEGIN_LIST)
93 auto iter = this->begin();
96 for (label i = 0; i < mRows_; ++i)
100 for (label j = 0; j < nCols_; ++j, (void)++iter)
114 is.
fatalCheck(
"readMatrix : reading the single entry");
116 std::fill_n(begin(), size(), elem);
128 <<
"incorrect first token, expected <int>, found " 129 << firstToken.info() <<
nl 136 template<
class Form,
class Type>
144 const label len = mat.
size();
149 os << mat.
nRows() << token::SPACE << mat.
nCols();
151 if (os.
format() == IOstreamOption::BINARY && is_contiguous_v<Type>)
161 else if (is_contiguous_v<Type> && len > 1 && mat.
uniform())
164 os << token::BEGIN_BLOCK << *iter << token::END_BLOCK;
168 (len <= 1 || !shortLen)
169 || (len <= shortLen && is_contiguous_v<Type>)
175 os << token::BEGIN_LIST;
178 for (label i = 0; i < mat.
nRows(); ++i)
181 os << token::BEGIN_LIST;
184 for (label j = 0; j < mat.
nCols(); ++j, (void)++iter)
186 if (j) os << token::SPACE;
191 os << token::END_LIST;
195 os << token::END_LIST;
199 (mat.
nCols() <= 1 || !shortLen)
200 || (mat.
nCols() <= shortLen && is_contiguous_v<Type>)
206 os <<
nl << token::BEGIN_LIST;
209 for (label i = 0; i < mat.
nRows(); ++i)
212 os <<
nl << token::BEGIN_LIST;
215 for (label j = 0; j < mat.
nCols(); ++j, (void)++iter)
217 if (j) os << token::SPACE;
222 os << token::END_LIST;
226 os <<
nl << token::END_LIST <<
nl;
233 os <<
nl << token::BEGIN_LIST;
236 for (label i=0; i < mat.
nRows(); ++i)
239 os <<
nl << token::BEGIN_LIST;
242 for (label j = 0; j < mat.
nCols(); ++j, (void)++iter)
248 os <<
nl << token::END_LIST;
252 os <<
nl << token::END_LIST <<
nl;
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr Matrix() noexcept
Default construct (empty matrix)
virtual bool check(const char *operation) const
Check IOstream status for given operation.
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.
Ostream & writeMatrix(Ostream &os, const label shortLen=0) const
Write Matrix, with line-breaks in ASCII when length exceeds shortLen.
label nRows() const noexcept
The number of rows.
bool uniform() const
True if all entries have identical values, and Matrix is non-empty.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
label size() const noexcept
The number of elements in Matrix (m*n)
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{'.
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...
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.
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing a constant Matrix.
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 ...