Class onumber
Introduction
This class implements various types of numeric string conversions. Class methods basespec and uintspec perform numeric string conversions. Class methods ipv4spec and ipv6spec perform internet address string conversions. The class header file defines numeric string conversion constants that may be referenced by other classes. Such classes may merely include this header file to obtain these constant definitions.
This class is declared in onumber.hpp and defined in onumber.cpp.
Inheritance
None.
Dependence
This class depends on classes oascii and oerror. It also needs custom header file types.h to define custom data type huge_t.
Constants
RADIX_BIN
Radix for string-to-binary and binary-to-string conversion. Value is 2.
RADIX_OCT
Radix for string-to-octal and octal-to-string conversion. Value is 8.
RADIX_DEC
Radix for string-to-decimal and decimal-to-string conversion. Value is 10.
RADIX_HEX
Radix for string-to-hexadecimal and hexadecimal-to-string conversion. Value is 16.
BIN_DIGITS
The maximum number of binary digits needed to represent one octet. Value is 8.
OCT_DIGITS
The maximum number of octal digits needed to represent one octet. Value is 3.
DEC_DIGITS
The maximum number of decimal digits needed to represent one octer. Value is 3.
HEX_DIGITS
The maximum number of hexadecimal digits needed to represent one octet. Value is 2.
BIN_EXTENDER
The character used to separate binary octets. Value is '-' or hyphen.
DEC_EXTENDER
The character used to separate decimal octets. Value is '.' or period.
HEX_EXTENDER
The character used to separate decimal octets. Value is ':' or colon.
IPv4_SIZE
The size of a binary IPv4 address in bytes. Value is 4.
IPv6_SIZE
The size of a binary IPv6 address in bytes. Value is 16.
Properties
None.
Methods
basespec
huge_t onumber::basespecconst char * stringunsigned baseunsigned size
Return the unsigned integer equivalent of a character string. The base argument determines the number base to be used for conversion. If base is 0 the number base is determined by the string prefix where 0b or 0B means binary format, no prefix or od or 0D means decimal format and 0x or 0X means hexadecimal format. Otherwise, the string must conform to the specified number base with, or without, an appropriate prefix. The size argument is the maximum number of bits permitted in the resulting integer. This method is useful for converting strings to integers of unusual size.
uintspec
huge_t onumber::uintspecconst char * stringhuge_t minimumhuge_t maximum
Return the unsigned interger equivalent of a character string. An error occurs if the integer value exceeds the specified maximum or minimum value. Errors are handled by the inherited oerror class.
ipv4spec
size_t onumber::ipv4specconst char * stringvoid * memory
Encode external memory with the binary equivalent of a variable-length IPv4 dotted-decimal string and return the number of bytes encoded.
ipv6spec
size_t onumber::ipv6const char * stringvoid * memory
Encode external memory with the binary equivalent of a variable-length IPv6 hexadecimal string and return the number of bytes encoded.