ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::strings::TDec< TChar > Class Template Reference

Description:

template<typename TChar>
class alib::strings::TDec< 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 AppendableTraits 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 AppendableTraits 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 of 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 << Dec( 1234.56 , &NumberFormat::Global );
cout << sample << endl;
which - dependent on the current local setting - might produce:
1.234,56

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

Template Parameters
TCharThe character type of the AString that instances can be "applied" to.

Definition at line 49 of file format.inl.

Public Field Index:

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

Public Method Index:

template<typename TFloat>
requires std::floating_point<TFloat>
 TDec (TFloat value, int overrideWidth=0, TNumberFormat< TChar > *numberFormat=nullptr)
 
template<typename TFloat>
requires std::floating_point<TFloat>
 TDec (TFloat value, TNumberFormat< TChar > *numberFormat=nullptr)
 
template<typename TIntegral>
requires std::integral<TIntegral>
 TDec (TIntegral value, int overrideWidth=0, TNumberFormat< TChar > *numberFormat=nullptr)
 
template<typename TIntegral>
requires std::integral<TIntegral>
 TDec (TIntegral value, TNumberFormat< TChar > *numberFormat=nullptr)
 

Field Details:

◆ fpValue

template<typename TChar>
double alib::strings::TDec< TChar >::fpValue

The value when using constructor with type double.

Definition at line 57 of file format.inl.

◆ nf

template<typename TChar>
TNumberFormat<TChar>* alib::strings::TDec< TChar >::nf

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

Definition at line 60 of file format.inl.

◆ [union]

union { ... } alib::strings::TDec< TChar >::v

The data.

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

◆ value

template<typename TChar>
int64_t alib::strings::TDec< TChar >::value

The value when using constructor with signed integer types.

Definition at line 56 of file format.inl.

◆ valueType

template<typename TChar>
int alib::strings::TDec< TChar >::valueType

Flag witch value to use (1= sInt, 2=uInt, 3=fp )

Definition at line 67 of file format.inl.

◆ width

template<typename TChar>
int alib::strings::TDec< TChar >::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 64 of file format.inl.

Constructor(s) / Destructor Details:

◆ TDec() [1/4]

template<typename TChar>
template<typename TIntegral>
requires std::integral<TIntegral>
alib::strings::TDec< TChar >::TDec ( TIntegral value,
int overrideWidth = 0,
TNumberFormat< TChar > * numberFormat = nullptr )
inline

Constructor. Stores parameters.

Template Parameters
TIntegralThe type of argument value. Deduced by the compiler. Only integral values 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.

Definition at line 80 of file format.inl.

◆ TDec() [2/4]

template<typename TChar>
template<typename TIntegral>
requires std::integral<TIntegral>
alib::strings::TDec< TChar >::TDec ( TIntegral value,
TNumberFormat< TChar > * numberFormat = nullptr )
inline

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

Template Parameters
TIntegralThe type of argument value. Deduced by the compiler. Only integral values are accepted.
Parameters
valueThe value to write.
numberFormatThe number format to use. Defaults to nullptr which chooses the static singleton found in NumberFormat::Computational.

Definition at line 98 of file format.inl.

◆ TDec() [3/4]

template<typename TChar>
template<typename TFloat>
requires std::floating_point<TFloat>
alib::strings::TDec< TChar >::TDec ( TFloat value,
int overrideWidth = 0,
TNumberFormat< TChar > * numberFormat = nullptr )
inline

Constructor. Stores parameters.

Template Parameters
TFloatThe type of argument value. Deduced by the compiler. Only floating-point values 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.

Definition at line 117 of file format.inl.

◆ TDec() [4/4]

template<typename TChar>
template<typename TFloat>
requires std::floating_point<TFloat>
alib::strings::TDec< TChar >::TDec ( TFloat value,
TNumberFormat< TChar > * numberFormat = nullptr )
inline

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

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

Definition at line 133 of file format.inl.


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