Phoenix
Object-oriented orthogonally persistent operating system
|
Base class for output text stream objects. More...
#include <OTextStream.h>
Classes | |
class | Context |
Conversion context. More... | |
class | Opt |
Wrapper for options. More... | |
Public Member Functions | |
template<typename... Args> | |
size_t | Format (const char *fmt, Args...args) |
Output formated string. | |
size_t | Format (const char *fmt) |
This method handles edge case of previous template when only format string is specified. | |
template<typename T , typename... Args> | |
bool | Format (Context &ctx, const char *fmt, T &value, Args...args) |
Output formatted string. | |
bool | Format (Context &ctx, const char *fmt) |
This method handles the last recursive iteration (or format string without arguments) of the previous template. | |
size_t | FormatV (const char *fmt, va_list args) |
Output formatted string. | |
bool | FormatV (Context &ctx, const char *fmt, va_list args) |
Output formatted string. | |
OTextStreamBase & | operator<< (const Opt &opt) |
Specify option for conversion. | |
OTextStreamBase & | operator<< (bool value) |
Convert the provided value to string. | |
template<class T > | |
OTextStreamBase & | operator<< (T &value) |
Default conversion operator for user defined classes. | |
void | ClearOptions () |
Clear all global options for the stream. | |
bool | FormatValue (Context &ctx, short value, char fmt=0) |
FormatValue methods family converts value of specific type into string. | |
template<class T > | |
bool | FormatValue (Context &ctx, T &value, char fmt=0) |
Format user defined class object. | |
Protected Member Functions | |
virtual bool | _Putc (char c)=0 |
This method must be overridden in a derived class. | |
bool | _Putc (Context &ctx, char c) |
Output provided character. | |
bool | _Puts (Context &ctx, const char *str) |
Output provided string. | |
bool | _CheckFmtChar (char fmtChar, short) |
These methods validate type against format character. | |
bool | _ParseFormat (Context &ctx, const char **fmt, char *fmtChar) |
Parse format string. | |
void | _SetOpt (Context &ctx, Opt::Option opt, long value) |
Wrappers for setting option value from format arguments. | |
size_t | _IntToString (unsigned long value, char *buf, unsigned long radix=10, bool upperCase=false) |
Convert integer value to string. | |
bool | _FormatField (Context &ctx, const char *value, size_t numChars, char padChar=0) |
Output field representation. | |
Protected Attributes | |
Context | _globalCtx |
Global context for insertion operators. |
Base class for output text stream objects.
They should be derived from this class. Output text streams are capable of converting user defined classes to strings. In order to support such conversion the user defined class should have the following methods defined:
bool CheckFmtChar(char fmtChar);
This method should check is the provided format character applicable for the class being stringified.
bool ToString(OTextStreamBase &stream, OTextStreamBase::Context &ctx, char fmtChar = 0);
This method actually converts user defined class object to string. fmtChar has value of format character specified for this object if it was converted by Format method, or can be zero if it was converted by << operator. ctx is a conversion context which can be used to get formatting options. Format or FormatValue methods should be used by the object to output all string data. Number of printed characters via Format method should be accounted in ctx. The method should return true if all Format (or FormatValue) calls returned true, and false otherwise.
bool text_stream::OTextStreamBase::_CheckFmtChar | ( | char | fmtChar, |
short | |||
) | [inline, protected] |
These methods validate type against format character.
fmtChar | Format character which was specified for value. |
bool OTextStreamBase::_FormatField | ( | Context & | ctx, |
const char * | value, | ||
size_t | numChars, | ||
char | padChar = 0 |
||
) | [protected] |
Output field representation.
ctx | Conversion context. Width and adjustment options are taken from it. |
value | Field string representation. |
numChars | Number of characters to take from value. |
padChar | Padding character. Use default if zero. Default may come from option O_PAD_CHAR. |
size_t OTextStreamBase::_IntToString | ( | unsigned long | value, |
char * | buf, | ||
unsigned long | radix = 10 , |
||
bool | upperCase = false |
||
) | [protected] |
Convert integer value to string.
String is filled in reverse order.
value | Value to convert. |
buf | Buffer where to store the result. |
radix | Radix for integer representation (2..36). |
upperCase | Use upper case letter if true. |
bool OTextStreamBase::_ParseFormat | ( | Context & | ctx, |
const char ** | fmt, | ||
char * | fmtChar | ||
) | [protected] |
Parse format string.
All encountered options should be applied to the provided conversion context. Plain string preceding format operators should be output using provided context.
ctx | Conversion context. |
fmt | Format string. Pointer is advanced during string parsing. When the functions returns it point to the character next to a format operator found. |
fmtChar | Pointer to location where format character will be stored. Will store zero if no format operators were found. |
bool text_stream::OTextStreamBase::_Putc | ( | Context & | ctx, |
char | c | ||
) | [inline, protected] |
Output provided character.
ctx | Conversion context. |
c | Character to output. |
virtual bool text_stream::OTextStreamBase::_Putc | ( | char | c | ) | [protected, pure virtual] |
This method must be overridden in a derived class.
All formatting methods call it to output next text character.
c | Character to output. |
bool OTextStreamBase::_Puts | ( | Context & | ctx, |
const char * | str | ||
) | [protected] |
Output provided string.
ctx | Conversion context. |
str | String to output. |
void text_stream::OTextStreamBase::_SetOpt | ( | Context & | ctx, |
Opt::Option | opt, | ||
long | value | ||
) | [inline, protected] |
Wrappers for setting option value from format arguments.
They should ensure that argument will have correct type for corresponding option.
void text_stream::OTextStreamBase::ClearOptions | ( | ) | [inline] |
Clear all global options for the stream.
The stream will have default conversion behavior after this operation.
size_t text_stream::OTextStreamBase::Format | ( | const char * | fmt | ) | [inline] |
This method handles edge case of previous template when only format string is specified.
fmt | Format string. Should not contain any formatting operators. |
Reimplemented in log::SysLogBase.
size_t text_stream::OTextStreamBase::Format | ( | const char * | fmt, |
Args... | args | ||
) | [inline] |
Output formated string.
Reimplemented in log::SysLogBase.
bool OTextStreamBase::Format | ( | Context & | ctx, |
const char * | fmt | ||
) |
This method handles the last recursive iteration (or format string without arguments) of the previous template.
ctx | Conversion context. |
fmt | Format string. Should not contain any formatting operators. |
bool text_stream::OTextStreamBase::Format | ( | Context & | ctx, |
const char * | fmt, | ||
T & | value, | ||
Args... | args | ||
) | [inline] |
Output formatted string.
This method should be used by user defined classes in ToString method to output string data into provided stream.
ctx | Conversion context. |
fmt | Format string. |
value | Value to format. |
args | Format arguments. |
size_t text_stream::OTextStreamBase::FormatV | ( | const char * | fmt, |
va_list | args | ||
) | [inline] |
Output formatted string.
It has more limited functionality than Format method because it is not types aware for format arguments. So it cannot format user defined classes. For the same reason it is not safe and should not be used unless absolutely necessary.
fmt | Format to output. |
args | List of variable arguments for a format. |
Reimplemented in log::SysLogBase.
bool OTextStreamBase::FormatV | ( | Context & | ctx, |
const char * | fmt, | ||
va_list | args | ||
) |
Output formatted string.
ctx | Conversion context. |
fmt | Format to output. |
args | List of variable arguments for a format. |
bool text_stream::OTextStreamBase::FormatValue | ( | Context & | ctx, |
short | value, | ||
char | fmt = 0 |
||
) | [inline] |
FormatValue methods family converts value of specific type into string.
ctx | Conversion context. |
value | Value of specific type to convert to string. FormatValue method should call _Putc method for each character it wants to output. |
fmt | Format letter. When format letter is searched the first alphabetical symbol except 'l', 'L', 'h' and 'H' is considered to be format letter. All preceding symbols are considered to be options. |
bool text_stream::OTextStreamBase::FormatValue | ( | Context & | ctx, |
T & | value, | ||
char | fmt = 0 |
||
) | [inline] |
Format user defined class object.
OTextStreamBase& text_stream::OTextStreamBase::operator<< | ( | T & | value | ) | [inline] |
Default conversion operator for user defined classes.
OTextStreamBase & OTextStreamBase::operator<< | ( | const Opt & | opt | ) |
Specify option for conversion.
opt | Option to switch. |
OTextStreamBase & OTextStreamBase::operator<< | ( | bool | value | ) |
Convert the provided value to string.
This operator is overloaded for all supported types. For the types which are not supported here, the >> operator of the object provided as value will be called. The operator should have the following prototype:
void operator >> (OTextStreamBase &s);
Context text_stream::OTextStreamBase::_globalCtx [protected] |
Global context for insertion operators.