Encapsulation of an integer type as an AbstractNumber.
More...
#include <tsInteger.h>
|
using | int_t = INT_T |
| The underlying signed integer type.
|
|
|
| Integer ()=default |
| Default constructor, implicitly initialized to zero.
|
|
template<typename INT2 >
requires std::integral<INT2> |
| Integer (INT2 i) |
| Constructor.
|
|
Integer | abs () const |
| Get the absolute value.
|
|
virtual ts::UString | description () const override |
| Get a textual description of the values of that type.
|
|
bool | divOverflow (const Integer &x) const |
| Check if this Integer number generates an overflow when divided by another Integer.
|
|
virtual bool | fromString (const UString &str, UChar separator=COMMA, UChar decimal_dot=FULL_STOP) override |
| Parse a string and interpret it as a number.
|
|
virtual bool | inRange (int64_t min, int64_t max) const override |
| Check if the value of the number is within a range of integer value.
|
|
Integer | max (const Integer &x) const |
| Get the maximum value of two fixed-point numbers.
|
|
Integer | min (const Integer &x) const |
| Get the minimum value of two fixed-point numbers.
|
|
bool | mulOverflow (const Integer &x) const |
| Check if this Integer number generates an overflow when multiplied by another Integer.
|
|
template<typename INT2 >
requires std::integral<INT2> |
bool | mulOverflow (INT2 x) const |
| Check if this Integer number generates an overflow when multiplied by an integer.
|
|
virtual double | toDouble () const override |
| Conversion to double value.
|
|
int_t | toInt () const |
| Conversion to integral units.
|
|
virtual int64_t | toInt64 () const override |
| Conversion to a 64-bit signed integer value.
|
|
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 override |
| Convert the number to a string object.
|
|
|
static const AbstractNumber *const | INVALID |
| Pointer to an invalid instance of AbstractNumber.
|
|
static const Integer | MAX |
| The maximum representable value of this fixed-point type.
|
|
static const Integer | MIN |
| The minimum representable value of this fixed-point type.
|
|
|
static void | Deformat (UString &str, UChar separator, UChar decimal_dot) |
| Static common utility to deformat a string containing a number.
|
|
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.
|
|
template<typename INT_T>
requires std::integral<INT_T>
class ts::Integer< INT_T >
Encapsulation of an integer type as an AbstractNumber.
- Template Parameters
-
INT_T | The underlying integer type. |
◆ Integer()
template<typename INT_T >
template<typename INT2 >
requires std::integral<INT2>
Constructor.
- Template Parameters
-
INT2 | Some other integer type (signed or unsigned). |
- Parameters
-
◆ description()
template<typename INT_T >
requires std::integral<INT_T>
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.
Implements ts::AbstractNumber.
◆ inRange()
template<typename INT_T >
requires std::integral<INT_T>
bool ts::Integer< INT_T >::inRange |
( |
int64_t |
min, |
|
|
int64_t |
max |
|
) |
| const |
|
overridevirtual |
Check if the value of the number is within a range of integer value.
- Parameters
-
[in] | min | Minimum integer value (inclusive). |
[in] | max | Maximum integer value (inclusive). |
- Returns
- True if this number is within the range min to max, inclusive.
Implements ts::AbstractNumber.
◆ toInt64()
template<typename INT_T >
requires std::integral<INT_T>
Conversion to a 64-bit signed integer value.
- Returns
- The value in integral units. Underflow or overflow rounding is applied when necessary.
Implements ts::AbstractNumber.
◆ toDouble()
template<typename INT_T >
requires std::integral<INT_T>
◆ fromString()
template<typename INT_T >
requires std::integral<INT_T>
Parse a string and interpret it as a number.
The content of this object is updated from the parsed string.
- Parameters
-
[in] | str | A string to parse, representing this object. |
[in] | separator | Separator character for groups of thousands, a comma by default. |
[in] | decimal_dot | The 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.
Implements ts::AbstractNumber.
◆ toString()
template<typename INT_T >
requires std::integral<INT_T>
Convert the number to a string object.
- Parameters
-
[in] | min_width | Minimum width of the returned string. Padded with pad characters if larger than the number of characters in the formatted number. |
[in] | right_justified | If 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] | separator | Separator character for groups of thousands, a comma by default. CHAR_NULL means no separator. |
[in] | force_sign | If true, force a '+' sign for positive values. |
[in] | decimals | Precision to use after the decimal point. NPOS means default. |
[in] | force_decimals | If 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_dot | The decimal separator, a dot by default. |
[in] | pad | The padding character to adjust the width. |
- Returns
- The formatted string.
Implements ts::AbstractNumber.
◆ toInt()
template<typename INT_T >
Conversion to integral units.
- Returns
- The value in integral units. Underflow or overflow rounding is applied when necessary.
◆ abs()
template<typename INT_T >
Get the absolute value.
- Returns
- The absolute value of this fixed-point number.
◆ max()
template<typename INT_T >
Get the maximum value of two fixed-point numbers.
- Parameters
-
[in] | x | Another fixed-point number. |
- Returns
- The maximum value of this fixed-point number and x.
◆ min()
template<typename INT_T >
Get the minimum value of two fixed-point numbers.
- Parameters
-
[in] | x | Another fixed-point number. |
- Returns
- The minimum value of this fixed-point number and x.
◆ mulOverflow() [1/2]
template<typename INT_T >
template<typename INT2 >
requires std::integral<INT2>
Check if this Integer number generates an overflow when multiplied by an integer.
- Template Parameters
-
INT2 | Another integer type. |
- Parameters
-
[in] | x | An integer of type INT2. |
- Returns
- True if this Integer number generates an overflow when multiplied by x.
◆ mulOverflow() [2/2]
template<typename INT_T >
Check if this Integer number generates an overflow when multiplied by another Integer.
- Parameters
-
- Returns
- True if this Integer number generates an overflow when multiplied by x.
◆ divOverflow()
template<typename INT_T >
Check if this Integer number generates an overflow when divided by another Integer.
The method is present for compliance with other AbstractNumber subclasses.
- Parameters
-
- Returns
- Always false. There is no possible division overflow with Integer.
◆ 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 |
|
) |
| |
|
staticprotectedinherited |
Static common utility to format a string containing a number with or without decimal part.
- Parameters
-
[in,out] | str | String to format. |
[in] | min_width | Minimum width of the string. |
[in] | right_justified | If true (the default), return a right-justified string. |
[in] | separator | Separator character for groups of thousands. |
[in] | add_plus_sign | If true, force a '+' sign before the number. |
[in] | decimals | Precision to use after the decimal point. NPOS not allowed. |
[in] | force_decimals | If true, force a decimal dot and the number of decimal digits. For integer types, use force_decimals == true and decimals == 0. |
[in] | decimal_dot | The decimal separator. |
[in] | pad | The padding character to adjust the width. |
◆ Deformat()
static void ts::AbstractNumber::Deformat |
( |
UString & |
str, |
|
|
UChar |
separator, |
|
|
UChar |
decimal_dot |
|
) |
| |
|
staticprotectedinherited |
Static common utility to deformat a string containing a number.
- Parameters
-
[in,out] | str | String to deformat. |
[in] | separator | Separator character for groups of thousands. |
[in] | decimal_dot | The decimal separator. |
◆ INVALID
The documentation for this class was generated from the following file: