rippled
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
ripple::base_uint< Bits, Tag > Class Template Reference

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

#include <base_uint.h>

Collaboration diagram for ripple::base_uint< Bits, Tag >:
Collaboration graph
[legend]

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 = hardened_hash<>
 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 base_uint ()
 
constexpr base_uint (beast::Zero)
 
 base_uint (std::uint64_t b)
 
constexpr base_uint (std::string_view sv) noexcept(false)
 
template<class Container , class = std::enable_if_t< detail::is_contiguous_container<Container>::value && std::is_trivially_copyable<typename Container::value_type>::value>>
 base_uint (Container const &c)
 
template<class Container >
std::enable_if_t< detail::is_contiguous_container< Container >::value &&std::is_trivially_copyable< typename Container::value_type >::value, base_uint & > operator= (Container const &c)
 
constexpr int signum () const
 
bool operator! () const
 
constexpr base_uint operator~ () const
 
base_uintoperator= (std::uint64_t uHost)
 
base_uintoperator^= (base_uint const &b)
 
base_uintoperator&= (base_uint const &b)
 
base_uintoperator|= (base_uint const &b)
 
base_uintoperator++ ()
 
base_uint const operator++ (int)
 
base_uintoperator-- ()
 
base_uint const operator-- (int)
 
base_uint next () const
 
base_uint prev () const
 
base_uintoperator+= (base_uint 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)
 
base_uint< Bits, Tag > & operator= (beast::Zero)
 
bool isZero () const
 
bool isNonZero () const
 
void zero ()
 

Static Public Member Functions

static base_uint fromVoid (void const *data)
 
template<class T >
static std::optional< base_uintfromVoidChecked (T const &from)
 
static constexpr std::size_t size ()
 

Static Public Attributes

static std::size_t constexpr bytes = Bits / 8
 

Private Types

enum class  ParseResult { okay , badLength , badChar }
 

Private Member Functions

 base_uint (void const *data, VoidHelper)
 
constexpr 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, WIDTHdata_
 

Static Private Attributes

static constexpr std::size_t WIDTH = Bits / 32
 

Friends

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

Detailed Description

template<std::size_t Bits, class Tag = void>
class ripple::base_uint< 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 85 of file base_uint.h.

Member Typedef Documentation

◆ size_type

template<std::size_t Bits, class Tag = void>
using ripple::base_uint< Bits, Tag >::size_type = std::size_t

Definition at line 111 of file base_uint.h.

◆ difference_type

template<std::size_t Bits, class Tag = void>
using ripple::base_uint< Bits, Tag >::difference_type = std::ptrdiff_t

Definition at line 112 of file base_uint.h.

◆ value_type

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

Definition at line 113 of file base_uint.h.

◆ pointer

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

Definition at line 114 of file base_uint.h.

◆ reference

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

Definition at line 115 of file base_uint.h.

◆ const_pointer

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

Definition at line 116 of file base_uint.h.

◆ const_reference

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

Definition at line 117 of file base_uint.h.

◆ iterator

template<std::size_t Bits, class Tag = void>
using ripple::base_uint< Bits, Tag >::iterator = pointer

Definition at line 118 of file base_uint.h.

◆ const_iterator

template<std::size_t Bits, class Tag = void>
using ripple::base_uint< Bits, Tag >::const_iterator = const_pointer

Definition at line 119 of file base_uint.h.

◆ reverse_iterator

template<std::size_t Bits, class Tag = void>
using ripple::base_uint< Bits, Tag >::reverse_iterator = std::reverse_iterator<iterator>

Definition at line 120 of file base_uint.h.

◆ const_reverse_iterator

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

Definition at line 121 of file base_uint.h.

◆ tag_type

template<std::size_t Bits, class Tag = void>
using ripple::base_uint< Bits, Tag >::tag_type = Tag

Definition at line 122 of file base_uint.h.

◆ hasher

template<std::size_t Bits, class Tag = void>
using ripple::base_uint< Bits, Tag >::hasher = hardened_hash<>

Value hashing function.

The seed prevents crafted inputs from causing degenerate parent containers.

Definition at line 170 of file base_uint.h.

Member Enumeration Documentation

◆ ParseResult

template<std::size_t Bits, class Tag = void>
enum class ripple::base_uint::ParseResult
strongprivate
Enumerator
okay 
badLength 
badChar 

Definition at line 193 of file base_uint.h.

Constructor & Destructor Documentation

◆ base_uint() [1/6]

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

Definition at line 187 of file base_uint.h.

◆ base_uint() [2/6]

template<std::size_t Bits, class Tag = void>
constexpr ripple::base_uint< Bits, Tag >::base_uint ( )
constexpr

Definition at line 267 of file base_uint.h.

◆ base_uint() [3/6]

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

Definition at line 271 of file base_uint.h.

◆ base_uint() [4/6]

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

Definition at line 275 of file base_uint.h.

◆ base_uint() [5/6]

template<std::size_t Bits, class Tag = void>
constexpr ripple::base_uint< Bits, Tag >::base_uint ( std::string_view  sv)
explicitconstexpr

Definition at line 283 of file base_uint.h.

◆ base_uint() [6/6]

template<std::size_t Bits, class Tag = void>
template<class Container , class = std::enable_if_t< detail::is_contiguous_container<Container>::value && std::is_trivially_copyable<typename Container::value_type>::value>>
ripple::base_uint< Bits, Tag >::base_uint ( Container const &  c)
explicit

Definition at line 293 of file base_uint.h.

Member Function Documentation

◆ data() [1/2]

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

Definition at line 125 of file base_uint.h.

◆ data() [2/2]

template<std::size_t Bits, class Tag = void>
const_pointer ripple::base_uint< Bits, Tag >::data ( ) const

Definition at line 130 of file base_uint.h.

◆ begin() [1/2]

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

Definition at line 136 of file base_uint.h.

◆ end() [1/2]

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

Definition at line 141 of file base_uint.h.

◆ begin() [2/2]

template<std::size_t Bits, class Tag = void>
const_iterator ripple::base_uint< Bits, Tag >::begin ( ) const

Definition at line 146 of file base_uint.h.

◆ end() [2/2]

template<std::size_t Bits, class Tag = void>
const_iterator ripple::base_uint< Bits, Tag >::end ( ) const

Definition at line 151 of file base_uint.h.

◆ cbegin()

template<std::size_t Bits, class Tag = void>
const_iterator ripple::base_uint< Bits, Tag >::cbegin ( ) const

Definition at line 156 of file base_uint.h.

◆ cend()

template<std::size_t Bits, class Tag = void>
const_iterator ripple::base_uint< Bits, Tag >::cend ( ) const

Definition at line 161 of file base_uint.h.

◆ parseFromStringView()

template<std::size_t Bits, class Tag = void>
constexpr Expected< decltype(data_), ParseResult > ripple::base_uint< Bits, Tag >::parseFromStringView ( std::string_view  sv)
constexprprivatenoexcept

Definition at line 200 of file base_uint.h.

◆ parseFromStringViewThrows()

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

Definition at line 253 of file base_uint.h.

◆ operator=() [1/3]

template<std::size_t Bits, class Tag = void>
template<class Container >
std::enable_if_t< detail::is_contiguous_container< Container >::value && std::is_trivially_copyable< typename Container::value_type >::value, base_uint & > ripple::base_uint< Bits, Tag >::operator= ( Container const &  c)

Definition at line 306 of file base_uint.h.

◆ fromVoid()

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

Definition at line 319 of file base_uint.h.

◆ fromVoidChecked()

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

Definition at line 326 of file base_uint.h.

◆ signum()

template<std::size_t Bits, class Tag = void>
constexpr int ripple::base_uint< Bits, Tag >::signum ( ) const
constexpr

Definition at line 334 of file base_uint.h.

◆ operator!()

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

Definition at line 344 of file base_uint.h.

◆ operator~()

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

Definition at line 350 of file base_uint.h.

◆ operator=() [2/3]

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

Definition at line 361 of file base_uint.h.

◆ operator^=()

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

Definition at line 377 of file base_uint.h.

◆ operator&=()

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

Definition at line 386 of file base_uint.h.

◆ operator|=()

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

Definition at line 395 of file base_uint.h.

◆ operator++() [1/2]

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

Definition at line 404 of file base_uint.h.

◆ operator++() [2/2]

template<std::size_t Bits, class Tag = void>
base_uint const ripple::base_uint< Bits, Tag >::operator++ ( int  )

Definition at line 419 of file base_uint.h.

◆ operator--() [1/2]

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

Definition at line 429 of file base_uint.h.

◆ operator--() [2/2]

template<std::size_t Bits, class Tag = void>
base_uint const ripple::base_uint< Bits, Tag >::operator-- ( int  )

Definition at line 445 of file base_uint.h.

◆ next()

template<std::size_t Bits, class Tag = void>
base_uint ripple::base_uint< Bits, Tag >::next ( ) const

Definition at line 455 of file base_uint.h.

◆ prev()

template<std::size_t Bits, class Tag = void>
base_uint ripple::base_uint< Bits, Tag >::prev ( ) const

Definition at line 462 of file base_uint.h.

◆ operator+=()

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

Definition at line 469 of file base_uint.h.

◆ parseHex() [1/3]

template<std::size_t Bits, class Tag = void>
constexpr bool ripple::base_uint< Bits, Tag >::parseHex ( std::string_view  sv)
constexpr

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 503 of file base_uint.h.

◆ parseHex() [2/3]

template<std::size_t Bits, class Tag = void>
constexpr bool ripple::base_uint< Bits, Tag >::parseHex ( char const *  str)
constexpr

Definition at line 514 of file base_uint.h.

◆ parseHex() [3/3]

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

Definition at line 520 of file base_uint.h.

◆ size()

template<std::size_t Bits, class Tag = void>
static constexpr std::size_t ripple::base_uint< Bits, Tag >::size ( )
staticconstexpr

Definition at line 526 of file base_uint.h.

◆ operator=() [3/3]

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

Definition at line 532 of file base_uint.h.

◆ isZero()

template<std::size_t Bits, class Tag = void>
bool ripple::base_uint< Bits, Tag >::isZero ( ) const

Definition at line 540 of file base_uint.h.

◆ isNonZero()

template<std::size_t Bits, class Tag = void>
bool ripple::base_uint< Bits, Tag >::isNonZero ( ) const

Definition at line 545 of file base_uint.h.

◆ zero()

template<std::size_t Bits, class Tag = void>
void ripple::base_uint< Bits, Tag >::zero ( )

Definition at line 550 of file base_uint.h.

Friends And Related Symbol Documentation

◆ hash_append

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

Definition at line 488 of file base_uint.h.

Member Data Documentation

◆ WIDTH

template<std::size_t Bits, class Tag = void>
constexpr std::size_t ripple::base_uint< Bits, Tag >::WIDTH = Bits / 32
staticconstexprprivate

Definition at line 95 of file base_uint.h.

◆ data_

template<std::size_t Bits, class Tag = void>
std::array<std::uint32_t, WIDTH> ripple::base_uint< Bits, Tag >::data_
private

Definition at line 100 of file base_uint.h.

◆ bytes

template<std::size_t Bits, class Tag = void>
std::size_t constexpr ripple::base_uint< Bits, Tag >::bytes = Bits / 8
staticconstexpr

Definition at line 108 of file base_uint.h.