xrpld
Loading...
Searching...
No Matches
STBitString.h
1#pragma once
2
3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/beast/utility/Zero.h>
5#include <xrpl/protocol/STBase.h>
6
7namespace xrpl {
8
9// The template parameter could be an unsigned type, however there's a bug in
10// gdb (last checked in gdb 12.1) that prevents gdb from finding the RTTI
11// information of a template parameterized by an unsigned type. This RTTI
12// information is needed to write gdb pretty printers.
13template <int Bits>
14class STBitString final : public STBase, public CountedObject<STBitString<Bits>>
15{
16 static_assert(Bits > 0, "Number of bits must be positive");
17
18public:
20
21private:
23
24public:
25 STBitString() = default;
26
29 STBitString(SField const& n, value_type const& v);
30 STBitString(SerialIter& sit, SField const& name);
31
32 [[nodiscard]] SerializedTypeID
33 getSType() const override;
34
35 [[nodiscard]] std::string
36 getText() const override;
37
38 [[nodiscard]] bool
39 isEquivalent(STBase const& t) const override;
40
41 void
42 add(Serializer& s) const override;
43
44 [[nodiscard]] bool
45 isDefault() const override;
46
47 template <typename Tag>
48 void
50
51 [[nodiscard]] value_type const&
52 value() const;
53
54 operator value_type() const;
55
56private:
57 STBase*
58 copy(std::size_t n, void* buf) const override;
59 STBase*
60 move(std::size_t n, void* buf) override;
61
62 friend class detail::STVar;
63};
64
69
70template <int Bits>
72{
73}
74
75template <int Bits>
77{
78}
79
80template <int Bits>
82{
83}
84
85template <int Bits>
87 : 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
164
165template <int Bits>
168{
169 return value_;
170}
171
172template <int Bits>
174operator value_type() const
175{
176 return value_;
177}
178
179template <int Bits>
180bool
182{
183 return value_ == beast::kZero;
184}
185
186} // namespace xrpl
Integers of any length that is a multiple of 32-bits.
Definition base_uint.h:71
Identifies fields.
Definition SField.h:130
A type which can be exported to a well known binary format.
Definition STBase.h:117
SField const & getFName() const
Definition STBase.cpp:126
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition STBase.h:215
STBitString(SerialIter &sit, SField const &name)
Definition STBitString.h:86
std::string getText() const override
BaseUInt< Bits > value_type
Definition STBitString.h:19
void setValue(BaseUInt< Bits, Tag > const &v)
bool isDefault() const override
void add(Serializer &s) const override
STBase * copy(std::size_t n, void *buf) const override
Definition STBitString.h:93
SerializedTypeID getSType() const override
STBitString(value_type const &v)
Definition STBitString.h:76
STBase * move(std::size_t n, void *buf) override
STBitString(SField const &n)
Definition STBitString.h:71
STBitString()=default
STBitString(SField const &n, value_type const &v)
Definition STBitString.h:81
bool isEquivalent(STBase const &t) const override
value_type const & value() const
int addBitString(BaseUInt< Bits, Tag > const &v)
Definition Serializer.h:105
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
STBitString< 128 > STUInt128
Definition STBitString.h:65
STBitString< 160 > STUInt160
Definition STBitString.h:66
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:633
SerializedTypeID
Definition SField.h:93
STBitString< 192 > STUInt192
Definition STBitString.h:67
STBitString< 256 > STUInt256
Definition STBitString.h:68