15 #ifndef KRATOS_TABLE_STREAM_H_INCLUDED
16 #define KRATOS_TABLE_STREAM_H_INCLUDED
79 std::ostream * Output,
80 const std::string& Separator =
"|",
81 const bool UseBoldFont =
true
82 ) : mOutStream(Output),
83 mSeparator(Separator),
84 mBoldFont(UseBoldFont)
105 template<
typename TClass>
108 if (
typeid(TClass) ==
typeid(
endl)) {
109 while (mIndexColumn != 0) {
113 if (mIndexColumn == 0) {
120 *mOutStream << std::right;
124 *mOutStream << std::setw(mColumnWidths.at(mIndexColumn)) << Input;
127 *mOutStream <<
"|\n";
128 mIndexRow = mIndexRow + 1;
131 *mOutStream << mSeparator;
132 mIndexColumn = mIndexColumn + 1;
146 OutputDecimalNumber<float>(Input);
157 OutputDecimalNumber<double>(Input);
171 return mColumnHeaders.size();
188 mSeparator = Separator;
196 mBoldFont = UseBoldFont;
221 const std::string& HeaderName,
222 const int ColumnWidth
225 KRATOS_ERROR_IF(ColumnWidth < 4) <<
"Column size has to be >= 4" << std::endl;
227 mColumnHeaders.push_back(HeaderName);
228 mColumnWidths.push_back(ColumnWidth);
229 mTableWidth += ColumnWidth + mSeparator.size();
237 PrintHorizontalLine();
239 if (mBoldFont ==
true) {
241 *mOutStream <<
"\x1B[1m";
251 *mOutStream << std::right;
254 *mOutStream << std::setw(mColumnWidths.at(
i)) << mColumnHeaders.at(
i).substr(0, mColumnWidths.at(
i));
257 *mOutStream << mSeparator;
263 if (mBoldFont ==
true) {
265 *mOutStream <<
"\x1B[0m";
271 PrintHorizontalLine();
279 PrintHorizontalLine();
348 std::ostream* mOutStream;
349 std::vector<std::string> mColumnHeaders;
350 std::vector<int> mColumnWidths;
351 std::string mSeparator;
354 unsigned int mIndexRow;
355 unsigned int mIndexColumn;
358 unsigned int mTableWidth;
375 void PrintHorizontalLine()
379 for (
unsigned int i = 0;
i< mTableWidth-1; ++
i) {
391 template<
typename TClass>
392 void OutputDecimalNumber(TClass Input)
395 if (Input < 10*(mColumnWidths.at(mIndexColumn)-1) || Input > 10*mColumnWidths.at(mIndexColumn)) {
396 std::stringstream string_out;
398 << std::setiosflags(std::ios::scientific)
399 << std::setprecision(3)
401 << std::setw(mColumnWidths.at(mIndexColumn))
404 std::string string_to_print = string_out.str();
406 *mOutStream << string_to_print;
409 << std::setiosflags(std::ios::scientific)
410 << std::setprecision(3)
412 << std::setw(mColumnWidths.at(mIndexColumn))
417 *mOutStream <<
"|\n";
418 mIndexRow = mIndexRow + 1;
421 *mOutStream << mSeparator;
422 mIndexColumn = mIndexColumn + 1;
439 rSerializer.
save(
"ColumnHeaders", mColumnHeaders);
440 rSerializer.
save(
"ColumnWidths", mColumnWidths);
441 rSerializer.
save(
"Separator", mSeparator);
442 rSerializer.
save(
"IndexRow", mIndexRow);
443 rSerializer.
save(
"IndexColumn", mIndexColumn);
444 rSerializer.
save(
"TableWidth", mTableWidth);
445 rSerializer.
save(
"FlushLeft", mFlushLeft);
446 rSerializer.
save(
"BoldFont", mBoldFont);
452 rSerializer.
load(
"ColumnHeaders", mColumnHeaders);
453 rSerializer.
load(
"ColumnWidths", mColumnWidths);
454 rSerializer.
load(
"Separator", mSeparator);
455 rSerializer.
load(
"IndexRow", mIndexRow);
456 rSerializer.
load(
"IndexColumn", mIndexColumn);
457 rSerializer.
load(
"TableWidth", mTableWidth);
458 rSerializer.
load(
"FlushLeft", mFlushLeft);
459 rSerializer.
load(
"BoldFont", mBoldFont);
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void load(std::string const &rTag, TDataType &rObject)
Definition: serializer.h:207
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
This is a fancy table to stream data in a fancy way.
Definition: table_stream.h:64
Definition: table_stream.h:55
void AddColumn(const std::string &HeaderName, const int ColumnWidth)
Add a column to our table.
Definition: table_stream.h:220
TableStream & operator<<(TClass Input)
This is the operator << for any kind of input.
Definition: table_stream.h:106
void SetFlushLeft()
Set the flush orientation to the left.
Definition: table_stream.h:202
TableStream(std::ostream *Output, const std::string &Separator="|", const bool UseBoldFont=true)
Default constructor.
Definition: table_stream.h:78
void SetFlushRight()
Set the flush orientation to the right.
Definition: table_stream.h:210
void PrintHeader()
This function prints the header of the stream.
Definition: table_stream.h:235
void PrintFooter()
This function prints the footer of the stream.
Definition: table_stream.h:277
void SetSeparator(const std::string &Separator)
Set the separator used for the table.
Definition: table_stream.h:186
TableStream & operator<<(float Input)
This is the operator << just for floats.
Definition: table_stream.h:144
unsigned int GetNumColumns() const
It returns the number of columns.
Definition: table_stream.h:169
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
unsigned int GetTableWidth() const
It returns the table width.
Definition: table_stream.h:178
TableStream & operator<<(double Input)
This is the operator << just for doubles.
Definition: table_stream.h:155
virtual ~TableStream()=default
Destructor.
KRATOS_CLASS_POINTER_DEFINITION(TableStream)
Pointer definition of TableStream.
void SetBold(const bool &UseBoldFont)
Set if the bold fonts are used for the table.
Definition: table_stream.h:194
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
left
Definition: exact_hinsberg_test.py:140
def load(f)
Definition: ode_solve.py:307
integer i
Definition: TensorModule.f:17