Phoenix
Object-oriented orthogonally persistent operating system
Classes | Public Member Functions | Protected Member Functions | Protected Attributes
text_stream::OTextStreamBase Class Reference

Base class for output text stream objects. More...

#include <OTextStream.h>

Inheritance diagram for text_stream::OTextStreamBase:
Collaboration diagram for text_stream::OTextStreamBase:

List of all members.

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.
OTextStreamBaseoperator<< (const Opt &opt)
 Specify option for conversion.
OTextStreamBaseoperator<< (bool value)
 Convert the provided value to string.
template<class T >
OTextStreamBaseoperator<< (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.

Detailed Description

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.


Member Function Documentation

bool text_stream::OTextStreamBase::_CheckFmtChar ( char  fmtChar,
short   
) [inline, protected]

These methods validate type against format character.

Parameters:
fmtCharFormat character which was specified for value.
Returns:
true if the specified format character is valid for the specified type.
bool OTextStreamBase::_FormatField ( Context ctx,
const char *  value,
size_t  numChars,
char  padChar = 0 
) [protected]

Output field representation.

Parameters:
ctxConversion context. Width and adjustment options are taken from it.
valueField string representation.
numCharsNumber of characters to take from value.
padCharPadding character. Use default if zero. Default may come from option O_PAD_CHAR.
Returns:
true if end of stream is not yet reached, false otherwise.
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.

Parameters:
valueValue to convert.
bufBuffer where to store the result.
radixRadix for integer representation (2..36).
upperCaseUse upper case letter if true.
Returns:
Number of characters stored in output buffer.
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.

Parameters:
ctxConversion context.
fmtFormat string. Pointer is advanced during string parsing. When the functions returns it point to the character next to a format operator found.
fmtCharPointer to location where format character will be stored. Will store zero if no format operators were found.
Returns:
true if end of stream is not yet reached during plain strings output, false otherwise.
bool text_stream::OTextStreamBase::_Putc ( Context ctx,
char  c 
) [inline, protected]

Output provided character.

Parameters:
ctxConversion context.
cCharacter to output.
Returns:
true if character was written, false otherwise.
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.

Parameters:
cCharacter to output.
Returns:
true if the character was output. false if end of stream reached, the rest characters in current string will be dropped in such case.
bool OTextStreamBase::_Puts ( Context ctx,
const char *  str 
) [protected]

Output provided string.

Parameters:
ctxConversion context.
strString to output.
Returns:
true if end of stream is not yet reached, false otherwise (end of stream reached).
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.

Parameters:
fmtFormat string. Should not contain any formatting operators.
Returns:
Number of characters written.

Reimplemented in log::SysLogBase.

template<typename... Args>
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.

Parameters:
ctxConversion context.
fmtFormat string. Should not contain any formatting operators.
Returns:
true if end of stream is not yet reached, false otherwise.
template<typename T , typename... Args>
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.

Parameters:
ctxConversion context.
fmtFormat string.
valueValue to format.
argsFormat arguments.
Returns:
true if end of stream is not yet reached, false otherwise.
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.

Parameters:
fmtFormat to output.
argsList of variable arguments for a format.
Returns:
Number of characters written.

Reimplemented in log::SysLogBase.

bool OTextStreamBase::FormatV ( Context ctx,
const char *  fmt,
va_list  args 
)

Output formatted string.

Parameters:
ctxConversion context.
fmtFormat to output.
argsList of variable arguments for a format.
Returns:
true if end of stream is not yet reached, false otherwise.
bool text_stream::OTextStreamBase::FormatValue ( Context ctx,
short  value,
char  fmt = 0 
) [inline]

FormatValue methods family converts value of specific type into string.

Parameters:
ctxConversion context.
valueValue of specific type to convert to string. FormatValue method should call _Putc method for each character it wants to output.
fmtFormat 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.
Returns:
true if end of stream is not yet reached and false otherwise.
template<class T >
bool text_stream::OTextStreamBase::FormatValue ( Context ctx,
T &  value,
char  fmt = 0 
) [inline]

Format user defined class object.

template<class T >
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.

Parameters:
optOption to switch.
Returns:
Reference to itself.
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);
Returns:
Reference to itself.

Member Data Documentation

Global context for insertion operators.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines