|
| BSLMF_NESTED_TRAIT_DECLARATION (JsonNumber, bslmf::IsBitwiseMoveable) |
|
| JsonNumber () |
|
| JsonNumber (const allocator_type &allocator) |
|
| JsonNumber (const char *text, const allocator_type &allocator=allocator_type()) |
|
| JsonNumber (const bsl::string_view &text, const allocator_type &allocator=allocator_type()) |
|
| JsonNumber (bslmf::MovableRef< bsl::string > text) |
|
| JsonNumber (bslmf::MovableRef< bsl::string > text, const allocator_type &allocator) |
|
| JsonNumber (int value, const allocator_type &allocator=allocator_type()) |
|
| JsonNumber (unsigned int value, const allocator_type &allocator=allocator_type()) |
|
| JsonNumber (bsls::Types::Int64 value, const allocator_type &allocator=allocator_type()) |
|
| JsonNumber (bsls::Types::Uint64 value, const allocator_type &allocator=allocator_type()) |
|
| JsonNumber (float value, const allocator_type &allocator=allocator_type()) |
|
| JsonNumber (double value, const allocator_type &allocator=allocator_type()) |
|
| JsonNumber (bdldfp::Decimal64 value, const allocator_type &allocator=allocator_type()) |
|
| JsonNumber (const JsonNumber &original, const allocator_type &allocator=allocator_type()) |
|
| JsonNumber (bslmf::MovableRef< JsonNumber > original) BSLS_KEYWORD_NOEXCEPT |
|
| JsonNumber (bslmf::MovableRef< JsonNumber > original, const allocator_type &allocator) |
|
| ~JsonNumber ()=default |
|
JsonNumber & | operator= (const JsonNumber &rhs) |
|
JsonNumber & | operator= (bslmf::MovableRef< JsonNumber > rhs) |
|
JsonNumber & | operator= (int rhs) |
|
JsonNumber & | operator= (unsigned int rhs) |
|
JsonNumber & | operator= (bsls::Types::Int64 rhs) |
|
JsonNumber & | operator= (bsls::Types::Uint64 rhs) |
|
JsonNumber & | operator= (float rhs) |
|
JsonNumber & | operator= (double rhs) |
|
JsonNumber & | operator= (bdldfp::Decimal64 rhs) |
|
void | swap (JsonNumber &other) |
|
bool | isEqual (const JsonNumber &other) const |
|
bool | isIntegral () const |
|
const bsl::string & | value () const |
| Return the textual representation of this JsonNumber .
|
|
int | asInt (int *result) const |
|
int | asInt64 (bsls::Types::Int64 *result) const |
|
int | asUint (unsigned int *result) const |
|
int | asUint64 (bsls::Types::Uint64 *result) const |
|
float | asFloat () const |
|
double | asDouble () const |
|
bdldfp::Decimal64 | asDecimal64 () const |
|
int | asDecimal64Exact (bdldfp::Decimal64 *result) const |
|
bslma::Allocator *BSLS_ANNOTATION_DEPRECATED | allocator () const |
|
allocator_type | get_allocator () const |
| Return the allocator used by this object to supply memory.
|
|
bsl::ostream & | print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const |
|
This class defines a value-semantic class that represents a JSON number. Objects of this class have a value determined at construction and does not change except by assignment from or swap with another JsonNumber
object. The value can be specified by supplying a string that conforms to the {JSON Textual Specification} or from one of the {Supported Types}. The value of a JSON object can be converted to any of those types; however, some of those conversions can be inexact.
See bdljsn_jsonnumber
Load to the specified result
the closest floating point representation to this number, even if a non-zero status is returned. Return 0 if this number can be represented exactly, and return k_INEXACT
and load result
with the closest approximation if value
cannot be represented exactly. If this number is outside the representable range, load result
with +INF
or -INF
(as appropriate). A number can be represented exactly as a Decimal64
if, for the significand and exponent, abs(significand) <= 9,999,999,999,999,999
and -398 <= exponent <= 369
.
int bdljsn::JsonNumber::asInt |
( |
int * |
result | ) |
const |
|
inline |
Load into the specified result
the integer value of this number. Return 0 on success, k_OVERFLOW
if value
is larger than can be represented by result
, k_UNDERFLOW
if value
is smaller than can be represented by result
, and k_NOT_INTEGRAL
if value
is not an integral number (i.e., there is a fractional part). For underflow, result
will be loaded with the minimum representable value, for overflow, result
will be loaded with the maximum representable value, for non-integral values result
will be loaded with the integer part of value
(truncating the fractional part). If the result is not an integer and also either overflows or underflows, it is treated as an overflow or underflow (respectively). Note that this operation returns an error status value (unlike similar floating point conversions) because typically it is an error if a conversion to an integer results in an in-exact value.
bool bdljsn::JsonNumber::isEqual |
( |
const JsonNumber & |
other | ) |
const |
|
inline |
Return true
if this number and the specified other
number represent the same numeric value, and false
otherwise. This method will return true
for differing representations of the same number (e.g., 1.0
, "1", "0.1e+1" are all equivalent) except in cases where the exponent cannot be represented by a 64-bit integer. If the exponent is outside the range of a 64-bit integer, true
will be returned if *this == other
. For example, comparing "1e18446744073709551615" with itself will return true
, but comparing it to "10e18446744073709551614" will return false
. Note that this method is more computationally expensive than the equality and inequality operators.
bsl::ostream & bdljsn::JsonNumber::print |
( |
bsl::ostream & |
stream, |
|
|
int |
level = 0 , |
|
|
int |
spacesPerLevel = 4 |
|
) |
| const |
Write the value of this object to the specified output stream
in a human-readable format, and return a non-const
reference to stream
. Optionally specify an initial indentation level
, whose absolute value is incremented recursively for nested objects. If level
is specified, optionally specify spacesPerLevel
, whose absolute value indicates the number of spaces per indentation level for this and all of its nested objects. If level
is negative, suppress indentation of the first line. If spacesPerLevel
is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by level
). If stream
is not valid on entry, this operation has no effect. Note that the format is not fully specified, and can change without notice.