FARGOS/VISTA Object Management Environment Core
..
|
These functions quickly convert between ASCII and integer, floating-point and fixed-point values. More...
Classes | |
struct | VariableFixedPointValue |
Return value structure for representing fixed-point values with variable precision. More... | |
union | Aligned4Chars |
Table of word-aligned 4-character groups representing 0000-9999. More... | |
Macros | |
#define | CONVERT_UINT_TO_TEXT(varName, sourceVal) uint32_t _workBfr_ ## varName [6]; char *varName = uint_to_ascii(_workBfr_ ## varName, sizeof(_workBfr_ ## varName), sourceVal) |
Convenience macro to declare a work buffer and convert an unsigned value into text. More... | |
#define | CONVERT_INT_TO_TEXT(varName, sourceVal) uint32_t _workBfr_ ## varName [6]; char *varName = int_to_ascii(_workBfr_ ## varName, sizeof(_workBfr_ ## varName), sourceVal); |
Convenience macro to declare a work buffer and convert a signed value into text. If the value is known to be positive, CONVERT_UINT_TO_TEXT() is faster. More... | |
Functions | |
uint_fast32_t | text2uint32 (const char *textString, uint_fast8_t text_len) |
Convert a sequence of text characters into an unsigned integer as quickly as possible. Depending on string length, this routine is between 2-3 times faster than standard routines such as strtol(). Note: text2int32() can be used if negative numbers will be seen. More... | |
int_fast32_t | text2int32 (const char *textString, uint_fast8_t text_len) |
Convert a sequence of text characters into a 32-bit signed integer as quickly as possible. Optional leading "-" or "+" supported. More... | |
uint64_t | text2uint64 (const char *textString, uint_fast8_t text_len) |
Convert a sequence of text characters into a 64-bit unsigned integer as quickly as possible. More... | |
int64_t | text2int64 (const char *textString, uint_fast8_t text_len) |
Convert a sequence of text characters into a 64-bit signed integer as quickly as possible. Optional leading "-" or "+" supported. More... | |
uint32_t | n2to_uint32 (const void *byteData) |
Convert a network byte order 2-byte integer into a native unsigned 32-bit value. More... | |
uint32_t | n4to_uint32 (const void *byteData) |
Convert a network byte order 4-byte integer into a native unsigned 32-bit value. More... | |
uint64_t | n8to_uint64 (const void *byteData) |
Convert a network byte order 8-byte integer into a native unsigned 64-bit value. More... | |
CONSTEXPR uint16_t | const_uint16_ton2 (const uint16_t arg) OME_ALWAYS_INLINE OME_PURE_FUNCTION OME_ALWAYS_OPTIMIZE("-O3") |
Equivalent of htons(), but evaluated at compile time. More... | |
CONSTEXPR uint32_t | const_uint32_ton4 (const uint32_t arg) OME_ALWAYS_INLINE OME_PURE_FUNCTION OME_ALWAYS_OPTIMIZE("-O3") |
Equivalent of htonl(), but evaluated at compile time. More... | |
CONSTEXPR uint64_t | const_uint64_ton8 (const uint64_t arg) OME_ALWAYS_INLINE OME_PURE_FUNCTION OME_ALWAYS_OPTIMIZE("-O3") |
Equivalent of htonll(), but evaluated at compile time. More... | |
char * | uint_to_ascii (uint32_t workBfr[], uint_fast8_t bfrLen, uint64_t value, uint_fast8_t *retStrLen=nullptr) NONNULL_RETURN |
Quickly convert a binary integer into ASCII decimal text. More... | |
char * | int_to_ascii (uint32_t workBfr[], uint_fast8_t bfrLen, int64_t value, uint_fast8_t *retStrLen=nullptr) NONNULL_RETURN |
Identical to uint_to_ascii(), except that negative values are accepted. More... | |
char * | uint_to_ascii_right_justified (uint32_t workBfr[], uint_fast8_t bfrLen, uint64_t value, uint_fast8_t fieldWidth, char fillChar=' ') NONNULL_RETURN |
Convert a binary integer into right-justified ASCII decimal text and pad on the left with a specified fill character. More... | |
char * | fixedpoint_to_ascii (char *resultBfr, uint_fast8_t bfrLen, int64_t value, uint_fast8_t decimals, uint_fast8_t *retStrLen=nullptr, int_fast8_t outputPrecision=-2) NONNULL_RETURN |
Format a fixed-point value with indicated decimal places. More... | |
VariableFixedPointValue | fast_ascii_to_fixedpoint (const char *str, uint_fast8_t len=0, int_fast8_t desiredPrecision=-2) NONNULL_PARAMETERS(1) |
Convert ASCII decimal text string to fixed point representation. More... | |
int64_t | ascii_to_fixedpoint (const char *str, uint_fast8_t *resultPrecision=nullptr, uint_fast8_t len=0, int_fast8_t desiredPrecision=-2) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE |
Convert ASCII decimal text string to fixed point representation. More... | |
double | text2double (const char *str, uint_fast8_t len=0) NONNULL_PARAMETERS(1) |
Convert ASCII decimal text string to a double. More... | |
char * | float_to_ascii (char *resultBfr, uint_fast8_t bfrLen, double value, uint_fast8_t *retStrLen=nullptr, int_fast8_t outputPrecision=-2, bool roundValue=false) NONNULL_PARAMETERS(1) NONNULL_RETURN |
Format a double-precision value with indicated decimal places. More... | |
uint_fast8_t | bytesInUTFcharacter (const char val) |
Return number of bytes required to represent UTF-encoded character as indicated by value of leading byte. More... | |
uint_fast8_t | bytesInUTFchar (const void *s) |
Return number of bytes required to represent UTF-encoded character pointed to by argument. More... | |
template<unsigned int EXPONENT> | |
CONSTEXPR uint64_t | powerOf10Constant () |
Generate compile-time constant for integral power of 10. More... | |
template<unsigned int LEN> | |
uint_fast32_t | right_padded_strlen (const char *s, const char PADDING_CHAR) |
Templated convenience routine to return the length of a possibly padded string. The assumption is that the string is padded on the right with a consistent padding character up to a predefined length. More... | |
template<> | |
uint_fast32_t | right_padded_strlen< 0 > (const char *s, const char PADDING_CHAR) |
specialization to stop recursion at length 0 More... | |
template<uint_fast8_t FIELD_LEN> | |
uint64_t | textField2uint (const char *field) |
Templated ASCII-to-integer conversion routine that very quickly converts fixed-length fields of positive integers. More... | |
template<uint_fast8_t FIELD_LEN> | |
int64_t | textField2int (const char *field) |
Templated ASCII-to-integer conversion routine that converts fixed-length fields. More... | |
CONSTEXPR double | cleanedNumericValue (double v, double minPrecision) |
Return value clipped to 0 if not above a threshold of precision. More... | |
CONSTEXPR double | cleanedPositiveNumericValue (double v, double minPrecision) |
Return value clipped to 0 if not above a threshold of precision. More... | |
template<typename STREAMTYPE > | |
STREAMTYPE & | operator<< (STREAMTYPE &os, const VariableFixedPointValue arg) |
Variables | |
const uint32_t | powersOf10 [10] |
Table of powers-of-10 constants as 32-bit unsigned integers. More... | |
const uint64_t | powersOf10_64bit [16] |
Table of powers-of-10 constants as 64-bit unsigned integers. More... | |
const double | floatingPowersOf10 [10] |
Table of powers-of-10 constants as floating-point values. More... | |
const double | reciprocalPowersOf10 [16] |
Table of reciprocal powers-of-10 divisors. More... | |
const uint32_t | text2int_table [256][10] |
Convert ASCII digit into corresponding 32-bit value. More... | |
const uint64_t | text2int64_table [256][20] |
Convert ASCII digit into corresponding 64-bit value. More... | |
const char | byteAsLowercaseHexadecimal [256][3] |
Table of uppercase hexadecimal characters for each byte value. More... | |
const char | byteAsUppercaseHexadecimal [256][3] |
Table of uppercase hexadecimal characters for each byte value. More... | |
const char | numberAsTwoDigits [100][3] |
Table of 2-character strings representing 00-99. More... | |
const union Aligned4Chars | numberAs4Digits [10000] |
These functions quickly convert between ASCII and integer, floating-point and fixed-point values.
#define CONVERT_INT_TO_TEXT | ( | varName, | |
sourceVal | |||
) | uint32_t _workBfr_ ## varName [6]; char *varName = int_to_ascii(_workBfr_ ## varName, sizeof(_workBfr_ ## varName), sourceVal); |
Convenience macro to declare a work buffer and convert a signed value into text. If the value is known to be positive, CONVERT_UINT_TO_TEXT() is faster.
varName | specifies the name of the new variable to be declared. It will point to the text result. |
sourceVal | specifies the integer value to be converted |
#define CONVERT_UINT_TO_TEXT | ( | varName, | |
sourceVal | |||
) | uint32_t _workBfr_ ## varName [6]; char *varName = uint_to_ascii(_workBfr_ ## varName, sizeof(_workBfr_ ## varName), sourceVal) |
Convenience macro to declare a work buffer and convert an unsigned value into text.
varName | specifies the name of the new variable to be declared. It will point to the text result. |
sourceVal | specifies the integer value to be converted |
|
inline |
Convert ASCII decimal text string to fixed point representation.
str | points to the text string to be converted |
resultPrecision | is an optional argument that points at a location into which the apparent precision of the source string will be stored. |
len | is an optional argument that indicates the length of the source string. If specified as 0, strlen() will be used to determine the length. |
desiredPrecision | is an optional parameter that specifies the desired precision of the result; it will be scaled to meet the constraint. A value of -2 indicates to use the precision implied by the source string. |
References fast_ascii_to_fixedpoint(), VariableFixedPointValue::precision, and VariableFixedPointValue::value.
Referenced by text2double().
|
inline |
Return number of bytes required to represent UTF-encoded character pointed to by argument.
References bytesInUTFcharacter(), and s.
|
inline |
Return number of bytes required to represent UTF-encoded character as indicated by value of leading byte.
References OME_EXPECT_TRUE, and Aligned4Chars::val.
Referenced by bytesInUTFchar().
|
inline |
Return value clipped to 0 if not above a threshold of precision.
v | specifies the value |
minPrecision | specifies the minimum precision. |
|
inline |
Return value clipped to 0 if not above a threshold of precision.
v | specifies the value that is supposed to be positive. |
minPrecision | specifies the minimum precision. |
The value of zero will be returned if v is not at least minPrecision. Note that this means that any values below minPrecision will be treated as 0.
|
inline |
Equivalent of htons(), but evaluated at compile time.
|
inline |
Equivalent of htonl(), but evaluated at compile time.
|
inline |
Equivalent of htonll(), but evaluated at compile time.
VariableFixedPointValue fast_ascii_to_fixedpoint | ( | const char * | str, |
uint_fast8_t | len = 0 , |
||
int_fast8_t | desiredPrecision = -2 |
||
) |
Convert ASCII decimal text string to fixed point representation.
str | points to the text string to be converted |
len | is an optional argument that indicates the length of the source string. If specified as 0, strlen() will be used to determine the length. |
desiredPrecision | is an optional parameter that specifies the desired precision of the result; it will be scaled to meet the constraint. A value of -2 indicates to use the precision implied by the source string. |
References l, OME_EXPECT_TRUE, OME_PREFETCH, powersOf10_64bit, VariableFixedPointValue::precision, text2int64(), text2uint64(), and VariableFixedPointValue::value.
Referenced by ascii_to_fixedpoint(), and defaultConvertAndTransferField().
char* fixedpoint_to_ascii | ( | char * | resultBfr, |
uint_fast8_t | bfrLen, | ||
int64_t | value, | ||
uint_fast8_t | decimals, | ||
uint_fast8_t * | retStrLen = nullptr , |
||
int_fast8_t | outputPrecision = -2 |
||
) |
Format a fixed-point value with indicated decimal places.
resultBfr | provides space into which the ASCII decimal text will be placed. |
bfrLen | specifies the length of the provided buffer. |
value | specifies the fixed-point value to be output. |
decimals | specifies the implied number of decimal places of precision. |
retStrLen | is an optional argument that points to a location into which the size of the result string will be placed. |
outputPrecision | is an optional parameter that specifies the desired output precision of the formatted result. The default value of -2 is used to indicate the precision specified by decimals should be used as-is. A value of -3 is used to request truncation to the minimum required precision. A value of -1 indicates truncation to an integer with no decimal point whereas a value of 0 will truncate to an integer result but retain a trailing decimal point. |
References int_to_ascii(), OME_EXPECT_FALSE, OME_EXPECT_TRUE, and stderr.
Referenced by defaultConvertAndTransferField(), float_to_ascii(), LogMessageRecord::formatRecordAsText(), operator<<(), and ReadBinaryLog::outputAssembledLine().
char* float_to_ascii | ( | char * | resultBfr, |
uint_fast8_t | bfrLen, | ||
double | value, | ||
uint_fast8_t * | retStrLen = nullptr , |
||
int_fast8_t | outputPrecision = -2 , |
||
bool | roundValue = false |
||
) |
Format a double-precision value with indicated decimal places.
resultBfr | provides space into which the ASCII text will be placed. |
bfrLen | specifies the length of the provided buffer. |
value | specifies the floating-point value to be output. |
retStrLen | is an optional argument that points to a location into which the size of the result string will be placed. |
outputPrecision | is an optional parameter that specifies the desired output precision of the formatted result. The value of -2 is used to indicate a minimal amount of precision should be used, but at least one decimal place will be displayed. A value of -1 indicates truncation to an integer with no decimal point whereas a value of 0 will truncate to an integer result but retain a trailing decimal point. |
roundValue | is an optional Boolean flag that indicates if the floating-point value should be rounded to the nearest integer or simply truncated (the default operation). |
References fixedpoint_to_ascii(), floatingPowersOf10, OME_EXPECT_FALSE, OME_EXPECT_TRUE, OME_PREFETCH, and safe_strcpy.
Referenced by defaultConvertAndTransferField(), LogMessageRecord::formatRecordAsText(), and OMEtype::outputOnStream().
char* int_to_ascii | ( | uint32_t | workBfr[], |
uint_fast8_t | bfrLen, | ||
int64_t | value, | ||
uint_fast8_t * | retStrLen = nullptr |
||
) |
Identical to uint_to_ascii(), except that negative values are accepted.
References uint_to_ascii().
Referenced by defaultConvertAndTransferField(), fixedpoint_to_ascii(), LogMessageRecord::formatRecordAsText(), and OMEtype::outputOnStream().
|
inline |
Convert a network byte order 2-byte integer into a native unsigned 32-bit value.
|
inline |
Convert a network byte order 4-byte integer into a native unsigned 32-bit value.
Referenced by defaultConvertAndTransferField().
|
inline |
Convert a network byte order 8-byte integer into a native unsigned 64-bit value.
STREAMTYPE& operator<< | ( | STREAMTYPE & | os, |
const VariableFixedPointValue | arg | ||
) |
|
inline |
Generate compile-time constant for integral power of 10.
NOTE: the return type is a 64-bit unsigned, which permits values of up to 10-to-the-19th to be represented. Currently EXPONENT values greater than 19 are accepted without complaint.
Referenced by TimePointOfGranularity< UNITS >::operator=().
|
inline |
Templated convenience routine to return the length of a possibly padded string. The assumption is that the string is padded on the right with a consistent padding character up to a predefined length.
s | points to the string to be examined. |
PADDING_CHAR | specifies the padding character; it defaults to a space. |
constexpr
, the compiler can determine the length at compile time if the source was compiled with optimization and the function was passed a string constant. References s.
|
inline |
specialization to stop recursion at length 0
double text2double | ( | const char * | str, |
uint_fast8_t | len = 0 |
||
) |
Convert ASCII decimal text string to a double.
str | points to the text string to be converted |
len | is an option argument that indicates the length of the source string. If specified as 0, strlen() will be used to determine the length. |
References ascii_to_fixedpoint(), floatingPowersOf10, OME_EXPECT_TRUE, reciprocalPowersOf10, and text2int32().
|
inline |
Convert a sequence of text characters into a 32-bit signed integer as quickly as possible. Optional leading "-" or "+" supported.
References OME_EXPECT_TRUE, OME_PREFETCH, text2uint32(), and Aligned4Chars::val.
Referenced by text2double().
|
inline |
Convert a sequence of text characters into a 64-bit signed integer as quickly as possible. Optional leading "-" or "+" supported.
References OME_EXPECT_TRUE, OME_PREFETCH, text2uint64(), and Aligned4Chars::val.
Referenced by fast_ascii_to_fixedpoint().
|
inline |
Convert a sequence of text characters into an unsigned integer as quickly as possible. Depending on string length, this routine is between 2-3 times faster than standard routines such as strtol(). Note: text2int32() can be used if negative numbers will be seen.
References CACHE_LINE_LENGTH, OME_PREFETCH, and text2int_table.
Referenced by TimePointOfGranularity< UNITS >::convertDayAndTime(), Parse_And_Process_HTTP_Stream::processHTTPheader(), GenericSocketAddress::setFromURL(), and text2int32().
|
inline |
Convert a sequence of text characters into a 64-bit unsigned integer as quickly as possible.
References CACHE_LINE_LENGTH, OME_PREFETCH, and text2int64_table.
Referenced by fast_ascii_to_fixedpoint(), and text2int64().
int64_t textField2int | ( | const char * | field | ) |
Templated ASCII-to-integer conversion routine that converts fixed-length fields.
FIELD_LEN is the template parameter and specifies the field length. Unlike text2uint(), the length of the field is must be known at compile time.
field | points at the start of the text field. |
|
inline |
Templated ASCII-to-integer conversion routine that very quickly converts fixed-length fields of positive integers.
FIELD_LEN is the template parameter and specifies the field length. Unlike text2uint(), the length of the field is must be known at compile time.
field | points at the start of the text field. |
This routine can be more than 5 to 8 times faster than standard routines such as strtol(). Unfortunately, the opportunity for a field's length to be known at compile time is rarely encountered. One compromise is to add the overhead of a test on field length and then select the custom call for that particular length.
char* uint_to_ascii | ( | uint32_t | workBfr[], |
uint_fast8_t | bfrLen, | ||
uint64_t | value, | ||
uint_fast8_t * | retStrLen = nullptr |
||
) |
Quickly convert a binary integer into ASCII decimal text.
workBfr | provides space into which the ASCII text will be placed. An array of uint32_t is requested in order to ensure proper alignment for performance (and correctness on machines where unaligned access results in a bus error). A minimum of a 6-element uint32_t array is required. |
bfrLen | specifies the size of the provided work buffer in bytes; at least 24 bytes should be provided. This value should always be a multiple of sizeof(uint32_t), which is 4. |
value | specifies the 64-bit unsigned value to be output. |
retStrLen | is an optional argument that points at an uint32_t that will be provided with the length of the generated string. |
References Aligned4Chars::digits, Aligned4Chars::lastThreeDigits, Aligned4Chars::lastTwoDigits, numberAs4Digits, OME_EXPECT_TRUE, and Aligned4Chars::val.
Referenced by defaultConvertAndTransferField(), LogMessageRecord::formatRecordAsText(), int_to_ascii(), ReadBinaryLog::outputAssembledLine(), OMEtype::outputOnStream(), and uint_to_ascii_right_justified().
char* uint_to_ascii_right_justified | ( | uint32_t | workBfr[], |
uint_fast8_t | bfrLen, | ||
uint64_t | value, | ||
uint_fast8_t | fieldWidth, | ||
char | fillChar = ' ' |
||
) |
Convert a binary integer into right-justified ASCII decimal text and pad on the left with a specified fill character.
workBfr | provides space into which the ASCII text will be placed. An array of uint32_t is requested in order to ensure proper alignment for performance (and correctness on machines where unaligned access results in a bus error). A minimum of a 6-element uint32_t array is required. |
bfrLen | specifies the size of the provided work buffer in bytes; at least 24 bytes should be provided. |
value | specifies the 64-bit unsigned value to be output. |
fieldWidth | specifies the desired width of the field. |
fillChar | specifies the fill character to pad unused positions on the left. If not specified, it defaults to a space. |
References uint_to_ascii().
Referenced by TimePointOfGranularity< UNITS >::formatIntoString().
const char byteAsLowercaseHexadecimal[256][3] |
Table of uppercase hexadecimal characters for each byte value.
Referenced by LogMessageRecord::formatRecordAsText(), operator<<(), and ReadBinaryLog::outputAssembledLine().
const char byteAsUppercaseHexadecimal[256][3] |
Table of uppercase hexadecimal characters for each byte value.
Referenced by LogMessageRecord::formatRecordAsText(), operator<<(), and ReadBinaryLog::outputAssembledLine().
const double floatingPowersOf10[10] |
Table of powers-of-10 constants as floating-point values.
Referenced by float_to_ascii(), and text2double().
const union Aligned4Chars numberAs4Digits[10000] |
const char numberAsTwoDigits[100][3] |
Table of 2-character strings representing 00-99.
Referenced by TimePointOfGranularity< UNITS >::formatIntoString().
const uint32_t powersOf10[10] |
Table of powers-of-10 constants as 32-bit unsigned integers.
Referenced by defaultConvertAndTransferField().
const uint64_t powersOf10_64bit[16] |
Table of powers-of-10 constants as 64-bit unsigned integers.
Referenced by fast_ascii_to_fixedpoint().
const double reciprocalPowersOf10[16] |
Table of reciprocal powers-of-10 divisors.
It is often an order-of-magnitude faster to multiply by a reciprocal than perform a division, so this table of reciprocals is used to divide numbers by various powers-of-10.
Referenced by text2double().
const uint64_t text2int64_table[256][20] |
Convert ASCII digit into corresponding 64-bit value.
Referenced by text2uint64().
const uint32_t text2int_table[256][10] |
Convert ASCII digit into corresponding 32-bit value.
Referenced by text2uint32().
![]() | Generated: Fri Jul 31 2020 18:19:16
Support Information |