ICAROUS
All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Modules Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
larcfm::SeparatedOutput Class Reference

#include <SeparatedOutput.h>

Inheritance diagram for larcfm::SeparatedOutput:
larcfm::ErrorReporter

Public Member Functions

 SeparatedOutput ()
 
 SeparatedOutput (std::ostream *w)
 
SeparatedOutputoperator= (const SeparatedOutput &x)
 
void close ()
 
std::string getHeading (int i)
 
long length ()
 
long size ()
 
void setOutputUnits (bool output)
 
void setHeading (int i, const std::string &name, const std::string &unit)
 
void addHeading (const std::string &name, const std::string &unit)
 
void addHeading (const std::vector< std::string > &names, const std::vector< std::string > &units)
 
void addHeading (const std::vector< std::string > &names_and_units)
 
int findHeading (const std::string &heading, bool caseSensitive)
 
int findHeading (const std::string &heading1, const std::string &heading2, bool caseSensitive)
 
int findHeading (const std::string &heading1, const std::string &heading2, const std::string &heading3, bool caseSensitive)
 
int findHeading (const std::string &heading1, const std::string &heading2, const std::string &heading3, const std::string &heading4, bool caseSensitive)
 
std::string getUnit (int i)
 
void setColumn (int i, double val)
 
void setColumn (double val)
 
void setColumn (int i, const std::string &val)
 
void addColumn (const std::string &val)
 
void addColumn (const std::vector< std::string > &vals)
 
void setColumnDelimiterTab ()
 
void setColumnDelimiterComma ()
 
void setColumnDelimiterSpace ()
 
void setColumnSpace (int num)
 
void setEmptyValue (std::string e)
 
void setCommentCharacter (const std::string &c)
 
void setParameters (const ParameterData &pr)
 
void setParameter (const std::string &key, const std::string &value)
 
void clearParameters ()
 
void addComment (const std::string &c)
 
void writeLine ()
 
void flush ()
 
std::string toString ()
 
bool hasError () const
 
bool hasMessage () const
 
std::string getMessage ()
 
std::string getMessageNoClear () const
 

Private Member Functions

void init ()
 
void print_line (std::vector< std::string > vals)
 

Private Attributes

std::ostream * writer
 
ErrorLog error
 
bool header
 
std::vector< std::string > header_str
 
bool bunits
 
std::vector< std::string > units_str
 
std::vector< std::string > line_str
 
long size_l
 
int column_count
 
int header_count
 
char delim
 
std::string space
 
std::string comment_char
 
std::string empty
 
std::vector< std::string > comments
 
std::vector< std::string > params
 

Detailed Description

A class to writes a separated value file (separated by commas, spaces, or tabs).

only one file can be created from an object.

Future: handle a memory buffer, standard output/error, file, socket?

Constructor & Destructor Documentation

◆ SeparatedOutput() [1/2]

larcfm::SeparatedOutput::SeparatedOutput ( )

Create an "empty" separated output

◆ SeparatedOutput() [2/2]

larcfm::SeparatedOutput::SeparatedOutput ( std::ostream *  w)

Create a new SeparatedOutput from the given writer

Parameters
wwriter object

Create a new SeparatedInput from the given reader

Member Function Documentation

◆ addColumn() [1/2]

void larcfm::SeparatedOutput::addColumn ( const std::string &  val)

Adds the given value to the next column.

Parameters
valvalue

Adds the given value to the next column.

◆ addColumn() [2/2]

void larcfm::SeparatedOutput::addColumn ( const std::vector< std::string > &  vals)

Adds each of the given values to the next columns.

Parameters
valslist of values

Adds each of the given values to the next columns.

◆ addComment()

void larcfm::SeparatedOutput::addComment ( const std::string &  c)

Add the following line to the comments.

Parameters
ccomment string

Add the following line to the comments.

◆ addHeading() [1/3]

void larcfm::SeparatedOutput::addHeading ( const std::string &  name,
const std::string &  unit 
)

Add the given heading (and unit) to the next column

Parameters
namethe name of this column heading
unitthe unit for this column. If you don't know, then use "unspecified"

◆ addHeading() [2/3]

void larcfm::SeparatedOutput::addHeading ( const std::vector< std::string > &  names,
const std::vector< std::string > &  units 
)

Add the given heading (and unit) to the next column

Parameters
namesthe name of this column heading
unitsthe unit for this column. If you don't know, then use "unspecified"

◆ addHeading() [3/3]

void larcfm::SeparatedOutput::addHeading ( const std::vector< std::string > &  names_and_units)

Add the given heading (and unit) to the next column

Parameters
names_and_unitsan array containing an alternating list of heading names and heading units. The length of this list must be even.

◆ clearParameters()

void larcfm::SeparatedOutput::clearParameters ( )

Clear all parameters.

◆ findHeading() [1/4]

int larcfm::SeparatedOutput::findHeading ( const std::string &  heading,
bool  caseSensitive 
)

Find the index of the column with given heading. If the heading is not found, then -1 is returned. Note: If you are getting some oddly large indexes, there are probably some nonstandard characters in the input.

Parameters
headingname of heading
caseSensitivefalse if ignoring case
Returns
index of heading

Find the index of the column with given heading. If the heading is not found, then -1 is returned. Note: If you are getting some oddly large indexes, there are probably some nonstandard characters in the input.

◆ findHeading() [2/4]

int larcfm::SeparatedOutput::findHeading ( const std::string &  heading1,
const std::string &  heading2,
bool  caseSensitive 
)

Find the index of the column with any of the given headings. If none of the given headings is found, then -1 is returned. This tries to find the first heading, and if it finds it then returns that index. If it doesn't find it, it moves to the next heading, etc. Note: If you are getting some oddly large indexes, there are probably some nonstandard characters in the input.

Parameters
heading1name of heading
heading2alternate name of heading
caseSensitivefalse if ignore case
Returns
index of heading

Find the index of the column with any of the given headings. If none of the given headings is found, then -1 is returned. This tries to find the first heading, and if it finds it then returns that index. If it doesn't find it, it moves to the next heading, etc. Note: If you are getting some oddly large indexes, there are probably some nonstandard characters in the input.

◆ findHeading() [3/4]

int larcfm::SeparatedOutput::findHeading ( const std::string &  heading1,
const std::string &  heading2,
const std::string &  heading3,
bool  caseSensitive 
)

Find the index of the column with any of the given headings. If none of the given headings is found, then -1 is returned. This tries to find the first heading, and if it finds it then returns that index. If it doesn't find it, it moves to the next heading, etc. Note: If you are getting some oddly large indexes, there are probably some nonstandard characters in the input.

Parameters
heading1name of heading
heading2alternate name of heading
heading3alternate name of heading
caseSensitivefalse if ignore heading
Returns
index of heading

Find the index of the column with any of the given headings. If none of the given headings is found, then -1 is returned. This tries to find the first heading, and if it finds it then returns that index. If it doesn't find it, it moves to the next heading, etc. Note: If you are getting some oddly large indexes, there are probably some nonstandard characters in the input.

◆ findHeading() [4/4]

int larcfm::SeparatedOutput::findHeading ( const std::string &  heading1,
const std::string &  heading2,
const std::string &  heading3,
const std::string &  heading4,
bool  caseSensitive 
)

Find the index of the column with any of the given headings. If none of the given headings is found, then -1 is returned. This tries to find the first heading, and if it finds it then returns that index. If it doesn't find it, it moves to the next heading, etc. Note: If you are getting some oddly large indexes, there are probably some nonstandard characters in the input.

Parameters
heading1name of heading
heading2alternate name of heading
heading3alternate name of heading
heading4alternate name of heading
caseSensitivefalse if ignore heading
Returns
index of heading

Find the index of the column with any of the given headings. If none of the given headings is found, then -1 is returned. This tries to find the first heading, and if it finds it then returns that index. If it doesn't find it, it moves to the next heading, etc. Note: If you are getting some oddly large indexes, there are probably some nonstandard characters in the input.

◆ getHeading()

std::string larcfm::SeparatedOutput::getHeading ( int  i)

Return the heading for the given column

Parameters
icolumn index
Returns
heading

Return the heading for the given column

◆ getMessage()

std::string larcfm::SeparatedOutput::getMessage ( )
virtual

Return a string representation of any errors or warnings. Calling this method will clear any messages and reset both the error and warning status to none.

Returns
error and warning messages. If there are no messages, an empty string is returned.

Implements larcfm::ErrorReporter.

◆ getMessageNoClear()

std::string larcfm::SeparatedOutput::getMessageNoClear ( ) const
virtual

Return a string representation of any errors or warnings. Calling this method will not clear the error or warning status (i.e., hasError() will return the same value before and after this call.)

Returns
error and warning messages. If there are no messages, an empty string is returned.

Implements larcfm::ErrorReporter.

◆ getUnit()

std::string larcfm::SeparatedOutput::getUnit ( int  i)

Returns the units string for the i-th column. If an invalid column is entered, then "unspecified" is returned.

Parameters
icolumn index
Returns
unit

Returns the units string for the i-th column. If an invalid column is entered, then "unspecified" is returned.

◆ hasError()

bool larcfm::SeparatedOutput::hasError ( ) const
virtual

Does this object have an error?

Returns
true if there is an error.

Implements larcfm::ErrorReporter.

◆ hasMessage()

bool larcfm::SeparatedOutput::hasMessage ( ) const
virtual

Does this object have an error or a warning?

Returns
true if there is an error or warning.

Implements larcfm::ErrorReporter.

◆ length()

long larcfm::SeparatedOutput::length ( )

Return the number of rows written

Returns
number of rows

Return the number of rows written

◆ operator=()

SeparatedOutput & larcfm::SeparatedOutput::operator= ( const SeparatedOutput x)

Assignment Operator.

◆ setColumn() [1/3]

void larcfm::SeparatedOutput::setColumn ( double  val)

Sets the next column value equal to the given value. The value is in internal units.

◆ setColumn() [2/3]

void larcfm::SeparatedOutput::setColumn ( int  i,
const std::string &  val 
)

Sets the next column value equal to the given value.

Parameters
iindex of column
valvalue

Sets the next column value equal to the given value.

◆ setColumn() [3/3]

void larcfm::SeparatedOutput::setColumn ( int  i,
double  val 
)

Sets the next column value equal to the given value. The value is in internal units.

◆ setColumnDelimiterComma()

void larcfm::SeparatedOutput::setColumnDelimiterComma ( )

Sets the column delimiter to a comma

◆ setColumnDelimiterSpace()

void larcfm::SeparatedOutput::setColumnDelimiterSpace ( )

Sets the column delimiter to a space. If a space is used as a separator then the empty value should be set (see setEmptyValue).

◆ setColumnDelimiterTab()

void larcfm::SeparatedOutput::setColumnDelimiterTab ( )

Sets the column delimiter to a tab

◆ setColumnSpace()

void larcfm::SeparatedOutput::setColumnSpace ( int  num)

Sets the number of extra spaces after the delimiter

Parameters
numnumber of spaces

Sets the number of extra spaces after the delimiter

◆ setCommentCharacter()

void larcfm::SeparatedOutput::setCommentCharacter ( const std::string &  c)

Set the code indicating the start of a comment.

Parameters
ccomment character

Set the code indicating the start of a comment.

◆ setEmptyValue()

void larcfm::SeparatedOutput::setEmptyValue ( std::string  e)

The value to be displayed if a column is "skipped". Empty values are only added inside a line, not at the end.

Parameters
evalue to indicate empty

The value to be displayed if a column is "skipped". Empty values are only added inside a line, not at the end.

◆ setHeading()

void larcfm::SeparatedOutput::setHeading ( int  i,
const std::string &  name,
const std::string &  unit 
)

Set the heading for the given column number, columns begin at 0.

Parameters
ithe column number
namethe name of this column heading
unitthe unit for this column. If you don't know, then use "unspecified"

◆ setOutputUnits()

void larcfm::SeparatedOutput::setOutputUnits ( bool  output)

Should the output units be placed in the output file?

Parameters
outputif true, then the units should be displayed

◆ setParameters()

void larcfm::SeparatedOutput::setParameters ( const ParameterData pr)

Additively set parameters. (This does not delete existing parameters, but will overwrite them.)

Parameters
prparameter object

Set parameters. Use all the parameters in the reader.

◆ size()

long larcfm::SeparatedOutput::size ( )

Return the number of columns

Returns
number of columns

Return the number of columns

◆ writeLine()

void larcfm::SeparatedOutput::writeLine ( )

Writes a line of the output. The first call to writeLine will write the column headings, units, etc.

Writes a line of the output. The first call to readLine will read the column headings, units, etc.


The documentation for this class was generated from the following files: