rippled
Loading...
Searching...
No Matches
STNumber.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2024 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef XRPL_PROTOCOL_STNUMBER_H_INCLUDED
21#define XRPL_PROTOCOL_STNUMBER_H_INCLUDED
22
23#include <xrpl/basics/CountedObject.h>
24#include <xrpl/basics/Number.h>
25#include <xrpl/protocol/STBase.h>
26
27#include <ostream>
28
29namespace ripple {
30
42class STNumber : public STBase, public CountedObject<STNumber>
43{
44private:
46
47public:
49
50 STNumber() = default;
51 explicit STNumber(SField const& field, Number const& value = Number());
52 STNumber(SerialIter& sit, SField const& field);
53
55 getSType() const override;
57 getText() const override;
58 void
59 add(Serializer& s) const override;
60
61 Number const&
62 value() const;
63 void
64 setValue(Number const& v);
65
67 operator=(Number const& rhs)
68 {
69 setValue(rhs);
70 return *this;
71 }
72
73 bool
74 isEquivalent(STBase const& t) const override;
75 bool
76 isDefault() const override;
77
78 operator Number() const
79 {
80 return value_;
81 }
82
83private:
84 STBase*
85 copy(std::size_t n, void* buf) const override;
86 STBase*
87 move(std::size_t n, void* buf) override;
88};
89
91operator<<(std::ostream& out, STNumber const& rhs);
92
94{
96 int exponent = 0;
97 bool negative = false;
98};
99
102
104numberFromJson(SField const& field, Json::Value const& value);
105
106} // namespace ripple
107
108#endif
Represents a JSON value.
Definition: json_value.h:150
Tracks the number of instances of an object.
Identifies fields.
Definition: SField.h:143
A type which can be exported to a well known binary format.
Definition: STBase.h:136
A serializable number.
Definition: STNumber.h:43
SerializedTypeID getSType() const override
Definition: STNumber.cpp:53
bool isDefault() const override
Definition: STNumber.cpp:111
void add(Serializer &s) const override
Definition: STNumber.cpp:65
STNumber & operator=(Number const &rhs)
Definition: STNumber.h:67
STNumber()=default
std::string getText() const override
Definition: STNumber.cpp:59
void setValue(Number const &v)
Definition: STNumber.cpp:83
STBase * move(std::size_t n, void *buf) override
Definition: STNumber.cpp:95
Number const & value() const
Definition: STNumber.cpp:77
Number value_
Definition: STNumber.h:45
STBase * copy(std::size_t n, void *buf) const override
Definition: STNumber.cpp:89
bool isEquivalent(STBase const &t) const override
Definition: STNumber.cpp:101
static Number number(STAmount const &a)
Definition: AMM.cpp:35
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
NumberParts partsFromString(std::string const &number)
Definition: STNumber.cpp:123
SerializedTypeID
Definition: SField.h:107
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
Definition: base_uint.h:637
STNumber numberFromJson(SField const &field, Json::Value const &value)
Definition: STNumber.cpp:179
std::uint64_t mantissa
Definition: STNumber.h:95