xrpld
Loading...
Searching...
No Matches
xrpl::BaseUInt< Bits, Tag > Class Template Reference

Integers of any length that is a multiple of 32-bits. More...

#include <base_uint.h>

Collaboration diagram for xrpl::BaseUInt< Bits, Tag >:

Classes

struct  VoidHelper
 Construct from a raw pointer. More...

Public Types

using size_type = std::size_t
using difference_type = std::ptrdiff_t
using value_type = unsigned char
using pointer = value_type*
using reference = value_type&
using const_pointer = value_type const*
using const_reference = value_type const&
using iterator = pointer
using const_iterator = const_pointer
using reverse_iterator = std::reverse_iterator<iterator>
using const_reverse_iterator = std::reverse_iterator<const_iterator>
using tag_type = Tag
using hasher = HardenedHash<>
 Value hashing function.

Public Member Functions

pointer data ()
const_pointer data () const
iterator begin ()
iterator end ()
const_iterator begin () const
const_iterator end () const
const_iterator cbegin () const
const_iterator cend () const
constexpr BaseUInt ()
constexpr BaseUInt (beast::Zero)
 BaseUInt (std::uint64_t b)
constexpr BaseUInt (std::string_view sv) noexcept(false)
template<class Container, class = std::enable_if_t< detail::IsContiguousContainer<Container>::value && std::is_trivially_copyable_v<typename Container::value_type>>>
 BaseUInt (Container const &c)
template<class Container>
std::enable_if_t< detail::IsContiguousContainer< Container >::value &&std::is_trivially_copyable_v< typename Container::value_type >, BaseUInt & > operator= (Container const &c)
constexpr int signum () const
bool operator! () const
constexpr BaseUInt operator~ () const
BaseUIntoperator= (std::uint64_t uHost)
BaseUIntoperator^= (BaseUInt const &b)
BaseUIntoperator&= (BaseUInt const &b)
BaseUIntoperator|= (BaseUInt const &b)
BaseUIntoperator++ ()
BaseUInt operator++ (int)
BaseUIntoperator-- ()
BaseUInt operator-- (int)
BaseUInt next () const
BaseUInt prev () const
BaseUIntoperator+= (BaseUInt const &b)
constexpr bool parseHex (std::string_view sv)
 Parse a hex string into a base_uint.
constexpr bool parseHex (char const *str)
bool parseHex (std::string const &str)
BaseUInt< Bits, Tag > & operator= (beast::Zero)
bool isZero () const
bool isNonZero () const
void zero ()

Static Public Member Functions

template<class Container, class = std::enable_if_t< detail::IsContiguousContainer<Container>::value && std::is_trivially_copyable_v<typename Container::value_type>>>
static BaseUInt fromRaw (Container const &c)
static BaseUInt fromVoid (void const *data)
template<class T>
static std::optional< BaseUIntfromVoidChecked (T const &from)
static constexpr std::size_t size ()

Static Public Attributes

static constexpr std::size_t kBytes = Bits / 8

Private Types

enum class  ParseResult { Okay , BadLength , BadChar }

Private Member Functions

 BaseUInt (void const *data, VoidHelper)
constexpr std::expected< decltype(data_), ParseResultparseFromStringView (std::string_view sv) noexcept
constexpr decltype(data_parseFromStringViewThrows (std::string_view sv) noexcept(false)

Private Attributes

std::array< std::uint32_t, kWidthdata_

Static Private Attributes

static constexpr std::size_t kWidth = Bits / 32

Friends

template<class Hasher>
void hash_append (Hasher &h, BaseUInt const &a) noexcept

Detailed Description

template<std::size_t Bits, class Tag = void>
class xrpl::BaseUInt< Bits, Tag >

Integers of any length that is a multiple of 32-bits.

Note
This class stores its values internally in big-endian form and that internal representation is part of the binary protocol of the XRP Ledger and cannot be changed arbitrarily without causing breakage.
Template Parameters
BitsThe number of bits this integer should have; must be at least 64 and a multiple of 32.
TagAn arbitrary type that functions as a tag and allows the instantiation of "distinct" types that the same number of bits.

Definition at line 70 of file base_uint.h.

Member Typedef Documentation

◆ size_type

template<std::size_t Bits, class Tag = void>
using xrpl::BaseUInt< Bits, Tag >::size_type = std::size_t

Definition at line 92 of file base_uint.h.

◆ difference_type

template<std::size_t Bits, class Tag = void>
using xrpl::BaseUInt< Bits, Tag >::difference_type = std::ptrdiff_t

Definition at line 93 of file base_uint.h.

◆ value_type

template<std::size_t Bits, class Tag = void>
using xrpl::BaseUInt< Bits, Tag >::value_type = unsigned char

Definition at line 94 of file base_uint.h.

◆ pointer

template<std::size_t Bits, class Tag = void>
using xrpl::BaseUInt< Bits, Tag >::pointer = value_type*

Definition at line 95 of file base_uint.h.

◆ reference

template<std::size_t Bits, class Tag = void>
using xrpl::BaseUInt< Bits, Tag >::reference = value_type&

Definition at line 96 of file base_uint.h.

◆ const_pointer

template<std::size_t Bits, class Tag = void>
using xrpl::BaseUInt< Bits, Tag >::const_pointer = value_type const*

Definition at line 97 of file base_uint.h.

◆ const_reference

template<std::size_t Bits, class Tag = void>
using xrpl::BaseUInt< Bits, Tag >::const_reference = value_type const&

Definition at line 98 of file base_uint.h.

◆ iterator

template<std::size_t Bits, class Tag = void>
using xrpl::BaseUInt< Bits, Tag >::iterator = pointer

Definition at line 99 of file base_uint.h.

◆ const_iterator

template<std::size_t Bits, class Tag = void>
using xrpl::BaseUInt< Bits, Tag >::const_iterator = const_pointer

Definition at line 100 of file base_uint.h.

◆ reverse_iterator

template<std::size_t Bits, class Tag = void>
using xrpl::BaseUInt< Bits, Tag >::reverse_iterator = std::reverse_iterator<iterator>

Definition at line 101 of file base_uint.h.

◆ const_reverse_iterator

template<std::size_t Bits, class Tag = void>
using xrpl::BaseUInt< Bits, Tag >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Definition at line 102 of file base_uint.h.

◆ tag_type

template<std::size_t Bits, class Tag = void>
using xrpl::BaseUInt< Bits, Tag >::tag_type = Tag

Definition at line 103 of file base_uint.h.

◆ hasher

template<std::size_t Bits, class Tag = void>
using xrpl::BaseUInt< Bits, Tag >::hasher = HardenedHash<>

Value hashing function.

The seed prevents crafted inputs from causing degenerate parent containers.

Definition at line 151 of file base_uint.h.

Member Enumeration Documentation

◆ ParseResult

template<std::size_t Bits, class Tag = void>
enum class xrpl::BaseUInt::ParseResult
strongprivate
Enumerator
Okay 
BadLength 
BadChar 

Definition at line 174 of file base_uint.h.

Constructor & Destructor Documentation

◆ BaseUInt() [1/6]

template<std::size_t Bits, class Tag = void>
xrpl::BaseUInt< Bits, Tag >::BaseUInt ( void const * data,
VoidHelper  )
explicitprivate

Definition at line 168 of file base_uint.h.

◆ BaseUInt() [2/6]

template<std::size_t Bits, class Tag = void>
xrpl::BaseUInt< Bits, Tag >::BaseUInt ( )
constexpr

Definition at line 252 of file base_uint.h.

◆ BaseUInt() [3/6]

template<std::size_t Bits, class Tag = void>
xrpl::BaseUInt< Bits, Tag >::BaseUInt ( beast::Zero )
constexpr

Definition at line 256 of file base_uint.h.

◆ BaseUInt() [4/6]

template<std::size_t Bits, class Tag = void>
xrpl::BaseUInt< Bits, Tag >::BaseUInt ( std::uint64_t b)
explicit

Definition at line 260 of file base_uint.h.

◆ BaseUInt() [5/6]

template<std::size_t Bits, class Tag = void>
xrpl::BaseUInt< Bits, Tag >::BaseUInt ( std::string_view sv)
explicitconstexpr

Definition at line 268 of file base_uint.h.

◆ BaseUInt() [6/6]

template<std::size_t Bits, class Tag = void>
template<class Container, class = std::enable_if_t< detail::IsContiguousContainer<Container>::value && std::is_trivially_copyable_v<typename Container::value_type>>>
xrpl::BaseUInt< Bits, Tag >::BaseUInt ( Container const & c)
explicit

Definition at line 278 of file base_uint.h.

Member Function Documentation

◆ data() [1/2]

template<std::size_t Bits, class Tag = void>
pointer xrpl::BaseUInt< Bits, Tag >::data ( )

Definition at line 106 of file base_uint.h.

◆ data() [2/2]

template<std::size_t Bits, class Tag = void>
const_pointer xrpl::BaseUInt< Bits, Tag >::data ( ) const
nodiscard

Definition at line 111 of file base_uint.h.

◆ begin() [1/2]

template<std::size_t Bits, class Tag = void>
iterator xrpl::BaseUInt< Bits, Tag >::begin ( )

Definition at line 117 of file base_uint.h.

◆ end() [1/2]

template<std::size_t Bits, class Tag = void>
iterator xrpl::BaseUInt< Bits, Tag >::end ( )

Definition at line 122 of file base_uint.h.

◆ begin() [2/2]

template<std::size_t Bits, class Tag = void>
const_iterator xrpl::BaseUInt< Bits, Tag >::begin ( ) const
nodiscard

Definition at line 127 of file base_uint.h.

◆ end() [2/2]

template<std::size_t Bits, class Tag = void>
const_iterator xrpl::BaseUInt< Bits, Tag >::end ( ) const
nodiscard

Definition at line 132 of file base_uint.h.

◆ cbegin()

template<std::size_t Bits, class Tag = void>
const_iterator xrpl::BaseUInt< Bits, Tag >::cbegin ( ) const
nodiscard

Definition at line 137 of file base_uint.h.

◆ cend()

template<std::size_t Bits, class Tag = void>
const_iterator xrpl::BaseUInt< Bits, Tag >::cend ( ) const
nodiscard

Definition at line 142 of file base_uint.h.

◆ parseFromStringView()

template<std::size_t Bits, class Tag = void>
std::expected< decltype(data_), ParseResult > xrpl::BaseUInt< Bits, Tag >::parseFromStringView ( std::string_view sv)
constexprprivatenoexcept

Definition at line 181 of file base_uint.h.

◆ parseFromStringViewThrows()

template<std::size_t Bits, class Tag = void>
decltype(data_) xrpl::BaseUInt< Bits, Tag >::parseFromStringViewThrows ( std::string_view sv)
constexprprivate

Definition at line 238 of file base_uint.h.

◆ fromRaw()

template<std::size_t Bits, class Tag = void>
template<class Container, class = std::enable_if_t< detail::IsContiguousContainer<Container>::value && std::is_trivially_copyable_v<typename Container::value_type>>>
BaseUInt xrpl::BaseUInt< Bits, Tag >::fromRaw ( Container const & c)
static

Definition at line 294 of file base_uint.h.

◆ operator=() [1/3]

template<std::size_t Bits, class Tag = void>
template<class Container>
std::enable_if_t< detail::IsContiguousContainer< Container >::value &&std::is_trivially_copyable_v< typename Container::value_type >, BaseUInt & > xrpl::BaseUInt< Bits, Tag >::operator= ( Container const & c)

Definition at line 309 of file base_uint.h.

◆ fromVoid()

template<std::size_t Bits, class Tag = void>
BaseUInt xrpl::BaseUInt< Bits, Tag >::fromVoid ( void const * data)
static

Definition at line 322 of file base_uint.h.

◆ fromVoidChecked()

template<std::size_t Bits, class Tag = void>
template<class T>
std::optional< BaseUInt > xrpl::BaseUInt< Bits, Tag >::fromVoidChecked ( T const & from)
static

Definition at line 329 of file base_uint.h.

◆ signum()

template<std::size_t Bits, class Tag = void>
int xrpl::BaseUInt< Bits, Tag >::signum ( ) const
nodiscardconstexpr

Definition at line 337 of file base_uint.h.

◆ operator!()

template<std::size_t Bits, class Tag = void>
bool xrpl::BaseUInt< Bits, Tag >::operator! ( ) const

Definition at line 349 of file base_uint.h.

◆ operator~()

template<std::size_t Bits, class Tag = void>
BaseUInt xrpl::BaseUInt< Bits, Tag >::operator~ ( ) const
constexpr

Definition at line 355 of file base_uint.h.

◆ operator=() [2/3]

template<std::size_t Bits, class Tag = void>
BaseUInt & xrpl::BaseUInt< Bits, Tag >::operator= ( std::uint64_t uHost)

Definition at line 366 of file base_uint.h.

◆ operator^=()

template<std::size_t Bits, class Tag = void>
BaseUInt & xrpl::BaseUInt< Bits, Tag >::operator^= ( BaseUInt< Bits, Tag > const & b)

Definition at line 384 of file base_uint.h.

◆ operator&=()

template<std::size_t Bits, class Tag = void>
BaseUInt & xrpl::BaseUInt< Bits, Tag >::operator&= ( BaseUInt< Bits, Tag > const & b)

Definition at line 393 of file base_uint.h.

◆ operator|=()

template<std::size_t Bits, class Tag = void>
BaseUInt & xrpl::BaseUInt< Bits, Tag >::operator|= ( BaseUInt< Bits, Tag > const & b)

Definition at line 402 of file base_uint.h.

◆ operator++() [1/2]

template<std::size_t Bits, class Tag = void>
BaseUInt & xrpl::BaseUInt< Bits, Tag >::operator++ ( )

Definition at line 411 of file base_uint.h.

◆ operator++() [2/2]

template<std::size_t Bits, class Tag = void>
BaseUInt xrpl::BaseUInt< Bits, Tag >::operator++ ( int )

Definition at line 425 of file base_uint.h.

◆ operator--() [1/2]

template<std::size_t Bits, class Tag = void>
BaseUInt & xrpl::BaseUInt< Bits, Tag >::operator-- ( )

Definition at line 435 of file base_uint.h.

◆ operator--() [2/2]

template<std::size_t Bits, class Tag = void>
BaseUInt xrpl::BaseUInt< Bits, Tag >::operator-- ( int )

Definition at line 450 of file base_uint.h.

◆ next()

template<std::size_t Bits, class Tag = void>
BaseUInt xrpl::BaseUInt< Bits, Tag >::next ( ) const
nodiscard

Definition at line 460 of file base_uint.h.

◆ prev()

template<std::size_t Bits, class Tag = void>
BaseUInt xrpl::BaseUInt< Bits, Tag >::prev ( ) const
nodiscard

Definition at line 467 of file base_uint.h.

◆ operator+=()

template<std::size_t Bits, class Tag = void>
BaseUInt & xrpl::BaseUInt< Bits, Tag >::operator+= ( BaseUInt< Bits, Tag > const & b)

Definition at line 474 of file base_uint.h.

◆ parseHex() [1/3]

template<std::size_t Bits, class Tag = void>
bool xrpl::BaseUInt< Bits, Tag >::parseHex ( std::string_view sv)
nodiscardconstexpr

Parse a hex string into a base_uint.

The input must be precisely 2 * bytes hexadecimal characters long, with one exception: the value '0'.

Parameters
svA null-terminated string of hexadecimal characters
Returns
true if the input was parsed properly; false otherwise.

Definition at line 507 of file base_uint.h.

◆ parseHex() [2/3]

template<std::size_t Bits, class Tag = void>
bool xrpl::BaseUInt< Bits, Tag >::parseHex ( char const * str)
nodiscardconstexpr

Definition at line 518 of file base_uint.h.

◆ parseHex() [3/3]

template<std::size_t Bits, class Tag = void>
bool xrpl::BaseUInt< Bits, Tag >::parseHex ( std::string const & str)
nodiscard

Definition at line 524 of file base_uint.h.

◆ size()

template<std::size_t Bits, class Tag = void>
constexpr std::size_t xrpl::BaseUInt< Bits, Tag >::size ( )
staticconstexpr

Definition at line 530 of file base_uint.h.

◆ operator=() [3/3]

template<std::size_t Bits, class Tag = void>
BaseUInt< Bits, Tag > & xrpl::BaseUInt< Bits, Tag >::operator= ( beast::Zero )

Definition at line 536 of file base_uint.h.

◆ isZero()

template<std::size_t Bits, class Tag = void>
bool xrpl::BaseUInt< Bits, Tag >::isZero ( ) const
nodiscard

Definition at line 544 of file base_uint.h.

◆ isNonZero()

template<std::size_t Bits, class Tag = void>
bool xrpl::BaseUInt< Bits, Tag >::isNonZero ( ) const
nodiscard

Definition at line 549 of file base_uint.h.

◆ zero()

template<std::size_t Bits, class Tag = void>
void xrpl::BaseUInt< Bits, Tag >::zero ( )

Definition at line 554 of file base_uint.h.

◆ hash_append

template<std::size_t Bits, class Tag = void>
template<class Hasher>
void hash_append ( Hasher & h,
BaseUInt< Bits, Tag > const & a )
friend

Definition at line 492 of file base_uint.h.

Member Data Documentation

◆ kWidth

template<std::size_t Bits, class Tag = void>
std::size_t xrpl::BaseUInt< Bits, Tag >::kWidth = Bits / 32
staticconstexprprivate

Definition at line 76 of file base_uint.h.

◆ data_

template<std::size_t Bits, class Tag = void>
std::array<std::uint32_t, kWidth> xrpl::BaseUInt< Bits, Tag >::data_
private

Definition at line 81 of file base_uint.h.

◆ kBytes

template<std::size_t Bits, class Tag = void>
std::size_t xrpl::BaseUInt< Bits, Tag >::kBytes = Bits / 8
staticconstexpr

Definition at line 89 of file base_uint.h.