rippled
Loading...
Searching...
No Matches
STBitString.h
1#ifndef XRPL_PROTOCOL_STBITSTRING_H_INCLUDED
2#define XRPL_PROTOCOL_STBITSTRING_H_INCLUDED
3
4#include <xrpl/basics/CountedObject.h>
5#include <xrpl/beast/utility/Zero.h>
6#include <xrpl/protocol/STBase.h>
7
8namespace xrpl {
9
10// The template parameter could be an unsigned type, however there's a bug in
11// gdb (last checked in gdb 12.1) that prevents gdb from finding the RTTI
12// information of a template parameterized by an unsigned type. This RTTI
13// information is needed to write gdb pretty printers.
14template <int Bits>
15class STBitString final : public STBase, public CountedObject<STBitString<Bits>>
16{
17 static_assert(Bits > 0, "Number of bits must be positive");
18
19public:
21
22private:
24
25public:
26 STBitString() = default;
27
28 STBitString(SField const& n);
29 STBitString(value_type const& v);
30 STBitString(SField const& n, value_type const& v);
31 STBitString(SerialIter& sit, SField const& name);
32
34 getSType() const override;
35
37 getText() const override;
38
39 bool
40 isEquivalent(STBase const& t) const override;
41
42 void
43 add(Serializer& s) const override;
44
45 bool
46 isDefault() const override;
47
48 template <typename Tag>
49 void
51
52 value_type const&
53 value() const;
54
55 operator value_type() const;
56
57private:
58 STBase*
59 copy(std::size_t n, void* buf) const override;
60 STBase*
61 move(std::size_t n, void* buf) override;
62
63 friend class detail::STVar;
64};
65
70
71template <int Bits>
73{
74}
75
76template <int Bits>
77inline STBitString<Bits>::STBitString(value_type const& v) : value_(v)
78{
79}
80
81template <int Bits>
82inline STBitString<Bits>::STBitString(SField const& n, value_type const& v) : STBase(n), value_(v)
83{
84}
85
86template <int Bits>
87inline STBitString<Bits>::STBitString(SerialIter& sit, SField const& name) : STBitString(name, sit.getBitString<Bits>())
88{
89}
90
91template <int Bits>
92STBase*
94{
95 return emplace(n, buf, *this);
96}
97
98template <int Bits>
99STBase*
101{
102 return emplace(n, buf, std::move(*this));
103}
104
105template <>
106inline SerializedTypeID
108{
109 return STI_UINT128;
110}
111
112template <>
113inline SerializedTypeID
115{
116 return STI_UINT160;
117}
118
119template <>
120inline SerializedTypeID
122{
123 return STI_UINT192;
124}
125
126template <>
127inline SerializedTypeID
129{
130 return STI_UINT256;
131}
132
133template <int Bits>
136{
137 return to_string(value_);
138}
139
140template <int Bits>
141bool
143{
144 STBitString const* v = dynamic_cast<STBitString const*>(&t);
145 return v && (value_ == v->value_);
146}
147
148template <int Bits>
149void
151{
152 XRPL_ASSERT(getFName().isBinary(), "xrpl::STBitString::add : field is binary");
153 XRPL_ASSERT(getFName().fieldType == getSType(), "xrpl::STBitString::add : field type match");
154 s.addBitString<Bits>(value_);
155}
156
157template <int Bits>
158template <typename Tag>
159void
161{
162 value_ = v;
163}
164
165template <int Bits>
166typename STBitString<Bits>::value_type const&
168{
169 return value_;
170}
171
172template <int Bits>
174{
175 return value_;
176}
177
178template <int Bits>
179bool
181{
182 return value_ == beast::zero;
183}
184
185} // namespace xrpl
186
187#endif
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
value_type value_
Definition STBitString.h:23
std::string getText() const override
bool isDefault() const override
void add(Serializer &s) const override
SerializedTypeID getSType() const override
STBase * copy(std::size_t n, void *buf) const override
Definition STBitString.h:93
STBase * move(std::size_t n, void *buf) override
void setValue(base_uint< Bits, Tag > const &v)
STBitString()=default
bool isEquivalent(STBase const &t) const override
base_uint< Bits > value_type
Definition STBitString.h:20
value_type const & value() const
int addBitString(base_uint< Bits, Tag > const &v)
Definition Serializer.h:106
Integers of any length that is a multiple of 32-bits.
Definition base_uint.h:67
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:598
SerializedTypeID
Definition SField.h:91