3#include <xrpl/basics/Blob.h>
4#include <xrpl/basics/CountedObject.h>
5#include <xrpl/basics/Number.h>
6#include <xrpl/basics/Slice.h>
7#include <xrpl/basics/base_uint.h>
8#include <xrpl/basics/contract.h>
9#include <xrpl/beast/utility/instrumentation.h>
10#include <xrpl/json/json_value.h>
11#include <xrpl/protocol/AccountID.h>
12#include <xrpl/protocol/HashPrefix.h>
13#include <xrpl/protocol/SField.h>
14#include <xrpl/protocol/SOTemplate.h>
15#include <xrpl/protocol/STAmount.h>
16#include <xrpl/protocol/STBase.h>
17#include <xrpl/protocol/STBitString.h>
18#include <xrpl/protocol/STCurrency.h>
19#include <xrpl/protocol/STIssue.h>
20#include <xrpl/protocol/STPathSet.h>
21#include <xrpl/protocol/STVector256.h>
22#include <xrpl/protocol/Serializer.h>
23#include <xrpl/protocol/Units.h>
24#include <xrpl/protocol/detail/STVar.h>
26#include <boost/iterator/transform_iterator.hpp>
75 using iterator = boost::transform_iterator<Transform, STObject::list_type::const_iterator>;
97 bool requireCanonicalOrder =
false);
130 set(
SerialIter& u,
int depth = 0,
bool requireCanonicalOrder =
false);
159 template <
class... Args>
182 [[nodiscard]]
STBase const&
188 [[nodiscard]]
STBase const*
197 [[nodiscard]]
SField const&
200 [[nodiscard]]
STBase const&
206 [[nodiscard]]
STBase const*
214 [[nodiscard]]
unsigned char
314 [[nodiscard]] T::value_type
471 template <
typename T,
typename V>
476 template <
typename T,
typename V>
481 template <
typename T>
486 template <
typename T>
528 [[nodiscard]] T
const*
541template <
typename U,
typename Value = U::value_type,
typename Unit = U::unit_type>
544template <
typename U,
typename Value = U::value_type>
549template <
class T,
class U>
550concept Addable =
requires(T t, U u) { t = t + u; };
551template <
typename T,
typename U>
577 template <IsArithmetic U>
582 template <IsArithmetic U>
589 template <
typename U>
593 return rhs.
value() == lhs;
622 operator bool() const noexcept;
635 return !lhs.engaged();
641 return rhs == std::nullopt;
663 if (lhs.engaged() != rhs.engaged())
665 return !lhs.engaged() || *lhs == *rhs;
707 if (
st_->type_ !=
nullptr)
710 if (!st_->peekAtPField(*f_))
711 Throw<STObject::FieldErr>(
"Template field error '" + this->f_->getName() +
"'");
712 style_ = st_->type_->style(*f_);
724 auto const t =
find();
742 return this->
value();
760 return dynamic_cast<T const*
>(
st_->peekAtPField(*
f_));
770 st_->makeFieldAbsent(*
f_);
776 t =
dynamic_cast<T*
>(
st_->getPField(*
f_,
true));
780 t =
dynamic_cast<T*
>(
st_->makeFieldPresent(*
f_));
782 XRPL_ASSERT(t,
"xrpl::STObject::Proxy::assign : type cast succeeded");
800template <IsArithmetic U>
810template <IsArithmetic U>
823 return this->
value();
835operator bool() const noexcept
844 return optionalValue();
870 this->
assign(std::move(*v));
924 this->
st_->delField(*this->
f_);
928 this->
st_->makeFieldAbsent(*this->
f_);
938 return this->
value();
990 return type_ ==
nullptr;
1010template <
class... Args>
1015 return v_.size() - 1;
1027 return v_[offset].get();
1033 return v_[offset].get();
1039 return &
v_[offset].get();
1045 return &
v_[offset].get();
1077[[nodiscard]] T::value_type
1088 if (
auto const u =
dynamic_cast<T const*
>(b))
1091 XRPL_ASSERT(
type_,
"xrpl::STObject::at(TypedField auto) : field template non-null");
1093 b->getSType() == STI_NOTPRESENT,
"xrpl::STObject::at(TypedField auto) : type not present");
1100 "xrpl::STObject::at(TypedField auto) : template style is default");
1114 return std::nullopt;
1115 auto const u =
dynamic_cast<T const*
>(b);
1120 "xrpl::STObject::at(OptionaledField auto) : field template "
1123 b->getSType() == STI_NOTPRESENT,
1124 "xrpl::STObject::at(OptionaledField auto) : type not present");
1126 return std::nullopt;
1129 "xrpl::STObject::at(OptionaledField auto) : template style is "
1131 return typename T::value_type{};
1159 if (rf->
getSType() == STI_NOTPRESENT)
1163 if (
auto cf =
dynamic_cast<Bits*
>(rf))
1173template <
typename T,
typename V>
1184 if (
id == STI_NOTPRESENT)
1187 T
const* cf =
dynamic_cast<T const*
>(rf);
1200template <
typename T,
typename V>
1211 if (
id == STI_NOTPRESENT)
1217 T
const* cf =
dynamic_cast<T const*
>(rf);
1226template <
typename T,
typename V>
1237 if (rf->
getSType() == STI_NOTPRESENT)
1240 T* cf =
dynamic_cast<T*
>(rf);
1245 cf->setValue(std::move(value));
1249template <
typename T>
1258 if (rf->
getSType() == STI_NOTPRESENT)
1261 T* cf =
dynamic_cast<T*
>(rf);
1270template <
typename T>
1279 if (rf->
getSType() == STI_NOTPRESENT)
1282 T* cf =
dynamic_cast<T*
>(rf);
Integers of any length that is a multiple of 32-bits.
std::string const & getName() const
Defines the fields and their attributes within a STObject.
A type which can be exported to a well known binary format.
virtual SerializedTypeID getSType() const
T runtime_error(T... args)
friend bool operator==(OptionalProxy const &lhs, optional_type const &rhs) noexcept
friend bool operator==(optional_type const &lhs, OptionalProxy const &rhs) noexcept
friend bool operator==(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
OptionalProxy(OptionalProxy const &)=default
value_type valueOr(value_type val) const
optional_type operator~() const
Explicit conversion to std::optional.
OptionalProxy & operator=(U &&u)
std::optional< std::decay_t< value_type > > optional_type
OptionalProxy & operator=(OptionalProxy const &)=delete
optional_type optionalValue() const
bool engaged() const noexcept
friend bool operator==(std::nullopt_t, OptionalProxy const &rhs) noexcept
Proxy(Proxy const &)=default
value_type operator*() const
T const * operator->() const
Do not use operator->() unless the field is required, or you've checked that it's set.
TypedField< T > const * f_
ValueProxy(ValueProxy const &)=default
ValueProxy & operator=(ValueProxy const &)=delete
ValueProxy & operator=(U &&u)
ValueProxy & operator-=(U const &u)
ValueProxy & operator+=(U const &u)
friend bool operator==(U const &lhs, STObject::ValueProxy< T > const &rhs)
void setFieldU8(SField const &field, unsigned char)
SField const & getFieldSType(int index) const
uint192 getFieldH192(SField const &field) const
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
STBase const * peekAtPIndex(int offset) const
void setFieldH192(SField const &field, uint192 const &)
STCurrency const & getFieldCurrency(SField const &field) const
Blob getFieldVL(SField const &field) const
void addWithoutSigningFields(Serializer &s) const
void setFieldIssue(SField const &field, STIssue const &)
uint128 getFieldH128(SField const &field) const
bool operator==(STObject const &o) const
bool isEquivalent(STBase const &t) const override
void setFieldNumber(SField const &field, STNumber const &)
void setFieldV256(SField const &field, STVector256 const &v)
void setFieldU64(SField const &field, std::uint64_t)
unsigned char getFieldU8(SField const &field) const
std::uint32_t getFieldU32(SField const &field) const
STBase const & peekAtIndex(int offset) const
V const & getFieldByConstRef(SField const &field, V const &empty) const
STNumber const & getFieldNumber(SField const &field) const
void setFieldVL(SField const &field, Blob const &)
void reserve(std::size_t n)
T::value_type operator[](TypedField< T > const &f) const
Get the value of a field.
void applyTemplate(SOTemplate const &type)
int getFieldIndex(SField const &field) const
uint256 getHash(HashPrefix prefix) const
void setFieldI32(SField const &field, std::int32_t)
std::string getFullText() const override
void setFieldU32(SField const &field, std::uint32_t)
STArray & peekFieldArray(SField const &field)
std::string getText() const override
~STObject() override=default
std::size_t emplaceBack(Args &&... args)
STArray const & getFieldArray(SField const &field) const
void setFieldArray(SField const &field, STArray const &v)
V getFieldByValue(SField const &field) const
STObject & peekFieldObject(SField const &field)
SOEStyle getStyle(SField const &field) const
STBase & getField(SField const &field)
std::vector< detail::STVar > list_type
void setFieldAmount(SField const &field, STAmount const &)
json::Value getJson(JsonOptions=JsonOptions::Values::None) const override
void add(Serializer &s) const override
Serializer getSerializer() const
bool isFlag(std::uint32_t) const
bool isFieldPresent(SField const &field) const
STObject & operator=(STObject const &)=default
STObject(STObject const &)=default
SerializedTypeID getSType() const override
void setFieldU16(SField const &field, std::uint16_t)
uint256 getFieldH256(SField const &field) const
static STObject makeInnerObject(SField const &name)
std::int32_t getFieldI32(SField const &field) const
STBase const & peekAtField(SField const &field) const
void set(SOTemplate const &)
STObject(SOTemplate const &type, SField const &name, F &&f)
uint256 getSigningHash(HashPrefix prefix) const
bool clearFlag(std::uint32_t)
void setFieldCurrency(SField const &field, STCurrency const &)
std::uint64_t getFieldU64(SField const &field) const
void setFieldPathSet(SField const &field, STPathSet const &)
STBase * move(std::size_t n, void *buf) override
static std::vector< STBase const * > getSortedFields(STObject const &objToSort, WhichFields whichFields)
STBase * getPField(SField const &field, bool createOkay=false)
STBase * makeFieldPresent(SField const &field)
STBase const * peekAtPField(SField const &field) const
void applyTemplateFromSField(SField const &)
bool setFlag(std::uint32_t)
void setFieldObject(SField const &field, STObject const &v)
void setFieldH128(SField const &field, uint128 const &)
STObject getFieldObject(SField const &field) const
T & peekField(SField const &field)
void setFieldUsingSetValue(SField const &field, V value)
void setAccountID(SField const &field, AccountID const &)
void setFieldUsingAssignment(SField const &field, T const &value)
bool delField(SField const &field)
STBase & getIndex(int offset)
uint160 getFieldH160(SField const &field) const
AccountID getAccountID(SField const &field) const
STBase * getPIndex(int offset)
STVector256 const & getFieldV256(SField const &field) const
STPathSet const & getFieldPathSet(SField const &field) const
bool isDefault() const override
void setFieldH160(SField const &field, BaseUInt< 160, Tag > const &v)
void makeFieldAbsent(SField const &field)
bool hasMatchingEntry(STBase const &) const
void setFieldH256(SField const &field, uint256 const &)
boost::transform_iterator< Transform, STObject::list_type::const_iterator > iterator
std::uint16_t getFieldU16(SField const &field) const
STAmount const & getFieldAmount(SField const &field) const
std::uint32_t getFlags() const
STBase * copy(std::size_t n, void *buf) const override
An immutable linear range of bytes.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void throwFieldNotFound(SField const &field)
SOEStyle
Kind of element in each entry of an SOTemplate.
Number operator*(Number const &x, Number const &y)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
HashPrefix
Prefix for hashing functions.
std::vector< unsigned char > Blob
Storage for linear binary data.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
T runtime_error(T... args)
Note, should be treated as flags that can be | and &.
Indicate std::optional field semantics.
TypedField< T > const * f
A field with a type known at compile time.