ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
Inner Classes | Public Fields | Public Methods | List of all members
TFormat< TChar > Class Template Reference

#include <format.hpp>

Class Description

template<typename TChar>
class aworx::lib::strings::TFormat< TChar >


This is a type purely made to be appended to objects of type AString. Various constructors accept integer and floating point values, along with formatting options. The specialization of functor T_Append will use a given (or defaulted) instance of class NumberFormat to format the encapsulated value and append the result to the AString in question.

Note
Within the same header file that this class in declared in, there are several specializations of functor T_Append defined for plain integer and floating point types. These specializations create an object of this type, providing the value only, hence, using this classes constructor's default values. The number format used as default by the constructors of this class is NumberFormat::Computational. As a result, the application of such core types, as in:
AString sample;
sample << 1234.56;
cout << sample << endl;
which produces:
1234.56
does not use a locale specific number format. Instead it uses one that is exchangeable between applications independent from the locale setting of the executing machine.
Consequently, for locale specific output, an object of this class needs to be appended along with a locale enabled instance of NumberFormat. For example:
AString sample;
sample << Format( 1234.56 , &NumberFormat::Global );
cout << sample << endl;
which - dependent on the current local setting - might produce:
1.234,56

Inner Types:
Besides accepting plain number types, this class in addition aggregates several public inner types, namely

Each of these classes provide certain formatting options, which are implemented by a corresponding specialization of functor T_Append.

Note
The types are not 'physically' related to this class. Instead, they have been aggregated here as a design decision.

Details on Formats:
Details on the options of formatting integer and floating point numbers are documented with class NumberFormat.

Template Parameters
TCharThe character type.
Alias names for specializations of this class using character types character, nchar, wchar, xchar, complementChar and strangeChar are provided in namespace aworx with type definitions Format, NFormat, WFormat, XFormat, ComplementFormat and StrangeFormat.

Definition at line 84 of file format.hpp.

Inner Classes

struct  Bin
 
struct  Escape
 
struct  Field
 
struct  Hex
 
struct  Oct
 
struct  Tab
 

Public Fields

TNumberFormat< TChar > * nf
 
union {
   double   fpValue
 The value when using constructor with type double.
 
   int64_t   value
 The value when using constructor with signed integer types.
 
v
 The data. More...
 
int valueType
 Flag witch value to use (1= sInt, 2=uInt, 3=fp )
 
int width
 

Public Methods

template<typename T >
 TFormat (T value, int overrideWidth=0, TNumberFormat< TChar > *numberFormat=nullptr)
 
template<typename T >
 TFormat (T value, TNumberFormat< TChar > *numberFormat=nullptr)
 

Constructor & Destructor Documentation

◆ TFormat() [1/2]

TFormat ( value,
int  overrideWidth = 0,
TNumberFormat< TChar > *  numberFormat = nullptr 
)
inline

Constructor. Stores parameters.

Template Parameters
TThe type of argument value. Deduced by the compiler. Integer and floating-point types are accepted
Parameters
valueThe value to write.
overrideWidthDefaults to 0 which denotes to choose the value of field NumberFormat::DecMinimumFieldWidth.
numberFormatThe number format to use. Defaults to nullptr which chooses the static singleton found in NumberFormat::Computational.

◆ TFormat() [2/2]

TFormat ( value,
TNumberFormat< TChar > *  numberFormat = nullptr 
)
inline

Alternative constructor that omits parameter width and set it to 0.

Template Parameters
TThe type of argument value. Deduced by the compiler. Integer and floating-point types are accepted
Parameters
valueThe value to write.
numberFormatThe number format to use. Defaults to nullptr which chooses the static singleton found in NumberFormat::Computational.

Member Data Documentation

◆ nf

TNumberFormat<TChar>* nf

The number format to use. Defaults to nullptr which chooses the static singleton found in NumberFormat::Computational.

Definition at line 448 of file format.hpp.

◆ v

union { ... } v

The data.

The union to hold an integral or floating point value provided with the different constructors.

◆ width

int width

The minimum width of the number to write. Defaults to 0 which denotes to choose the value of field NumberFormat::DecMinimumFieldWidth.

Definition at line 452 of file format.hpp.


The documentation for this class was generated from the following file:
aworx::lib::strings::TNumberFormat< character >::Global
static TNumberFormat Global
Definition: numberformat.hpp:150
aworx::Format
lib::strings::TFormat< character > Format
Type alias in namespace aworx.
Definition: strings/fwds.hpp:305
aworx::AString
lib::strings::TAString< character > AString
Type alias in namespace aworx.
Definition: strings/fwds.hpp:135