3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/basics/Slice.h>
5#include <xrpl/basics/chrono.h>
6#include <xrpl/basics/contract.h>
7#include <xrpl/beast/utility/instrumentation.h>
8#include <xrpl/protocol/HashPrefix.h>
9#include <xrpl/protocol/SOTemplate.h>
10#include <xrpl/protocol/STAmount.h>
11#include <xrpl/protocol/STBase.h>
12#include <xrpl/protocol/STCurrency.h>
13#include <xrpl/protocol/STIssue.h>
14#include <xrpl/protocol/STPathSet.h>
15#include <xrpl/protocol/STVector256.h>
16#include <xrpl/protocol/Units.h>
17#include <xrpl/protocol/detail/STVar.h>
19#include <boost/iterator/transform_iterator.hpp>
63 using iterator = boost::transform_iterator<Transform, STObject::list_type::const_iterator>;
143 template <
class... Args>
166 [[nodiscard]]
STBase const&
172 [[nodiscard]]
STBase const*
181 [[nodiscard]]
SField const&
184 [[nodiscard]]
STBase const&
190 [[nodiscard]]
STBase const*
198 [[nodiscard]]
unsigned char
293 [[nodiscard]] T::value_type
448 template <
typename T,
typename V>
453 template <
typename T,
typename V>
458 template <
typename T>
463 template <
typename T>
503 [[nodiscard]] T
const*
516template <
typename U,
typename Value = U::value_type,
typename Unit = U::unit_type>
519template <
typename U,
typename Value = U::value_type>
524template <
class T,
class U>
525concept Addable =
requires(T t, U u) { t = t + u; };
526template <
typename T,
typename U>
547 template <IsArithmetic U>
552 template <IsArithmetic U>
559 template <
typename U>
563 return rhs.
value() == lhs;
591 operator bool() const noexcept;
602 return !lhs.engaged();
608 return rhs == std::nullopt;
630 if (lhs.engaged() != rhs.engaged())
632 return !lhs.engaged() || *lhs == *rhs;
638 return !(lhs == std::nullopt);
644 return !(rhs == std::nullopt);
650 return !(lhs == rhs);
656 return !(lhs == rhs);
662 return !(lhs == rhs);
703 if (
st_->type_ !=
nullptr)
706 if (!st_->peekAtPField(*f_))
707 Throw<STObject::FieldErr>(
"Template field error '" + this->f_->getName() +
"'");
708 style_ = st_->type_->style(*f_);
720 auto const t =
find();
738 return this->
value();
754 return dynamic_cast<T const*
>(
st_->peekAtPField(*
f_));
764 st_->makeFieldAbsent(*
f_);
770 t =
dynamic_cast<T*
>(
st_->getPField(*
f_,
true));
774 t =
dynamic_cast<T*
>(
st_->makeFieldPresent(*
f_));
776 XRPL_ASSERT(t,
"xrpl::STObject::Proxy::assign : type cast succeeded");
792template <IsArithmetic U>
802template <IsArithmetic U>
815 return this->
value();
827operator bool() const noexcept
836 return optionalValue();
862 this->
assign(std::move(*v));
915 this->
st_->delField(*this->
f_);
919 this->
st_->makeFieldAbsent(*this->
f_);
929 return this->
value();
981 return type_ ==
nullptr;
1001template <
class... Args>
1006 return v_.size() - 1;
1018 return v_[offset].get();
1024 return v_[offset].get();
1030 return &
v_[offset].get();
1036 return &
v_[offset].get();
1068[[nodiscard]] T::value_type
1079 if (
auto const u =
dynamic_cast<T const*
>(b))
1082 XRPL_ASSERT(
type_,
"xrpl::STObject::at(TypedField auto) : field template non-null");
1084 b->getSType() == STI_NOTPRESENT,
"xrpl::STObject::at(TypedField auto) : type not present");
1091 "xrpl::STObject::at(TypedField auto) : template style is default");
1105 return std::nullopt;
1106 auto const u =
dynamic_cast<T const*
>(b);
1111 "xrpl::STObject::at(OptionaledField auto) : field template "
1114 b->getSType() == STI_NOTPRESENT,
1115 "xrpl::STObject::at(OptionaledField auto) : type not present");
1117 return std::nullopt;
1120 "xrpl::STObject::at(OptionaledField auto) : template style is "
1122 return typename T::value_type{};
1150 if (rf->
getSType() == STI_NOTPRESENT)
1154 if (
auto cf =
dynamic_cast<Bits*
>(rf))
1167 return !(*
this == o);
1170template <
typename T,
typename V>
1181 if (
id == STI_NOTPRESENT)
1184 T
const* cf =
dynamic_cast<T const*
>(rf);
1197template <
typename T,
typename V>
1208 if (
id == STI_NOTPRESENT)
1214 T
const* cf =
dynamic_cast<T const*
>(rf);
1223template <
typename T,
typename V>
1234 if (rf->
getSType() == STI_NOTPRESENT)
1237 T* cf =
dynamic_cast<T*
>(rf);
1242 cf->setValue(std::move(value));
1246template <
typename T>
1255 if (rf->
getSType() == STI_NOTPRESENT)
1258 T* cf =
dynamic_cast<T*
>(rf);
1267template <
typename T>
1276 if (rf->
getSType() == STI_NOTPRESENT)
1279 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==(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
std::enable_if_t< std::is_assignable_v< T, U >, OptionalProxy & > operator=(U &&u)
OptionalProxy(OptionalProxy const &)=default
value_type valueOr(value_type val) const
optional_type operator~() const
Explicit conversion to std::optional.
friend bool operator!=(OptionalProxy const &lhs, std::nullopt_t) noexcept
std::optional< std::decay_t< value_type > > optional_type
friend bool operator!=(std::nullopt_t, OptionalProxy const &rhs) noexcept
OptionalProxy & operator=(OptionalProxy const &)=delete
optional_type optionalValue() const
bool engaged() const noexcept
friend bool operator!=(optional_type const &lhs, OptionalProxy const &rhs) noexcept
friend bool operator==(std::nullopt_t, OptionalProxy const &rhs) noexcept
friend bool operator!=(OptionalProxy const &lhs, 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 const &u)
ValueProxy & operator+=(U const &u)
friend bool operator==(U const &lhs, STObject::ValueProxy< T > const &rhs)
std::enable_if_t< std::is_assignable_v< T, U >, ValueProxy & > operator=(U &&u)
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)
bool operator!=(STObject const &o) const
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.