43 #include "Teuchos_TabularOutputter.hpp"
67 const std::string getFieldLine(
const int width)
70 line.append(width,
'-');
81 const std::string TabularOutputter::fieldSpacer_(
" ");
84 TabularOutputter::TabularOutputter(std::ostream &out)
105 out_ = fancyOStream(out);
110 const std::string &fieldName,
const EFieldType fieldType,
119 !(as<int>(fieldName.size()) <= width),
121 "Error, the length of the field name \""<<fieldName<<
"\"\n"
122 "is "<<fieldName.size()<<
" which is larger than the\n"
123 "specifically set field width "<<width<<
"!"
128 FieldSpec(fieldName, fieldType, fieldJustification, floatingOutputType,
129 TEUCHOS_MAX(as<int>(fieldName.size()), width)
138 fieldTypePrecision_[fieldType] = prec;
148 const int numFields = fieldSpecs_.
size();
153 "Error, you must add at least one field spec using pushFieldSpec(...)!"
158 for (
int i = 0; i < numFields; ++i) {
159 FieldSpec &fieldSpec = fieldSpecs_[i];
160 const EFieldType fieldType = fieldSpec.fieldType;
161 const int fieldTypePrecision = fieldTypePrecision_[fieldType];
162 fieldSpec.precision = fieldTypePrecision;
163 const int fieldPrecisionWidth =
164 getFieldWidth(fieldType, fieldTypePrecision);
165 if (fieldSpec.outputWidth < fieldPrecisionWidth) {
166 fieldSpec.outputWidth = fieldPrecisionWidth;
168 *out_ << fieldSpacer_ << left << setw(fieldSpec.outputWidth) << fieldSpec.fieldName;
172 for (
int i = 0; i < numFields; ++i) {
173 const FieldSpec &fieldSpec = fieldSpecs_[i];
174 *out_ << fieldSpacer_ << left << setw(fieldSpec.outputWidth) << getFieldLine(fieldSpec.outputWidth);
185 const int numFields = fieldSpecs_.
size();
186 if (allowRemainingFields) {
187 while (currFieldIdx_ < numFields) {
194 !(currFieldIdx_ == numFields),
196 "Error, you must call outputField(...) for every field in the row\n"
197 "before you call nextRow()!"
209 void TabularOutputter::initialize()
211 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.
Smart reference counting pointer class for automatic garbage collection.
Definition of Teuchos::as, for conversions between types.
void nextRow(const bool allowRemainingFields=false)
Finalize the row of output.