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