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>
86inline STBitString<Bits>::STBitString(SerialIter& sit, SField const& name) : STBitString(name, sit.getBitString<Bits>())
87{
88}
89
90template <int Bits>
91STBase*
93{
94 return emplace(n, buf, *this);
95}
96
97template <int Bits>
98STBase*
100{
101 return emplace(n, buf, std::move(*this));
102}
103
104template <>
105inline SerializedTypeID
107{
108 return STI_UINT128;
109}
110
111template <>
112inline SerializedTypeID
114{
115 return STI_UINT160;
116}
117
118template <>
119inline SerializedTypeID
121{
122 return STI_UINT192;
123}
124
125template <>
126inline SerializedTypeID
128{
129 return STI_UINT256;
130}
131
132template <int Bits>
135{
136 return to_string(value_);
137}
138
139template <int Bits>
140bool
142{
143 STBitString const* v = dynamic_cast<STBitString const*>(&t);
144 return v && (value_ == v->value_);
145}
146
147template <int Bits>
148void
150{
151 XRPL_ASSERT(getFName().isBinary(), "xrpl::STBitString::add : field is binary");
152 XRPL_ASSERT(getFName().fieldType == getSType(), "xrpl::STBitString::add : field type match");
153 s.addBitString<Bits>(value_);
154}
155
156template <int Bits>
157template <typename Tag>
158void
160{
161 value_ = v;
162}
163
164template <int Bits>
165typename STBitString<Bits>::value_type const&
167{
168 return value_;
169}
170
171template <int Bits>
173{
174 return value_;
175}
176
177template <int Bits>
178bool
180{
181 return value_ == beast::zero;
182}
183
184} // 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:92
STBase * move(std::size_t n, void *buf) override
Definition STBitString.h:99
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:597
SerializedTypeID
Definition SField.h:90