Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ecl::Format< std::string > Class Reference

Formatter for string types. More...

#include <strings.hpp>

Public Member Functions

Format< std::string > & align (Alignment a)
 
 Format (int w=-1, Alignment a=NoAlign)
 
Format< std::string > & operator() (const std::string &input_string)
 
Format< std::string > & operator() (const std::string &input_string, int w)
 
Format< std::string > & operator() (const std::string &input_string, int w, Alignment a)
 
Format< std::string > & operator() (int w, Alignment a)
 
Format< std::string > & width (int w)
 
virtual ~Format ()
 

Private Member Functions

template<typename OutputStream >
void format (OutputStream &ostream) const
 
template<typename OutputStream >
void pad (int n, OutputStream &ostream) const
 
template<typename OutputStream >
void postPad (int n, OutputStream &ostream) const
 
template<typename OutputStream >
void prePad (int n, OutputStream &ostream) const
 

Private Attributes

Alignment alignment_
 
bool ready_to_format
 
std::string s
 
int width_
 

Friends

template<typename OutputStream >
OutputStream & operator<< (OutputStream &ostream, Format< std::string > &formatter)
 

Detailed Description

Formatter for string types.

Default formatter for string types. This is pretty slow since we're using strings, but its convenient when speed is not an issue.

Definition at line 48 of file strings.hpp.

Constructor & Destructor Documentation

◆ Format()

ecl::Format< std::string >::Format ( int  w = -1,
Alignment  a = NoAlign 
)
inline

Default constructor. Initialises the format tags for width, alignment and base.

Parameters
w: width (default - no width constraints)
a: the textual alignment (default - no alignment constraints)

Definition at line 66 of file strings.hpp.

◆ ~Format()

virtual ecl::Format< std::string >::~Format ( )
inlinevirtual

Definition at line 67 of file strings.hpp.

Member Function Documentation

◆ align()

Format<std::string>& ecl::Format< std::string >::align ( Alignment  a)
inline

Sets the alignment format parameter. This aligns the text output in the text window which has a width specified by the width parameter.

Parameters
a: the aligning property for the output text.
See also
Alignment

Definition at line 82 of file strings.hpp.

◆ format()

template<typename OutputStream >
void ecl::Format< std::string >::format ( OutputStream &  ostream) const
private

Internal function that does the actual formatting of a format object into a stream.

Parameters
ostream: the stream to be inserted into.

Definition at line 180 of file strings.hpp.

◆ operator()() [1/4]

Format< std::string > & ecl::Format< std::string >::operator() ( const std::string &  input_string)

Insert an input value to be formatted when passed to a stream.

Parameters
input_string: the string to be formatted.
Returns
Format<string> : formatting object to be passed back to the stream.

Definition at line 42 of file strings.cpp.

◆ operator()() [2/4]

Format< std::string > & ecl::Format< std::string >::operator() ( const std::string &  input_string,
int  w 
)

Temporarily configure the formatter with a width, base combination along with a value to be formatted.

Parameters
input_string: the string to be formatted.
w: the width to be used.
Returns
Format<string> : formatting object to be passed back to the stream.

Definition at line 52 of file strings.cpp.

◆ operator()() [3/4]

Format< std::string > & ecl::Format< std::string >::operator() ( const std::string &  input_string,
int  w,
Alignment  a 
)

Temporarily configure the formatter with a complete parameter set along with a value to be formatted.

Parameters
input_string: the string to be formatted.
w: the width to be used.
a: the alignment to be used.
Returns
Format<string> : formatting object to be passed back to the stream.

Definition at line 59 of file strings.cpp.

◆ operator()() [4/4]

Format< std::string > & ecl::Format< std::string >::operator() ( int  w,
Alignment  a 
)

Convenient stream format parameter setter. This one permanently configures the width and alignment as specfied.

Parameters
w: the total width of the text output.
a: the aligning property for the output text.
Returns
Format<String>& : this formatter (for use with streams).

Definition at line 35 of file strings.cpp.

◆ pad()

template<typename OutputStream >
void ecl::Format< std::string >::pad ( int  n,
OutputStream &  ostream 
) const
private

Internally used to pad the output with spaces when requested.

Parameters
n: the number of spaces to pad.
ostream: the streaming operator the formatter is conencted to.

Definition at line 216 of file strings.hpp.

◆ postPad()

template<typename OutputStream >
void ecl::Format< std::string >::postPad ( int  n,
OutputStream &  ostream 
) const
private

Postpad the output with spaces when requested.

Parameters
n: the number of spaces to pad.
ostream: the streaming operator the formatter is conencted to.

Definition at line 203 of file strings.hpp.

◆ prePad()

template<typename OutputStream >
void ecl::Format< std::string >::prePad ( int  n,
OutputStream &  ostream 
) const
private

Prepad the output with spaces when requested.

Parameters
n: the number of spaces to pad.
ostream: the streaming operator the formatter is conencted to.

Definition at line 190 of file strings.hpp.

◆ width()

Format<std::string>& ecl::Format< std::string >::width ( int  w)
inline

Sets the width format parameter. Setting this to -1 will turn off width formatting constraints.

Parameters
w: the total width of the text output.

Definition at line 76 of file strings.hpp.

Friends And Related Function Documentation

◆ operator<<

template<typename OutputStream >
OutputStream& operator<< ( OutputStream &  ostream,
Format< std::string > &  formatter 
)
friend

Insertion operator for formatters. It takes a customised formatter and inserts its current context into the stream. If two formatters are used in succession, it will throw an error (c++ cannot handle two in a single line of streaming). This works on normal c++ streams as well as TextStreams.

Parameters
ostream: the stream to insert the formatted object into.
formatter: the format context.
Returns
OutputStream : a handle to the resultant stream.
Exceptions
StandardException: throws if the formatter is used multiply in one stream operation [debug mode only].

Definition at line 229 of file strings.hpp.

Member Data Documentation

◆ alignment_

Alignment ecl::Format< std::string >::alignment_
private

Definition at line 147 of file strings.hpp.

◆ ready_to_format

bool ecl::Format< std::string >::ready_to_format
private

Definition at line 148 of file strings.hpp.

◆ s

std::string ecl::Format< std::string >::s
private

Definition at line 149 of file strings.hpp.

◆ width_

int ecl::Format< std::string >::width_
private

Definition at line 146 of file strings.hpp.


The documentation for this class was generated from the following files:


ecl_formatters
Author(s): Daniel Stonier
autogenerated on Sun Aug 2 2020 03:12:09