TSDuck Version 3.32-2820 (TSDuck - The MPEG Transport Stream Toolkit)
ts::AbstractNumber Class Referenceabstract

Abstract base class for different representations of "numbers". More...

Inheritance diagram for ts::AbstractNumber:
Collaboration diagram for ts::AbstractNumber:

Public Member Functions

virtual ~AbstractNumber ()
 Virtual destructor.
 
virtual UString description () const =0
 Get a textual description of the values of that type. More...
 
virtual bool fromString (const UString &str, UChar separator=COMMA, UChar decimal_dot=FULL_STOP)=0
 Parse a string and interpret it as a number. More...
 
virtual bool inRange (int64_t min, int64_t max) const =0
 Check if the value of the number is within a range of integer value. More...
 
virtual double toDouble () const =0
 Conversion to double value. More...
 
virtual int64_t toInt64 () const =0
 Conversion to a 64-bit signed integer value. More...
 
virtual UString toString (size_t min_width=0, bool right_justified=true, UChar separator=COMMA, bool force_sign=false, size_t decimals=NPOS, bool force_decimals=false, UChar decimal_dot=FULL_STOP, UChar pad=SPACE) const =0
 Convert the number to a string object. More...
 

Static Public Attributes

static const AbstractNumber *const INVALID
 Pointer to an invalid instance of AbstractNumber. More...
 

Static Protected Member Functions

static void Deformat (UString &str, UChar separator, UChar decimal_dot)
 Static common utility to deformat a string containing a number. More...
 
static void Format (UString &str, size_t min_width, bool right_justified, UChar separator, bool add_plus_sign, size_t decimals, bool force_decimals, UChar decimal_dot, UChar pad)
 Static common utility to format a string containing a number with or without decimal part. More...
 

Detailed Description

Abstract base class for different representations of "numbers".

All arithmetic and comparison operators shall be defined by concrete subclasses between number instances and between a number instance and an integer value, both directions.

See also
FixedPoint
Fraction
Double

Member Function Documentation

◆ toString()

virtual UString ts::AbstractNumber::toString ( size_t  min_width = 0,
bool  right_justified = true,
UChar  separator = COMMA,
bool  force_sign = false,
size_t  decimals = NPOS,
bool  force_decimals = false,
UChar  decimal_dot = FULL_STOP,
UChar  pad = SPACE 
) const
pure virtual

Convert the number to a string object.

Parameters
[in]min_widthMinimum width of the returned string. Padded with pad characters if larger than the number of characters in the formatted number.
[in]right_justifiedIf true (the default), return a right-justified string. When false, return a left-justified string. Ignored if min_width is lower than the number of characters in the formatted number.
[in]separatorSeparator character for groups of thousands, a comma by default. CHAR_NULL means no separator.
[in]force_signIf true, force a '+' sign for positive values.
[in]decimalsPrecision to use after the decimal point. NPOS means default.
[in]force_decimalsIf true, with positive precision, force a decimal dot and the number of decimal digits of the precision. By default, skip non significant decimal digits.
[in]decimal_dotThe decimal separator, a dot by default.
[in]padThe padding character to adjust the width.
Returns
The formatted string.

Implemented in ts::Integer< INT_T, type >, ts::Fraction< INT_T, type >, ts::FloatingPoint< FLOAT_T, PREC, type >, and ts::FixedPoint< INT_T, PREC, type >.

◆ fromString()

virtual bool ts::AbstractNumber::fromString ( const UString str,
UChar  separator = COMMA,
UChar  decimal_dot = FULL_STOP 
)
pure virtual

Parse a string and interpret it as a number.

The content of this object is updated from the parsed string.

Parameters
[in]strA string to parse, representing this object.
[in]separatorSeparator character for groups of thousands, a comma by default.
[in]decimal_dotThe decimal separator, a dot by default.
Returns
True if the str is valid, false otherwise. In case of parsing error, the content of this object is undefined.

Implemented in ts::Integer< INT_T, type >, ts::Fraction< INT_T, type >, ts::FloatingPoint< FLOAT_T, PREC, type >, and ts::FixedPoint< INT_T, PREC, type >.

◆ toInt64()

virtual int64_t ts::AbstractNumber::toInt64 ( ) const
pure virtual

Conversion to a 64-bit signed integer value.

Returns
The value in integral units. Underflow or overflow rounding is applied when necessary.

Implemented in ts::Integer< INT_T, type >, ts::Fraction< INT_T, type >, ts::FloatingPoint< FLOAT_T, PREC, type >, and ts::FixedPoint< INT_T, PREC, type >.

◆ toDouble()

virtual double ts::AbstractNumber::toDouble ( ) const
pure virtual

Conversion to double value.

Returns
The value as a double.

Implemented in ts::Integer< INT_T, type >, ts::Fraction< INT_T, type >, ts::FloatingPoint< FLOAT_T, PREC, type >, and ts::FixedPoint< INT_T, PREC, type >.

◆ inRange()

virtual bool ts::AbstractNumber::inRange ( int64_t  min,
int64_t  max 
) const
pure virtual

Check if the value of the number is within a range of integer value.

Parameters
[in]minMinimum integer value (inclusive).
[in]maxMaximum integer value (inclusive).
Returns
True if this number is within the range min to max, inclusive.

Implemented in ts::Integer< INT_T, type >, ts::Fraction< INT_T, type >, ts::FloatingPoint< FLOAT_T, PREC, type >, and ts::FixedPoint< INT_T, PREC, type >.

◆ description()

virtual UString ts::AbstractNumber::description ( ) const
pure virtual

Get a textual description of the values of that type.

This is typically used in help texts.

Returns
A textual description of the values of that type.

Implemented in ts::Integer< INT_T, type >, ts::Fraction< INT_T, type >, ts::FloatingPoint< FLOAT_T, PREC, type >, and ts::FixedPoint< INT_T, PREC, type >.

◆ Format()

static void ts::AbstractNumber::Format ( UString str,
size_t  min_width,
bool  right_justified,
UChar  separator,
bool  add_plus_sign,
size_t  decimals,
bool  force_decimals,
UChar  decimal_dot,
UChar  pad 
)
staticprotected

Static common utility to format a string containing a number with or without decimal part.

Parameters
[in,out]strString to format.
[in]min_widthMinimum width of the string.
[in]right_justifiedIf true (the default), return a right-justified string.
[in]separatorSeparator character for groups of thousands.
[in]add_plus_signIf true, force a '+' sign before the number.
[in]decimalsPrecision to use after the decimal point. NPOS not allowed.
[in]force_decimalsIf true, force a decimal dot and the number of decimal digits. For integer types, use force_decimals == true and decimals == 0.
[in]decimal_dotThe decimal separator.
[in]padThe padding character to adjust the width.

◆ Deformat()

static void ts::AbstractNumber::Deformat ( UString str,
UChar  separator,
UChar  decimal_dot 
)
staticprotected

Static common utility to deformat a string containing a number.

Parameters
[in,out]strString to deformat.
[in]separatorSeparator character for groups of thousands.
[in]decimal_dotThe decimal separator.

Member Data Documentation

◆ INVALID

const AbstractNumber* const ts::AbstractNumber::INVALID
static

Pointer to an invalid instance of AbstractNumber.

Its toString() method always return an empty string.


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