rippled
Loading...
Searching...
No Matches
STInteger.h
1#ifndef XRPL_PROTOCOL_STINTEGER_H_INCLUDED
2#define XRPL_PROTOCOL_STINTEGER_H_INCLUDED
3
4#include <xrpl/basics/CountedObject.h>
5#include <xrpl/protocol/STBase.h>
6
7namespace ripple {
8
9template <typename Integer>
10class STInteger : public STBase, public CountedObject<STInteger<Integer>>
11{
12public:
13 using value_type = Integer;
14
15private:
16 Integer value_;
17
18public:
19 explicit STInteger(Integer v);
20 STInteger(SField const& n, Integer v = 0);
21 STInteger(SerialIter& sit, SField const& name);
22
24 getSType() const override;
25
26 Json::Value getJson(JsonOptions) const override;
27
29 getText() const override;
30
31 void
32 add(Serializer& s) const override;
33
34 bool
35 isDefault() const override;
36
37 bool
38 isEquivalent(STBase const& t) const override;
39
41 operator=(value_type const& v);
42
44 value() const noexcept;
45
46 void
47 setValue(Integer v);
48
49 operator Integer() const;
50
51private:
52 STBase*
53 copy(std::size_t n, void* buf) const override;
54 STBase*
55 move(std::size_t n, void* buf) override;
56
57 friend class ripple::detail::STVar;
58};
59
60using STUInt8 = STInteger<unsigned char>;
61using STUInt16 = STInteger<std::uint16_t>;
62using STUInt32 = STInteger<std::uint32_t>;
63using STUInt64 = STInteger<std::uint64_t>;
64
65using STInt32 = STInteger<std::int32_t>;
66
67template <typename Integer>
68inline STInteger<Integer>::STInteger(Integer v) : value_(v)
69{
70}
71
72template <typename Integer>
73inline STInteger<Integer>::STInteger(SField const& n, Integer v)
74 : STBase(n), value_(v)
75{
76}
77
78template <typename Integer>
79inline STBase*
81{
82 return emplace(n, buf, *this);
83}
84
85template <typename Integer>
86inline STBase*
88{
89 return emplace(n, buf, std::move(*this));
90}
91
92template <typename Integer>
93inline void
95{
96 XRPL_ASSERT(
97 getFName().isBinary(), "ripple::STInteger::add : field is binary");
98 XRPL_ASSERT(
99 getFName().fieldType == getSType(),
100 "ripple::STInteger::add : field type match");
101 s.addInteger(value_);
102}
103
104template <typename Integer>
105inline bool
107{
108 return value_ == 0;
109}
110
111template <typename Integer>
112inline bool
114{
115 STInteger const* v = dynamic_cast<STInteger const*>(&t);
116 return v && (value_ == v->value_);
117}
118
119template <typename Integer>
120inline STInteger<Integer>&
122{
123 value_ = v;
124 return *this;
125}
126
127template <typename Integer>
128inline typename STInteger<Integer>::value_type
130{
131 return value_;
132}
133
134template <typename Integer>
135inline void
137{
138 value_ = v;
139}
140
141template <typename Integer>
142inline STInteger<Integer>::operator Integer() const
143{
144 return value_;
145}
146
147} // namespace ripple
148
149#endif
Represents a JSON value.
Definition json_value.h:131
Tracks the number of instances of an object.
Identifies fields.
Definition SField.h:127
A type which can be exported to a well known binary format.
Definition STBase.h:116
STInteger(Integer v)
Definition STInteger.h:68
void add(Serializer &s) const override
Definition STInteger.h:94
STInteger & operator=(value_type const &v)
Definition STInteger.h:121
std::string getText() const override
Definition STInteger.cpp:37
STBase * move(std::size_t n, void *buf) override
Definition STInteger.h:87
Integer value_type
Definition STInteger.h:13
value_type value() const noexcept
Definition STInteger.h:129
Json::Value getJson(JsonOptions) const override
Definition STInteger.cpp:57
STBase * copy(std::size_t n, void *buf) const override
Definition STInteger.h:80
SerializedTypeID getSType() const override
Definition STInteger.cpp:30
friend class ripple::detail::STVar
Definition STInteger.h:57
bool isEquivalent(STBase const &t) const override
Definition STInteger.h:113
STInteger(SerialIter &sit, SField const &name)
void setValue(Integer v)
Definition STInteger.h:136
bool isDefault() const override
Definition STInteger.h:106
int addInteger(Integer)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
SerializedTypeID
Definition SField.h:91
STL namespace.
Note, should be treated as flags that can be | and &.
Definition STBase.h:18