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
66 bool
67 isEquivalent(STBase const& t) const override;
68 bool
69 isDefault() const override;
70
71 operator Number() const
72 {
73 return value_;
74 }
75
76private:
77 STBase*
78 copy(std::size_t n, void* buf) const override;
79 STBase*
80 move(std::size_t n, void* buf) override;
81};
82
84operator<<(std::ostream& out, STNumber const& rhs);
85
86} // namespace ripple
87
88#endif
Tracks the number of instances of an object.
Identifies fields.
Definition: SField.h:144
A type which can be exported to a well known binary format.
Definition: STBase.h:124
A serializable number.
Definition: STNumber.h:43
SerializedTypeID getSType() const override
Definition: STNumber.cpp:42
bool isDefault() const override
Definition: STNumber.cpp:100
void add(Serializer &s) const override
Definition: STNumber.cpp:54
STNumber()=default
std::string getText() const override
Definition: STNumber.cpp:48
void setValue(Number const &v)
Definition: STNumber.cpp:72
STBase * move(std::size_t n, void *buf) override
Definition: STNumber.cpp:84
Number const & value() const
Definition: STNumber.cpp:66
Number value_
Definition: STNumber.h:45
STBase * copy(std::size_t n, void *buf) const override
Definition: STNumber.cpp:78
bool isEquivalent(STBase const &t) const override
Definition: STNumber.cpp:90
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
SerializedTypeID
Definition: SField.h:108
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
Definition: base_uint.h:636