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>
33 Throw<std::runtime_error>(
"Field not found: " + field.getName());
63 using iterator = boost::transform_iterator<Transform, STObject::list_type::const_iterator>;
143 template <
class... Args>
243 typename T::value_type
290 typename T::value_type
444 template <
typename T,
typename V>
449 template <
typename T,
typename V>
454 template <
typename T>
459 template <
typename T>
511template <
typename U,
typename Value =
typename U::value_type,
typename Unit =
typename U::unit_type>
514template <
typename U,
typename Value =
typename U::value_type>
519template <
class T,
class U>
520concept Addable =
requires(T t, U u) { t = t + u; };
521template <
typename T,
typename U>
541 template <IsArithmetic U>
546 template <IsArithmetic U>
553 template <
typename U>
557 return rhs.
value() == lhs;
585 operator bool() const noexcept;
596 return !lhs.engaged();
624 if (lhs.engaged() != rhs.engaged())
626 return !lhs.engaged() || *lhs == *rhs;
644 return !(lhs == rhs);
650 return !(lhs == rhs);
656 return !(lhs == rhs);
701 Throw<STObject::FieldErr>(
"Template field error '" + this->
f_->getName() +
"'");
714 auto const t = find();
719 Throw<STObject::FieldErr>(
"Value requested from invalid STObject.");
723 Throw<STObject::FieldErr>(
"Missing field '" + this->f_->getName() +
"'");
732 return this->value();
748 return dynamic_cast<T const*
>(st_->peekAtPField(*f_));
758 st_->makeFieldAbsent(*f_);
763 t =
dynamic_cast<T*
>(st_->getPField(*f_,
true));
765 t =
dynamic_cast<T*
>(st_->makeFieldPresent(*f_));
766 XRPL_ASSERT(t,
"xrpl::STObject::Proxy::assign : type cast succeeded");
782template <IsArithmetic U>
787 this->assign(this->value() + u);
792template <IsArithmetic U>
797 this->assign(this->value() - u);
804 return this->value();
823 return optional_value();
830 return optional_value();
846 this->assign(std::move(*v));
881 return this->style_ ==
soeDEFAULT || this->find() !=
nullptr;
889 Throw<STObject::FieldErr>(
"Template field error '" + this->f_->getName() +
"'");
891 this->st_->delField(*this->f_);
893 this->st_->makeFieldAbsent(*this->f_);
902 return this->value();
909 return engaged() ? this->value() : val;
953 return mType ==
nullptr;
973template <
class... Args>
990 return v_[offset].get();
996 return v_[offset].get();
1002 return &
v_[offset].get();
1008 return &
v_[offset].get();
1012typename T::value_type
1040typename T::value_type
1047 Throw<STObject::FieldErr>(
"Missing field: " + f.
getName());
1049 if (
auto const u =
dynamic_cast<T const*
>(b))
1052 XRPL_ASSERT(
mType,
"xrpl::STObject::at(TypedField auto) : field template non-null");
1053 XRPL_ASSERT(b->getSType() == STI_NOTPRESENT,
"xrpl::STObject::at(TypedField auto) : type not present");
1056 Throw<STObject::FieldErr>(
"Missing optional field: " + f.
getName());
1058 XRPL_ASSERT(
mType->
style(f) ==
soeDEFAULT,
"xrpl::STObject::at(TypedField auto) : template style is default");
1073 auto const u =
dynamic_cast<T const*
>(b);
1078 "xrpl::STObject::at(OptionaledField auto) : field template "
1080 XRPL_ASSERT(b->getSType() == STI_NOTPRESENT,
"xrpl::STObject::at(OptionaledField auto) : type not present");
1085 "xrpl::STObject::at(OptionaledField auto) : template style is "
1087 return typename T::value_type{};
1115 if (rf->
getSType() == STI_NOTPRESENT)
1119 if (
auto cf =
dynamic_cast<Bits*
>(rf))
1122 Throw<std::runtime_error>(
"Wrong field type");
1128 return !(*
this == o);
1131template <
typename T,
typename V>
1142 if (
id == STI_NOTPRESENT)
1145 T
const* cf =
dynamic_cast<T const*
>(rf);
1148 Throw<std::runtime_error>(
"Wrong field type");
1158template <
typename T,
typename V>
1169 if (
id == STI_NOTPRESENT)
1172 T
const* cf =
dynamic_cast<T const*
>(rf);
1175 Throw<std::runtime_error>(
"Wrong field type");
1181template <
typename T,
typename V>
1192 if (rf->
getSType() == STI_NOTPRESENT)
1195 T* cf =
dynamic_cast<T*
>(rf);
1198 Throw<std::runtime_error>(
"Wrong field type");
1200 cf->setValue(std::move(value));
1204template <
typename T>
1213 if (rf->
getSType() == STI_NOTPRESENT)
1216 T* cf =
dynamic_cast<T*
>(rf);
1219 Throw<std::runtime_error>(
"Wrong field type");
1225template <
typename T>
1234 if (rf->
getSType() == STI_NOTPRESENT)
1237 T* cf =
dynamic_cast<T*
>(rf);
1240 Throw<std::runtime_error>(
"Wrong field type");
Tracks the number of instances of an object.
std::string const & getName() const
Defines the fields and their attributes within a STObject.
SOEStyle style(SField const &sf) const
A type which can be exported to a well known binary format.
virtual SerializedTypeID getSType() const
void setValue(base_uint< Bits, Tag > const &v)
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
optional_type operator~() const
Explicit conversion to std::optional.
std::optional< typename std::decay< value_type >::type > optional_type
typename T::value_type value_type
friend bool operator!=(OptionalProxy const &lhs, std::nullopt_t) noexcept
friend bool operator!=(std::nullopt_t, OptionalProxy const &rhs) noexcept
OptionalProxy & operator=(OptionalProxy const &)=delete
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
value_type value_or(value_type val) const
optional_type optional_value() const
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.
typename T::value_type value_type
TypedField< T > const * f_
ValueProxy(ValueProxy const &)=default
ValueProxy & operator=(ValueProxy const &)=delete
typename T::value_type value_type
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
Json::Value getJson(JsonOptions=JsonOptions::none) const override
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
bool hasMatchingEntry(STBase const &)
V const & getFieldByConstRef(SField const &field, V const &empty) const
STNumber const & getFieldNumber(SField const &field) const
OptionalProxy< T > at(OptionaledField< T > const &of)
Return a modifiable field value as std::optional.
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.
std::size_t emplace_back(Args &&... args)
void applyTemplate(SOTemplate const &type)
int getFieldIndex(SField const &field) const
uint256 getHash(HashPrefix prefix) const
void setFieldI32(SField const &field, std::int32_t)
virtual ~STObject()=default
std::string getFullText() const override
void setFieldU32(SField const &field, std::uint32_t)
STArray & peekFieldArray(SField const &field)
std::string getText() const override
STArray const & getFieldArray(SField const &field) const
void setFieldArray(SField const &field, STArray const &v)
STObject & peekFieldObject(SField const &field)
SOEStyle getStyle(SField const &field) const
STBase & getField(SField const &field)
void setFieldAmount(SField const &field, STAmount const &)
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
ValueProxy< T > operator[](TypedField< T > const &f)
Get a modifiable field value.
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 setFieldH160(SField const &field, base_uint< 160, Tag > const &v)
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
V getFieldByValue(SField const &field) const
void makeFieldAbsent(SField const &field)
ValueProxy< T > at(TypedField< T > const &f)
Get a modifiable field value.
void setFieldH256(SField const &field, uint256 const &)
boost::transform_iterator< Transform, STObject::list_type::const_iterator > iterator
OptionalProxy< T > operator[](OptionaledField< T > const &of)
Return a modifiable field value as std::optional.
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.
T emplace_back(T... args)
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)
HashPrefix
Prefix for hashing functions.
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.