10#ifndef TEUCHOS_TABULAR_OUTPUTTER_HPP
11#define TEUCHOS_TABULAR_OUTPUTTER_HPP
14#include "Teuchos_FancyOStream.hpp"
16#include "Teuchos_Tuple.hpp"
19#include "Teuchos_Exceptions.hpp"
37 enum { numFieldTypes = 3 };
41 enum { numFieldJustifications = 2 };
45 enum { numFloatingOutputTypes = 2 };
48 class MissingFieldsError :
public ExceptionBase
49 {
public:MissingFieldsError(
const std::string& what_arg) : ExceptionBase(what_arg) {}};
52 class InvalidFieldSpecError :
public ExceptionBase
53 {
public:InvalidFieldSpecError(
const std::string& what_arg) : ExceptionBase(what_arg) {}};
56 class MissingHeaderError :
public ExceptionBase
57 {
public:MissingHeaderError(
const std::string& what_arg) : ExceptionBase(what_arg) {}};
60 class InvalidFieldOutputError :
public ExceptionBase
61 {
public:InvalidFieldOutputError(
const std::string& what_arg) : ExceptionBase(what_arg) {}};
96 void nextRow(
const bool allowRemainingFields =
false);
103 FieldSpec(std::string fieldName_in,
EFieldType fieldType_in,
106 const int outputWidth_in
108 :fieldName(fieldName_in), fieldType(fieldType_in),
109 fieldJustification(fieldJustification_in),
110 floatingOutputType(floatingOutputType_in),
111 outputWidth(outputWidth_in),
114 std::string fieldName;
115 EFieldType fieldType;
116 EFieldJustification fieldJustification;
117 EFloatingOutputType floatingOutputType;
124 static const std::string fieldSpacer_;
129#pragma warning(disable:4251)
131 Array<FieldSpec> fieldSpecs_;
132 RCP<FancyOStream> out_;
133 Tuple<int,numFieldTypes> fieldTypePrecision_;
147 double adjustTime(
const double &time_in )
149 return ( time_in > 0.0 ? time_in : -1.0 );
154 void startTimer(
const int numLoops)
158 numLoops_ = numLoops;
167 const double relTime =
168 adjustTime(timer_.totalElapsedTime()) / numLoops_;
182#define TEUCHOS_START_PERF_OUTPUT_TIMER(OUTPUTTER, NUMLOOPS) \
183 (OUTPUTTER).startTimer(NUMLOOPS); \
184 for ( int k = 0; k < (NUMLOOPS); ++k )
188#define TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(OUTPUTTER, NUMLOOPS, NUMINNERLOOPS) \
189 (OUTPUTTER).startTimer((NUMLOOPS)*(NUMINNERLOOPS)); \
190 for ( int k = 0; k < (NUMLOOPS); ++k )
194#define TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(OUTPUTTER, NUMLOOPS, NUMINNERLOOPS) \
195 (OUTPUTTER).startTimer((NUMLOOPS)*(NUMINNERLOOPS)); \
196 for ( int k = 0; k < (NUMLOOPS); ++k )
202#define TEUCHOS_END_PERF_OUTPUT_TIMER(OUTPUTTER, VARNAME) \
203 const double VARNAME = (OUTPUTTER).stopTimer(); \
204 (OUTPUTTER).outputField(VARNAME)
222 "Error, you can not output a field until you print the header with"
226 !(currFieldIdx_ <
as<int>(fieldSpecs_.size())),
228 "Error, you have already output all of the "
229 << fieldSpecs_.size() <<
" fields for this tabular output."
230 " You must call nextRow() before outputting to the next row."
234 FieldSpec &fieldSpec = fieldSpecs_[currFieldIdx_];
236 *out_ << fieldSpacer_ << std::setprecision(fieldSpec.precision);
238 switch(fieldSpec.fieldJustification) {
250 switch(fieldSpec.floatingOutputType) {
252 *out_ << std::scientific;
262 *out_ << setw(fieldSpec.outputWidth) << t;
Templated array class derived from the STL std::vector.
Reference-counted pointer class and non-member templated function implementations.
Basic wall-clock timer class.
Smart reference counting pointer class for automatic garbage collection.
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.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call.
#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,...