#ifndef XRPL_PROTOCOL_STBITSTRING_H_INCLUDED #define XRPL_PROTOCOL_STBITSTRING_H_INCLUDED #include #include #include namespace ripple { // The template parameter could be an unsigned type, however there's a bug in // gdb (last checked in gdb 12.1) that prevents gdb from finding the RTTI // information of a template parameterized by an unsigned type. This RTTI // information is needed to write gdb pretty printers. template class STBitString final : public STBase, public CountedObject> { static_assert(Bits > 0, "Number of bits must be positive"); public: using value_type = base_uint; private: value_type value_; public: STBitString() = default; STBitString(SField const& n); STBitString(value_type const& v); STBitString(SField const& n, value_type const& v); STBitString(SerialIter& sit, SField const& name); SerializedTypeID getSType() const override; std::string getText() const override; bool isEquivalent(STBase const& t) const override; void add(Serializer& s) const override; bool isDefault() const override; template void setValue(base_uint const& v); value_type const& value() const; operator value_type() const; private: STBase* copy(std::size_t n, void* buf) const override; STBase* move(std::size_t n, void* buf) override; friend class detail::STVar; }; using STUInt128 = STBitString<128>; using STUInt160 = STBitString<160>; using STUInt192 = STBitString<192>; using STUInt256 = STBitString<256>; template inline STBitString::STBitString(SField const& n) : STBase(n) { } template inline STBitString::STBitString(value_type const& v) : value_(v) { } template inline STBitString::STBitString(SField const& n, value_type const& v) : STBase(n), value_(v) { } template inline STBitString::STBitString(SerialIter& sit, SField const& name) : STBitString(name, sit.getBitString()) { } template STBase* STBitString::copy(std::size_t n, void* buf) const { return emplace(n, buf, *this); } template STBase* STBitString::move(std::size_t n, void* buf) { return emplace(n, buf, std::move(*this)); } template <> inline SerializedTypeID STUInt128::getSType() const { return STI_UINT128; } template <> inline SerializedTypeID STUInt160::getSType() const { return STI_UINT160; } template <> inline SerializedTypeID STUInt192::getSType() const { return STI_UINT192; } template <> inline SerializedTypeID STUInt256::getSType() const { return STI_UINT256; } template std::string STBitString::getText() const { return to_string(value_); } template bool STBitString::isEquivalent(STBase const& t) const { STBitString const* v = dynamic_cast(&t); return v && (value_ == v->value_); } template void STBitString::add(Serializer& s) const { XRPL_ASSERT( getFName().isBinary(), "ripple::STBitString::add : field is binary"); XRPL_ASSERT( getFName().fieldType == getSType(), "ripple::STBitString::add : field type match"); s.addBitString(value_); } template template void STBitString::setValue(base_uint const& v) { value_ = v; } template typename STBitString::value_type const& STBitString::value() const { return value_; } template STBitString::operator value_type() const { return value_; } template bool STBitString::isDefault() const { return value_ == beast::zero; } } // namespace ripple #endif