10 #include "Teuchos_TabularOutputter.hpp"
34 const std::string getFieldLine(
const int width)
37 line.append(width,
'-');
48 const std::string TabularOutputter::fieldSpacer_(
" ");
51 TabularOutputter::TabularOutputter(std::ostream &out):
74 out_ = fancyOStream(out);
79 const std::string &fieldName,
const EFieldType fieldType,
88 !(as<int>(fieldName.size()) <= width),
90 "Error, the length of the field name \""<<fieldName<<
"\"\n"
91 "is "<<fieldName.size()<<
" which is larger than the\n"
92 "specifically set field width "<<width<<
"!"
97 FieldSpec(fieldName, fieldType, fieldJustification, floatingOutputType,
98 TEUCHOS_MAX(as<int>(fieldName.size()), width)
107 fieldTypePrecision_[fieldType] = prec;
117 const int numFields =
static_cast<int>(fieldSpecs_.
size());
122 "Error, you must add at least one field spec using pushFieldSpec(...)!"
127 for (
int i = 0; i < numFields; ++i) {
128 FieldSpec &fieldSpec = fieldSpecs_[i];
129 const EFieldType fieldType = fieldSpec.fieldType;
130 const int fieldTypePrecision = fieldTypePrecision_[fieldType];
131 fieldSpec.precision = fieldTypePrecision;
132 const int fieldPrecisionWidth =
133 getFieldWidth(fieldType, fieldTypePrecision);
134 if (fieldSpec.outputWidth < fieldPrecisionWidth) {
135 fieldSpec.outputWidth = fieldPrecisionWidth;
137 *out_ << fieldSpacer_ << left << setw(fieldSpec.outputWidth) << fieldSpec.fieldName;
141 for (
int i = 0; i < numFields; ++i) {
142 const FieldSpec &fieldSpec = fieldSpecs_[i];
143 *out_ << fieldSpacer_ << left << setw(fieldSpec.outputWidth) << getFieldLine(fieldSpec.outputWidth);
154 const int numFields =
static_cast<int>(fieldSpecs_.
size());
155 if (allowRemainingFields) {
156 while (currFieldIdx_ < numFields) {
163 !(currFieldIdx_ == numFields),
165 "Error, you must call outputField(...) for every field in the row\n"
166 "before you call nextRow()!"
178 void TabularOutputter::initialize()
180 std::fill( fieldTypePrecision_.
begin(), fieldTypePrecision_.
end(), 4 );
iterator begin() const
Return an iterator to beginning of the array of data.
void outputHeader()
Output the headers.
void outputField(const T &t)
Output to the next field.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Utility class that makes it easy to create formatted tables of output.
void setFieldTypePrecision(const EFieldType fieldType, const int prec)
Set the precision of output for a field.
void pushFieldSpec(const std::string &fieldName, const EFieldType fieldType=DOUBLE, const EFieldJustification fieldJustification=RIGHT, const EFloatingOutputType floatingOutputType=SCIENTIFIC, const int width=-1)
Add a new field to be output.
void setOStream(const RCP< std::ostream > &out)
Set the ostream that all output will be sent to.
const RCP< T > & assert_not_null() const
Throws NullReferenceError if this->get()==NULL, otherwise returns reference to *this.
void push_back(const value_type &x)
iterator end() const
Return an iterator to past the end of the array of data.
Definition of Teuchos::as, for conversions between types.
void nextRow(const bool allowRemainingFields=false)
Finalize the row of output.