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 ripple {
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>
83 : STBase(n), value_(v)
84{
85}
86
87template <int Bits>
89 : STBitString(name, sit.getBitString<Bits>())
90{
91}
92
93template <int Bits>
94STBase*
96{
97 return emplace(n, buf, *this);
98}
99
100template <int Bits>
101STBase*
103{
104 return emplace(n, buf, std::move(*this));
105}
106
107template <>
108inline SerializedTypeID
110{
111 return STI_UINT128;
112}
113
114template <>
115inline SerializedTypeID
117{
118 return STI_UINT160;
119}
120
121template <>
122inline SerializedTypeID
124{
125 return STI_UINT192;
126}
127
128template <>
129inline SerializedTypeID
131{
132 return STI_UINT256;
133}
134
135template <int Bits>
138{
139 return to_string(value_);
140}
141
142template <int Bits>
143bool
145{
146 STBitString const* v = dynamic_cast<STBitString const*>(&t);
147 return v && (value_ == v->value_);
148}
149
150template <int Bits>
151void
153{
154 XRPL_ASSERT(
155 getFName().isBinary(), "ripple::STBitString::add : field is binary");
156 XRPL_ASSERT(
157 getFName().fieldType == getSType(),
158 "ripple::STBitString::add : field type match");
159 s.addBitString<Bits>(value_);
160}
161
162template <int Bits>
163template <typename Tag>
164void
166{
167 value_ = v;
168}
169
170template <int Bits>
171typename STBitString<Bits>::value_type const&
173{
174 return value_;
175}
176
177template <int Bits>
179{
180 return value_;
181}
182
183template <int Bits>
184bool
186{
187 return value_ == beast::zero;
188}
189
190} // namespace ripple
191
192#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
bool isDefault() const override
STBase * move(std::size_t n, void *buf) override
std::string getText() const override
SerializedTypeID getSType() const override
STBase * copy(std::size_t n, void *buf) const override
Definition STBitString.h:95
bool isEquivalent(STBase const &t) const override
void setValue(base_uint< Bits, Tag > const &v)
value_type const & value() const
base_uint< Bits > value_type
Definition STBitString.h:20
void add(Serializer &s) const override
int addBitString(base_uint< Bits, Tag > const &v)
Definition Serializer.h:112
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
SerializedTypeID
Definition SField.h:91
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:611