43#include "Teuchos_TabularOutputter.hpp"
67const std::string getFieldLine(
const int width)
70 line.append(width,
'-');
81const std::string TabularOutputter::fieldSpacer_(
" ");
112 const std::string &fieldName,
const EFieldType fieldType,
121 !(
as<int>(fieldName.size()) <= width),
123 "Error, the length of the field name \""<<fieldName<<
"\"\n"
124 "is "<<fieldName.size()<<
" which is larger than the\n"
125 "specifically set field width "<<width<<
"!"
129 fieldSpecs_.push_back(
130 FieldSpec(fieldName, fieldType, fieldJustification, floatingOutputType,
131 TEUCHOS_MAX(
as<int>(fieldName.size()), width)
140 fieldTypePrecision_[fieldType] = prec;
150 const int numFields =
static_cast<int>(fieldSpecs_.size());
155 "Error, you must add at least one field spec using pushFieldSpec(...)!"
160 for (
int i = 0; i < numFields; ++i) {
161 FieldSpec &fieldSpec = fieldSpecs_[i];
162 const EFieldType fieldType = fieldSpec.fieldType;
163 const int fieldTypePrecision = fieldTypePrecision_[fieldType];
164 fieldSpec.precision = fieldTypePrecision;
165 const int fieldPrecisionWidth =
166 getFieldWidth(fieldType, fieldTypePrecision);
167 if (fieldSpec.outputWidth < fieldPrecisionWidth) {
168 fieldSpec.outputWidth = fieldPrecisionWidth;
170 *out_ << fieldSpacer_ << left << setw(fieldSpec.outputWidth) << fieldSpec.fieldName;
174 for (
int i = 0; i < numFields; ++i) {
175 const FieldSpec &fieldSpec = fieldSpecs_[i];
176 *out_ << fieldSpacer_ << left << setw(fieldSpec.outputWidth) << getFieldLine(fieldSpec.outputWidth);
187 const int numFields =
static_cast<int>(fieldSpecs_.size());
188 if (allowRemainingFields) {
189 while (currFieldIdx_ < numFields) {
196 !(currFieldIdx_ == numFields),
198 "Error, you must call outputField(...) for every field in the row\n"
199 "before you call nextRow()!"
211void TabularOutputter::initialize()
213 std::fill( fieldTypePrecision_.
begin(), fieldTypePrecision_.
end(), 4 );
Definition of Teuchos::as, for conversions between types.
iterator end() const
Return an iterator to past the end of the array of data.
iterator begin() const
Return an iterator to beginning of the array of data.
Smart reference counting pointer class for automatic garbage collection.
RCP< T > rcpFromRef(T &r)
Return a non-owning weak RCP object from a raw object reference for a defined type.
const RCP< T > & assert_not_null() const
Throws NullReferenceError if this->get()==NULL, otherwise returns reference to *this.
Utility class that makes it easy to create formatted tables of output.
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 nextRow(const bool allowRemainingFields=false)
Finalize the row of output.
void outputHeader()
Output the headers.
void setFieldTypePrecision(const EFieldType fieldType, const int prec)
Set the precision of output for a field.
TabularOutputter(std::ostream &out)
void setOStream(const RCP< std::ostream > &out)
Set the ostream that all output will be sent to.
void outputField(const T &t)
Output to the next field.
RCP< basic_FancyOStream< char > > fancyOStream(const RCP< std::basic_ostream< char > > &oStream, const std::basic_string< char > &tabIndentStr=" ", const int startingTab=0, const bool showLinePrefix=false, const int maxLenLinePrefix=10, const bool showTabCount=false, const bool showProcRank=false)
Dynamically allocate a FancyOStream and return it wrapped in an RCP object.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...