cisst-saw
|
#include <cmnPrintf.h>
Public Types | |
enum | { BUFFER_SIZE = 256 } |
Public Member Functions | |
cmnPrintfParser (std::ostream &output, const cmnPrintf &outputFormat) | |
void | RawOutput (const char *text) |
template<class _argType > | |
cmnPrintfParser & | operator<< (const _argType &dataOut) |
cmnPrintfParser & | operator<< (const int dataOut) |
cmnPrintfParser & | operator<< (const std::string &dataOut) |
operator bool (void) | |
template<typename _outputType > | |
bool | MatchOutputWithFormatChar (const _outputType &data) |
bool | NextTypeIdCharIsOneOf (const char *typeIdCharset) const |
void | SuspendOutput (void) |
const char * | GetNextFormatSequence (void) const |
char | GetNextTypeIdCharacter (void) const |
Static Public Member Functions | |
static const char * | TypeIdString (double CMN_UNUSED(value)) |
static const char * | TypeIdString (float CMN_UNUSED(value)) |
static const char * | TypeIdString (int CMN_UNUSED(value)) |
static const char * | TypeIdString (unsigned int CMN_UNUSED(value)) |
static const char * | TypeIdString (long CMN_UNUSED(value)) |
static const char * | TypeIdString (unsigned long CMN_UNUSED(value)) |
Static Public Attributes | |
static const char * | TypeIdCharset |
static const char * | IntegerTypeIds |
static const char * | FloatTypeIds |
static const char * | StringTypeIds |
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,
The function should return true if the formatting is successful, and false otherwise, although in the current implementation we ignore the return value.
anonymous enum |
cmnPrintfParser::cmnPrintfParser | ( | std::ostream & | output, |
const cmnPrintf & | outputFormat | ||
) |
|
inline |
Returns the next format sequence, i.e., '' sequence, which is to be processed next.
|
inline |
Returns the type identifying character to be processed next
|
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.
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.
|
inline |
Overload operator void * to allow similar evaluations of "success" as are available for ostream. E.g.,
A similar test can be performed for a cmnPrintfParser object, and tests the status of the output channel.
|
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.
|
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:
You should cast your enum value to int.
|
inline |
Overloaded operator for std::string. This operators is required since there is no implicit cast from std::string to const char pointer.
|
inline |
Dump raw text to the output stream. The user may call this function to output any text to the stream, without internal formatting.
|
inline |
|
inlinestatic |
This auxiliary function returns the set of characters that identify a double variable in the '' sequence, such as 'e', 'f', 'g', etc.
|
inlinestatic |
This auxiliary function returns the set of characters that identify a float variable in the '' sequence, such as 'e', 'f', 'g', etc.
|
inlinestatic |
This auxiliary function returns the set of characters that identify an int variable in the '' sequence, such as 'd', 'x', 'o', etc.
|
inlinestatic |
This auxiliary function returns the set of characters that identify an int variable in the '' sequence, such as 'd', 'x', 'o', etc.
|
inlinestatic |
This auxiliary function returns the set of characters that identify a long variable in the '' sequence, such as 'd', 'x', 'o', etc.
|
inlinestatic |
This auxiliary function returns the set of characters that identify an unsigned long variable in the '' sequence, such as 'd', 'x', 'o', etc.
|
static |
The collection of characters that identify floating-point output
|
static |
The collection of characters that identify integer output
|
static |
The collection of characters that identify strings, e.g., 's'
|
static |
The complete collection of type identifying characters which can be used in printf