rippled
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
27 STBitString(SField const& n);
28 STBitString(value_type const& v);
29 STBitString(SField const& n, value_type const& v);
30 STBitString(SerialIter& sit, SField const& name);
31
33 getSType() const override;
34
36 getText() const override;
37
38 bool
39 isEquivalent(STBase const& t) const override;
40
41 void
42 add(Serializer& s) const override;
43
44 bool
45 isDefault() const override;
46
47 template <typename Tag>
48 void
50
51 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>
76inline STBitString<Bits>::STBitString(value_type const& v) : value_(v)
77{
78}
79
80template <int Bits>
81inline STBitString<Bits>::STBitString(SField const& n, value_type const& v) : STBase(n), value_(v)
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
161{
162 value_ = v;
163}
164
165template <int Bits>
166typename STBitString<Bits>::value_type const&
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::zero;
184}
185
186} // namespace xrpl
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_
Definition STBitString.h:22
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:19
value_type const & value() const
int addBitString(base_uint< Bits, Tag > const &v)
Definition Serializer.h:105
Integers of any length that is a multiple of 32-bits.
Definition base_uint.h:66
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:602
SerializedTypeID
Definition SField.h:90