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");
95 if (listDelimiter == token::BEGIN_LIST)
97 auto iter = this->
begin();
100 for (label i = 0; i < mRows_; ++i)
104 for (label j = 0; j < nCols_; ++j, (void)++iter)
118 is.
fatalCheck(
"readMatrix : reading the single entry");
120 std::fill_n(
begin(), size(), elem);
132 <<
"incorrect first token, expected <int>, found " 133 << firstToken.info() <<
nl 140 template<
class Form,
class Type>
148 const label len = mat.
size();
165 else if (is_contiguous<Type>::value && len > 1 && mat.
uniform())
168 os << token::BEGIN_BLOCK << *iter << token::END_BLOCK;
172 (len <= 1 || !shortLen)
173 || (len <= shortLen && is_contiguous<Type>::value)
179 os << token::BEGIN_LIST;
182 for (label i = 0; i < mat.
nRows(); ++i)
185 os << token::BEGIN_LIST;
188 for (label j = 0; j < mat.
nCols(); ++j, (void)++iter)
190 if (j)
os << token::SPACE;
195 os << token::END_LIST;
199 os << token::END_LIST;
203 (mat.
nCols() <= 1 || !shortLen)
204 || (mat.
nCols() <= shortLen && is_contiguous<Type>::value)
210 os <<
nl << token::BEGIN_LIST;
213 for (label i = 0; i < mat.
nRows(); ++i)
216 os <<
nl << token::BEGIN_LIST;
219 for (label j = 0; j < mat.
nCols(); ++j, (void)++iter)
221 if (j)
os << token::SPACE;
226 os << token::END_LIST;
230 os <<
nl << token::END_LIST <<
nl;
237 os <<
nl << token::BEGIN_LIST;
240 for (label i=0; i < mat.
nRows(); ++i)
243 os <<
nl << token::BEGIN_LIST;
246 for (label j = 0; j < mat.
nCols(); ++j, (void)++iter)
252 os <<
nl << token::END_LIST;
256 os <<
nl << 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.
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.
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 '{'.
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...
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)
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing a constant 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 ...