Base Framework
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | Static Protected Attributes | Related Functions | List of all members
FormatOutputStream Class Reference

Format output stream. More...

#include <base/string/FormatOutputStream.h>

Inherits BufferedOutputStream.

Inherited by StringOutputStream, and WideStringOutputStream.

Classes

class  Context
 Context of format output stream object. More...
 
class  GetContext
 
class  Indent
 
class  Manipulator
 
class  PushContext
 Push and pop default context of format output stream. More...
 
class  SetContext
 
class  SourceCodeLocation
 
class  StringManipulator
 
class  Symbols
 
class  TabIndent
 

Public Types

typedef SpinLock Guard
 

Public Member Functions

 FormatOutputStream (OutputStream &out, unsigned int size=DEFAULT_BUFFER_SIZE)
 
 FormatOutputStream (const FormatOutputStream &copy)=delete
 
void reset () noexcept
 
bool isANSITerminal ()
 
FormatOutputStreamsetRadixPosition (unsigned int position) noexcept
 
FormatOutputStreamsetJustification (Symbols::Justification justification) noexcept
 
FormatOutputStreamsetWidth (unsigned int width) noexcept
 
FormatOutputStreamsetPrecision (unsigned int precision) noexcept
 
FormatOutputStreamsetDateFormat (const String &format)
 
void setLocale (const Locale &locale) noexcept
 
unsigned int getFlags () const noexcept
 
void setFlags (unsigned int flags) noexcept
 
Symbols::Base getBase () const noexcept
 
Symbols::Base getRealBase () const noexcept
 
unsigned int getWidth () const noexcept
 
unsigned int getPrecision () const noexcept
 
FormatOutputStreamoperator<< (Action action)
 
FormatOutputStreamoperator<< (Indent indent)
 
FormatOutputStreamoperator<< (TabIndent indent)
 
void indent (unsigned int size, bool useTab=false)
 
void addCharacterField (const char *buffer, MemorySize size)
 
void addCharacterField (const wchar *buffer, MemorySize size)
 
void addCharacterField (const char16_t *buffer, MemorySize size)
 
void addCharacterField (const char32_t *buffer, MemorySize size)
 
void addIntegerField (const char *buffer, MemorySize size, bool isSigned)
 
void addDateField (const Date &date)
 
void writeFloatingPointType (unsigned int significant, unsigned int *mantissa, unsigned int mantissaSize, int base2Exponent, unsigned int valueFlags)
 
FormatOutputStreamgetContext (Context &context) noexcept
 
FormatOutputStreamsetContext (const Context &context) noexcept
 
FormatOutputStreamoperator<< (const SourceCodeLocation &location)
 
template<MemorySize SIZE>
FormatOutputStreamoperator<< (const char(&literal)[SIZE])
 
FormatOutputStreamoperator<< (bool value)
 
FormatOutputStreamoperator<< (char value)
 
FormatOutputStreamoperator<< (wchar value)
 
FormatOutputStreamoperator<< (short int value)
 
FormatOutputStreamoperator<< (unsigned short int value)
 
FormatOutputStreamoperator<< (int value)
 
FormatOutputStreamoperator<< (unsigned int value)
 
FormatOutputStreamoperator<< (long value)
 
FormatOutputStreamoperator<< (unsigned long value)
 
FormatOutputStreamoperator<< (long long value)
 
FormatOutputStreamoperator<< (unsigned long long value)
 
FormatOutputStreamoperator<< (int128 value)
 
FormatOutputStreamoperator<< (uint128 value)
 
FormatOutputStreamoperator<< (float value)
 
FormatOutputStreamoperator<< (double value)
 
FormatOutputStreamoperator<< (long double value)
 
FormatOutputStreamoperator<< (float128 value)
 
FormatOutputStreamoperator<< (const NativeString &value)
 
FormatOutputStreamoperator<< (const NativeWideString &value)
 
FormatOutputStreamoperator<< (const char *value)
 
FormatOutputStreamoperator<< (const wchar *value)
 
FormatOutputStreamoperator<< (const char16_t *value)
 
FormatOutputStreamoperator<< (const char32_t *value)
 
FormatOutputStreamoperator<< (const MemorySpan &span)
 
FormatOutputStreamoperator<< (const void *value)
 
template<class TYPE >
FormatOutputStreamoperator<< (Reference< TYPE > value)
 
FormatOutputStreamoperator<< (const Literal &literal)
 
FormatOutputStreamoperator<< (const WideLiteral &literal)
 
FormatOutputStreamoperator<< (const Exception &e)
 
virtual String toString ()
 
 ~FormatOutputStream ()
 
- Public Member Functions inherited from BufferedOutputStream
 BufferedOutputStream (OutputStream &out, unsigned int size=DEFAULT_BUFFER_SIZE)
 
void flush ()
 
unsigned int write (const uint8 *buffer, unsigned int size, bool nonblocking=false)
 
void unfoldValue (char value, unsigned int count)
 
 ~BufferedOutputStream ()
 
- Public Member Functions inherited from FilterOutputStream
 FilterOutputStream (OutputStream &out)
 
OutputStreamgetOutputStream () noexcept
 
void close ()
 
void flush ()
 
unsigned int write (const uint8 *buffer, unsigned int size, bool nonblocking=false)
 
- Public Member Functions inherited from Stream
virtual ~Stream () noexcept(false)
 
- Public Member Functions inherited from ReferenceCountedObject
 ReferenceCountedObject () noexcept
 
 ReferenceCountedObject (const ReferenceCountedObject &copy) noexcept
 
 ReferenceCountedObject (ReferenceCountedObject &&move) noexcept
 
ReferenceCountedObjectoperator= (const ReferenceCountedObject &copy) noexcept
 
ReferenceCountedObjectoperator= (ReferenceCountedObject &&move) noexcept
 
MemorySize getNumberOfReferences_INTERNAL () const noexcept
 
virtual bool useGarbageCollector () const noexcept
 
- Public Member Functions inherited from DynamicObject
 DynamicObject () noexcept
 
bool isValidObject () const noexcept
 
virtual ~DynamicObject () noexcept(false)
 
 _COM_AZURE_DEV__BASE__OVERRIDE_ALLOC ()
 

Static Public Attributes

static const unsigned int DEFAULT_FLAGS
 
static const Symbols::EndOfLine DEFAULT_EOL = Symbols::UNIXEOL
 
static const Symbols::Base DEFAULT_INTEGER_BASE = Symbols::DECIMAL
 
static const Symbols::Base DEFAULT_REAL_BASE = Symbols::DECIMAL
 
static const Symbols::RealStyle DEFAULT_REAL_STYLE = Symbols::FIXED
 
static const int DEFAULT_RADIX_POSITION = 0
 
static const Symbols::MajorDateFormat DEFAULT_MAJOR_DATE_FORMAT
 
static const Symbols::NamedDateFormat DEFAULT_NAMED_DATE_FORMAT
 
static const Symbols::Justification DEFAULT_JUSTIFICATION
 
static const int DEFAULT_WIDTH = 0
 
static const int DEFAULT_PRECISION = 6
 
static constexpr unsigned int MAXIMUM_WIDTH = 128
 
static constexpr unsigned int MAXIMUM_PRECISION = 64
 
static constexpr unsigned int MAXIMUM_SIZE = 256
 
- Static Public Attributes inherited from BufferedOutputStream
static const unsigned int DEFAULT_BUFFER_SIZE = 4096
 
static const unsigned int MINIMUM_BUFFER_SIZE = 1024
 

Protected Attributes

Guard guard
 
Context defaultContext
 
Context context
 
- Protected Attributes inherited from BufferedOutputStream
Allocator< uint8 > buffer
 
unsigned int writeHead = 0
 
unsigned int readHead = 0
 
- Protected Attributes inherited from FilterOutputStream
OutputStreamout
 

Static Protected Attributes

static const Context DEFAULT_CONTEXT
 

Related Functions

(Note that these are not member functions.)

enum  Action
 

Detailed Description

Format output stream.

Stream used to stringify types.

Version
1.4
Examples
testsuite/client.cpp, testsuite/ftp.cpp, testsuite/http.cpp, and testsuite/server.cpp.

Member Typedef Documentation

◆ Guard

The type of the guard.

Constructor & Destructor Documentation

◆ FormatOutputStream()

FormatOutputStream::FormatOutputStream ( OutputStream out,
unsigned int  size = DEFAULT_BUFFER_SIZE 
)

Initializes the format output stream.

Parameters
outThe output stream.
sizeThe size of the buffer. Default is given by DEFAULT_BUFFER_SIZE.

◆ ~FormatOutputStream()

FormatOutputStream::~FormatOutputStream ( )

Destroy format output stream.

Member Function Documentation

◆ addCharacterField() [1/4]

void FormatOutputStream::addCharacterField ( const char *  buffer,
MemorySize  size 
)

Writes the specifies number of characters to the stream.

◆ addCharacterField() [2/4]

void FormatOutputStream::addCharacterField ( const char16_t *  buffer,
MemorySize  size 
)

Writes the specifies number of characters to the stream.

◆ addCharacterField() [3/4]

void FormatOutputStream::addCharacterField ( const char32_t *  buffer,
MemorySize  size 
)

Writes the specifies number of characters to the stream.

◆ addCharacterField() [4/4]

void FormatOutputStream::addCharacterField ( const wchar *  buffer,
MemorySize  size 
)

Writes the specifies number of characters to the stream.

◆ addDateField()

void FormatOutputStream::addDateField ( const Date date)

Writes a date object to the stream.

◆ addIntegerField()

void FormatOutputStream::addIntegerField ( const char *  buffer,
MemorySize  size,
bool  isSigned 
)

Writes a preformated integer to the stream.

◆ getBase()

Symbols::Base FormatOutputStream::getBase ( ) const
inlinenoexcept

Returns the current integer base.

◆ getContext()

FormatOutputStream& FormatOutputStream::getContext ( Context context)
noexcept

Gets the context.

◆ getFlags()

unsigned int FormatOutputStream::getFlags ( ) const
inlinenoexcept

Returns the flags for the next field.

◆ getPrecision()

unsigned int FormatOutputStream::getPrecision ( ) const
inlinenoexcept

Returns the current precision.

◆ getRealBase()

Symbols::Base FormatOutputStream::getRealBase ( ) const
inlinenoexcept

Returns the current floating-point base.

◆ getWidth()

unsigned int FormatOutputStream::getWidth ( ) const
inlinenoexcept

Returns the current field width.

◆ indent()

void FormatOutputStream::indent ( unsigned int  size,
bool  useTab = false 
)

Writes the specified number of spaces to the stream. The current context is ignored and not reset by this method.

◆ isANSITerminal()

bool FormatOutputStream::isANSITerminal ( )

Returns true if the stream is connected to an ANSI terminal.

Examples
testsuite/ls.cpp.

◆ operator<<() [1/30]

FormatOutputStream& FormatOutputStream::operator<< ( Action  action)

Send action to stream.

◆ operator<<() [2/30]

FormatOutputStream& FormatOutputStream::operator<< ( const char *  value)
inline

Write value to stream.

◆ operator<<() [3/30]

template<MemorySize SIZE>
FormatOutputStream& FormatOutputStream::operator<< ( const char(&)  literal[SIZE])
inline

Writes the given string literal to the stream.

Parameters
literalString literal.

◆ operator<<() [4/30]

FormatOutputStream& FormatOutputStream::operator<< ( const char16_t *  value)
inline

Write value to stream.

◆ operator<<() [5/30]

FormatOutputStream& FormatOutputStream::operator<< ( const char32_t *  value)
inline

Write value to stream.

◆ operator<<() [6/30]

FormatOutputStream& FormatOutputStream::operator<< ( const Exception e)

Writes a nice description of the exception to the format output stream.

◆ operator<<() [7/30]

FormatOutputStream& FormatOutputStream::operator<< ( const Literal literal)
inline

Writes a string literal to a format output stream.

◆ operator<<() [8/30]

FormatOutputStream& FormatOutputStream::operator<< ( const MemorySpan span)
inline

Writes the memory span to the stream.

◆ operator<<() [9/30]

FormatOutputStream& FormatOutputStream::operator<< ( const NativeString value)
inline

Write value to stream.

◆ operator<<() [10/30]

FormatOutputStream& FormatOutputStream::operator<< ( const NativeWideString value)
inline

Write value to stream.

◆ operator<<() [11/30]

FormatOutputStream& FormatOutputStream::operator<< ( const SourceCodeLocation location)

Writes the debug information to the stream.

◆ operator<<() [12/30]

FormatOutputStream& FormatOutputStream::operator<< ( const void *  value)

Writes a pointer to a format output stream.

◆ operator<<() [13/30]

FormatOutputStream& FormatOutputStream::operator<< ( const wchar *  value)
inline

Write value to stream.

◆ operator<<() [14/30]

FormatOutputStream& FormatOutputStream::operator<< ( double  value)

Write value to stream.

◆ operator<<() [15/30]

FormatOutputStream& FormatOutputStream::operator<< ( float  value)

Write value to stream.

◆ operator<<() [16/30]

FormatOutputStream& FormatOutputStream::operator<< ( float128  value)

Write value to stream.

◆ operator<<() [17/30]

FormatOutputStream& FormatOutputStream::operator<< ( Indent  indent)
inline

Indents the stream with the specified number of spaces. This is usually used immediately after an EOL.

◆ operator<<() [18/30]

FormatOutputStream& FormatOutputStream::operator<< ( int  value)

Write value to stream.

◆ operator<<() [19/30]

FormatOutputStream& FormatOutputStream::operator<< ( int128  value)

Write value to stream.

◆ operator<<() [20/30]

FormatOutputStream& FormatOutputStream::operator<< ( long double  value)

Write value to stream.

◆ operator<<() [21/30]

FormatOutputStream& FormatOutputStream::operator<< ( long long  value)

Write value to stream.

◆ operator<<() [22/30]

FormatOutputStream& FormatOutputStream::operator<< ( long  value)

Write value to stream.

◆ operator<<() [23/30]

template<class TYPE >
FormatOutputStream& FormatOutputStream::operator<< ( Reference< TYPE >  value)
inline

Writes a reference to a format output stream.

◆ operator<<() [24/30]

FormatOutputStream& FormatOutputStream::operator<< ( short int  value)

Write value to stream.

◆ operator<<() [25/30]

FormatOutputStream& FormatOutputStream::operator<< ( TabIndent  indent)
inline

Indents the stream with the specified number of TABs. This is usually used immediately after an EOL.

◆ operator<<() [26/30]

FormatOutputStream& FormatOutputStream::operator<< ( uint128  value)

Write value to stream.

◆ operator<<() [27/30]

FormatOutputStream& FormatOutputStream::operator<< ( unsigned int  value)

Write value to stream.

◆ operator<<() [28/30]

FormatOutputStream& FormatOutputStream::operator<< ( unsigned long long  value)

Write value to stream.

◆ operator<<() [29/30]

FormatOutputStream& FormatOutputStream::operator<< ( unsigned long  value)

Write value to stream.

◆ operator<<() [30/30]

FormatOutputStream& FormatOutputStream::operator<< ( unsigned short int  value)

Write value to stream.

◆ reset()

void FormatOutputStream::reset ( )
noexcept

Resets context flags.

◆ setContext()

FormatOutputStream& FormatOutputStream::setContext ( const Context context)
noexcept

Sets the context.

◆ setDateFormat()

FormatOutputStream& FormatOutputStream::setDateFormat ( const String format)

Sets the date format.

Parameters
formatThe desired date format.

◆ setFlags()

void FormatOutputStream::setFlags ( unsigned int  flags)
inlinenoexcept

Sets the flags for the next field.

◆ setJustification()

FormatOutputStream& FormatOutputStream::setJustification ( Symbols::Justification  justification)
noexcept

Sets the value justification within the field.

Parameters
justificationThe desired justification.

◆ setLocale()

void FormatOutputStream::setLocale ( const Locale locale)
noexcept

Sets the locale of the stream. The locale is global for the stream. The stream uses POSIX formatting until the locale is set explicitly using this method. The action POSIX can be used to override the locale (see ISO/IEC WG14 N884, NCITS J11/99-019).

Parameters
localeThe desired locale.

◆ setPrecision()

FormatOutputStream& FormatOutputStream::setPrecision ( unsigned int  precision)
noexcept

Sets the precision for floating-point numbers (i.e. the number of digits after the decimal-point). The requested precision is silently reduced to MAXIMUM_PRECISION.

Parameters
precisionThe desired precision.

◆ setRadixPosition()

FormatOutputStream& FormatOutputStream::setRadixPosition ( unsigned int  position)
noexcept

Sets the desired position of the decimal-point within the field. Please note that the position is only advisory. Please note that this method sets the justification state to Symbols::RADIX as a side effect.

Parameters
positionThe desired position.

◆ setWidth()

FormatOutputStream& FormatOutputStream::setWidth ( unsigned int  width)
noexcept

Sets the current field width. The width silently reduced to MAXIMUM_WIDTH.

Parameters
widthThe desired width.

◆ toString()

virtual String FormatOutputStream::toString ( )
virtual

Returns the associated buffer as a String if supported by stream. E.g. StringOutputStream. Returns empty String otherwise. Stream is restarted for new content.

Reimplemented in WideStringOutputStream, and StringOutputStream.

◆ writeFloatingPointType()

void FormatOutputStream::writeFloatingPointType ( unsigned int  significant,
unsigned int *  mantissa,
unsigned int  mantissaSize,
int  base2Exponent,
unsigned int  valueFlags 
)

Writes a preformated floating point value to stream.

Friends And Related Function Documentation

◆ Action

enum Action
related

Actions used to modify a format output stream. Use BIN, OCT, DEC, and HEX to select an appropriate integer base. Use ZEROPAD and NOZEROPAD to enable/disable zero padding. Use PREFIX and NOPREFIX to enable/disable prefixes for numbers. EOL writes a new line to the stream. FLUSH forces the internal buffers to be flushed. Use ENDL to both write a new line and flush the internal buffers.

Member Data Documentation

◆ context

Context FormatOutputStream::context
protected

The current context.

◆ DEFAULT_CONTEXT

const Context FormatOutputStream::DEFAULT_CONTEXT
staticprotected

The initial context.

◆ DEFAULT_FLAGS

const unsigned int FormatOutputStream::DEFAULT_FLAGS
static
Initial value:
=
Symbols::PREFIX | Symbols::NECESSARY | Symbols::POSIX

◆ DEFAULT_JUSTIFICATION

const Symbols::Justification FormatOutputStream::DEFAULT_JUSTIFICATION
static
Initial value:
=
Symbols::DEPENDENT

◆ DEFAULT_MAJOR_DATE_FORMAT

const Symbols::MajorDateFormat FormatOutputStream::DEFAULT_MAJOR_DATE_FORMAT
static
Initial value:
=
Symbols::DATETIME

◆ DEFAULT_NAMED_DATE_FORMAT

const Symbols::NamedDateFormat FormatOutputStream::DEFAULT_NAMED_DATE_FORMAT
static
Initial value:
=
Symbols::MEDIUM_FORMAT

◆ defaultContext

Context FormatOutputStream::defaultContext
protected

The current default context.

◆ guard

Guard FormatOutputStream::guard
protected

Guard.

◆ MAXIMUM_PRECISION

constexpr unsigned int FormatOutputStream::MAXIMUM_PRECISION = 64
staticconstexpr

Specifies the maximum precision.

◆ MAXIMUM_SIZE

constexpr unsigned int FormatOutputStream::MAXIMUM_SIZE = 256
staticconstexpr

Specifies the maximum number of characters for real numbers.

◆ MAXIMUM_WIDTH

constexpr unsigned int FormatOutputStream::MAXIMUM_WIDTH = 128
staticconstexpr

Specifies the maximum field width.