ERC CISST - cisst software

cmnPrintfParser Class Reference
[Common Tools]

#include <cmnPrintf.h>

Collaboration diagram for cmnPrintfParser:

Collaboration graph
[legend]
List of all members.

Detailed Description

Parser for cmnPrintf.

This class performs the actual formatting of the input. It communicates with a cmnPrintf object, parses the format string, and sends formatted inputs to the output. Normally, the user does not deal with this class.

The user may use a cmnPrintfParser object to provide formatting for new types, such as user-defined classes. Note that the collection of `' sequences is specified through the C sprintf set of control characters, and cannot be changed. However, the user may override an existing `' sequence to format new types with that control. For example, the sequence "%d%" can be used to format a single integer or a vector of integers.

To format new classes, the user should provide an overload of the global function cmnTypePrintf, that takes the user's class as an input. For example,

  bool cmnTypePrintf(cmnPrintfParser & outputParser, const MyClass data);

The function should return true if the formatting is successful, and false otherwise, although in the current implementation we ignore the return value.

Definition at line 228 of file cmnPrintf.h.

Public Types

Public Member Functions

Static Public Member Functions

Static Public Attributes


Member Enumeration Documentation

anonymous enum

The size of buffer allocated for formatting each output element. Exceeding this size will truncate the output for that element.

Definition at line 316 of file cmnPrintf.h.


Constructor & Destructor Documentation

cmnPrintfParser::cmnPrintfParser ( std::ostream &  output,
const cmnPrintf outputFormat 
)

Initialize a cmnPrintf object with the destination output stream and a format string.

Parameters:
output the actual output stream to which text will be printed
outputFormat a cmnPrintf object that holds a copy of the format string


Member Function Documentation

void cmnPrintfParser::RawOutput ( const char *  text  )  [inline]

Dump raw text to the output stream. The user may call this function to output any text to the stream, without internal formatting.

Definition at line 244 of file cmnPrintf.h.

template<class _argType>
cmnPrintfParser& cmnPrintfParser::operator<< ( const _argType &  dataOut  )  [inline]

This is the overloaded operator << that formates the currenct input element and advances to the next one. It calls cmnTypePrintf for the given input type.

Definition at line 254 of file cmnPrintf.h.

cmnPrintfParser& cmnPrintfParser::operator<< ( const int  dataOut  )  [inline]

Overloaded operator for integers. This operator is mostly a helper for compilers which won't convert an anonymous enum as an integer to infer the type used in the templated operator.

This solution works with gcc 4.0.2 but not with gcc 4.0.1. If you get a compilation error like:

      error: 'myClass::<anonymous enum>' is/uses anonymous type
You should cast your enum value to int.

Definition at line 275 of file cmnPrintf.h.

cmnPrintfParser& cmnPrintfParser::operator<< ( const std::string &  dataOut  )  [inline]

Overloaded operator for std::string. This operators is required since there is no implicit cast from std::string to const char pointer.

Definition at line 288 of file cmnPrintf.h.

cmnPrintfParser::operator void * ( void   )  [inline]

Overload operator void * to allow similar evaluations of "success" as are available for ostream. E.g.,

      if (!std::cout) {
      // do something
      }

A similar test can be performed for a cmnPrintfParser object, and tests the status of the output channel.

Definition at line 308 of file cmnPrintf.h.

static const char* cmnPrintfParser::TypeIdString ( double   CMN_UNUSED(value)  )  [inline, static]

This auxiliary function returns the set of characters that identify a double variable in the '' sequence, such as 'e', 'f', 'g', etc.

Definition at line 381 of file cmnPrintf.h.

static const char* cmnPrintfParser::TypeIdString ( float   CMN_UNUSED(value)  )  [inline, static]

This auxiliary function returns the set of characters that identify a float variable in the '' sequence, such as 'e', 'f', 'g', etc.

Definition at line 390 of file cmnPrintf.h.

static const char* cmnPrintfParser::TypeIdString ( int   CMN_UNUSED(value)  )  [inline, static]

This auxiliary function returns the set of characters that identify an int variable in the '' sequence, such as 'd', 'x', 'o', etc.

Definition at line 399 of file cmnPrintf.h.

static const char* cmnPrintfParser::TypeIdString ( unsigned int   CMN_UNUSED(value)  )  [inline, static]

This auxiliary function returns the set of characters that identify an int variable in the '' sequence, such as 'd', 'x', 'o', etc.

Definition at line 408 of file cmnPrintf.h.

static const char* cmnPrintfParser::TypeIdString ( long   CMN_UNUSED(value)  )  [inline, static]

This auxiliary function returns the set of characters that identify a long variable in the '' sequence, such as 'd', 'x', 'o', etc.

Definition at line 417 of file cmnPrintf.h.

static const char* cmnPrintfParser::TypeIdString ( unsigned long   CMN_UNUSED(value)  )  [inline, static]

This auxiliary function returns the set of characters that identify an unsigned long variable in the '' sequence, such as 'd', 'x', 'o', etc.

Definition at line 426 of file cmnPrintf.h.

template<typename _outputType>
bool cmnPrintfParser::MatchOutputWithFormatChar ( const _outputType &  data  )  [inline]

This function matches the "type" of the given data with the set of format characters for that type, by calling TypeIdString for the type of the data. The function returns true of the next format character in the format string matches the type of the data, and false otherwise. For example, if the format text is "%f" and the data is of type double, or float, the function returns true; but if the data is of type in the function returns false.

Definition at line 440 of file cmnPrintf.h.

bool cmnPrintfParser::NextTypeIdCharIsOneOf ( const char *  typeIdCharset  )  const

This function matches the next type character with the string of id characters given as argument. For example, if the argument is "dxci" and the next type id in the format string was taken from "%10d" the function returns true; but if the next type id is taken from "%7.2f" the function returns false.

const char* cmnPrintfParser::GetNextFormatSequence ( void   )  const [inline]

Returns the next format sequence, i.e., '' sequence, which is to be processed next.

Definition at line 463 of file cmnPrintf.h.

char cmnPrintfParser::GetNextTypeIdCharacter ( void   )  const [inline]

Returns the type identifying character to be processed next

Definition at line 469 of file cmnPrintf.h.


Member Data Documentation

const char* cmnPrintfParser::TypeIdCharset [static]

The complete collection of type identifying characters which can be used in printf

Definition at line 366 of file cmnPrintf.h.

const char* cmnPrintfParser::IntegerTypeIds [static]

The collection of characters that identify integer output

Definition at line 369 of file cmnPrintf.h.

const char* cmnPrintfParser::FloatTypeIds [static]

The collection of characters that identify floating-point output

Definition at line 372 of file cmnPrintf.h.

const char* cmnPrintfParser::StringTypeIds [static]

The collection of characters that identify strings, e.g., 's'

Definition at line 375 of file cmnPrintf.h.


The documentation for this class was generated from the following file:
erc-cisst-devel<at>lists.johnshopkins.edu