20#ifndef RIPPLE_PROTOCOL_STOBJECT_H_INCLUDED
21#define RIPPLE_PROTOCOL_STOBJECT_H_INCLUDED
23#include <xrpl/basics/CountedObject.h>
24#include <xrpl/basics/Slice.h>
25#include <xrpl/basics/chrono.h>
26#include <xrpl/basics/contract.h>
27#include <xrpl/beast/utility/instrumentation.h>
28#include <xrpl/protocol/HashPrefix.h>
29#include <xrpl/protocol/SOTemplate.h>
30#include <xrpl/protocol/STAmount.h>
31#include <xrpl/protocol/STBase.h>
32#include <xrpl/protocol/STCurrency.h>
33#include <xrpl/protocol/STIssue.h>
34#include <xrpl/protocol/STPathSet.h>
35#include <xrpl/protocol/STVector256.h>
36#include <xrpl/protocol/Units.h>
37#include <xrpl/protocol/detail/STVar.h>
39#include <boost/iterator/transform_iterator.hpp>
53 Throw<std::runtime_error>(
"Field not found: " + field.getName());
84 transform_iterator<Transform, STObject::list_type::const_iterator>;
165 template <
class... Args>
262 typename T::value_type
309 typename T::value_type
458 template <
typename T,
typename V>
463 template <
typename T,
typename V>
468 template <
typename T>
473 template <
typename T>
541 template <IsArithmetic U>
545 template <IsArithmetic U>
551 template <
typename U>
555 return rhs.
value() == lhs;
583 operator bool() const noexcept;
594 return !lhs.engaged();
622 if (lhs.engaged() != rhs.engaged())
624 return !lhs.engaged() || *lhs == *rhs;
642 return !(lhs == rhs);
648 return !(lhs == rhs);
654 return !(lhs == rhs);
699 Throw<STObject::FieldErr>(
700 "Template field error '" + this->
f_->getName() +
"'");
713 auto const t = find();
718 Throw<STObject::FieldErr>(
"Value requested from invalid STObject.");
722 Throw<STObject::FieldErr>(
723 "Missing field '" + this->f_->getName() +
"'");
732 return this->value();
746 return dynamic_cast<T const*
>(st_->peekAtPField(*f_));
756 st_->makeFieldAbsent(*f_);
761 t =
dynamic_cast<T*
>(st_->getPField(*f_,
true));
763 t =
dynamic_cast<T*
>(st_->makeFieldPresent(*f_));
764 XRPL_ASSERT(t,
"ripple::STObject::Proxy::assign : type cast succeeded");
780template <IsArithmetic U>
784 this->assign(this->value() + u);
789template <IsArithmetic U>
793 this->assign(this->value() - u);
800 return this->value();
819 T>::optional_type()
const
821 return optional_value();
828 return optional_value();
844 this->assign(std::move(*v));
880 return this->style_ ==
soeDEFAULT || this->find() !=
nullptr;
888 Throw<STObject::FieldErr>(
889 "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;
954 return mType ==
nullptr;
974template <
class... Args>
991 return v_[offset].get();
997 return v_[offset].get();
1003 return &
v_[offset].get();
1009 return &
v_[offset].get();
1013typename T::value_type
1041typename T::value_type
1048 Throw<STObject::FieldErr>(
"Missing field: " + f.
getName());
1050 if (
auto const u =
dynamic_cast<T const*
>(b))
1055 "ripple::STObject::at(TypedField auto) : field template non-null");
1057 b->getSType() == STI_NOTPRESENT,
1058 "ripple::STObject::at(TypedField auto) : type not present");
1061 Throw<STObject::FieldErr>(
"Missing optional field: " + f.
getName());
1065 "ripple::STObject::at(TypedField auto) : template style is default");
1080 auto const u =
dynamic_cast<T const*
>(b);
1085 "ripple::STObject::at(OptionaledField auto) : field template "
1088 b->getSType() == STI_NOTPRESENT,
1089 "ripple::STObject::at(OptionaledField auto) : type not present");
1094 "ripple::STObject::at(OptionaledField auto) : template style is "
1096 return typename T::value_type{};
1124 if (rf->
getSType() == STI_NOTPRESENT)
1128 if (
auto cf =
dynamic_cast<Bits*
>(rf))
1131 Throw<std::runtime_error>(
"Wrong field type");
1137 return !(*
this == o);
1140template <
typename T,
typename V>
1151 if (
id == STI_NOTPRESENT)
1154 T
const* cf =
dynamic_cast<T const*
>(rf);
1157 Throw<std::runtime_error>(
"Wrong field type");
1167template <
typename T,
typename V>
1178 if (
id == STI_NOTPRESENT)
1181 T
const* cf =
dynamic_cast<T const*
>(rf);
1184 Throw<std::runtime_error>(
"Wrong field type");
1190template <
typename T,
typename V>
1201 if (rf->
getSType() == STI_NOTPRESENT)
1204 T* cf =
dynamic_cast<T*
>(rf);
1207 Throw<std::runtime_error>(
"Wrong field type");
1209 cf->setValue(std::move(value));
1213template <
typename T>
1222 if (rf->
getSType() == STI_NOTPRESENT)
1225 T* cf =
dynamic_cast<T*
>(rf);
1228 Throw<std::runtime_error>(
"Wrong field type");
1234template <
typename T>
1243 if (rf->
getSType() == STI_NOTPRESENT)
1246 T* cf =
dynamic_cast<T*
>(rf);
1249 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
optional_type operator~() const
Explicit conversion to std::optional.
OptionalProxy(OptionalProxy const &)=default
value_type value_or(value_type val) const
friend bool operator!=(OptionalProxy const &lhs, std::nullopt_t) noexcept
friend bool operator!=(std::nullopt_t, OptionalProxy const &rhs) noexcept
std::enable_if_t< std::is_assignable_v< T, U >, OptionalProxy & > operator=(U &&u)
typename T::value_type value_type
OptionalProxy & operator=(OptionalProxy const &)=delete
optional_type optional_value() const
std::optional< typename std::decay< value_type >::type > optional_type
friend bool operator!=(optional_type const &lhs, OptionalProxy const &rhs) noexcept
friend bool operator==(std::nullopt_t, OptionalProxy const &rhs) noexcept
bool engaged() const noexcept
friend bool operator!=(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
typename T::value_type value_type
Proxy(Proxy const &)=default
TypedField< T > const * f_
value_type operator*() const
T const * operator->() const
ValueProxy & operator-=(U const &u)
typename T::value_type value_type
ValueProxy & operator+=(U const &u)
ValueProxy & operator=(ValueProxy const &)=delete
std::enable_if_t< std::is_assignable_v< T, U >, ValueProxy & > operator=(U &&u)
ValueProxy(ValueProxy const &)=default
friend bool operator==(U const &lhs, STObject::ValueProxy< T > const &rhs)
STPathSet const & getFieldPathSet(SField const &field) const
unsigned char getFieldU8(SField const &field) const
uint192 getFieldH192(SField const &field) const
STBase * getPField(SField const &field, bool createOkay=false)
void setFieldIssue(SField const &field, STIssue const &)
bool operator!=(STObject const &o) const
void applyTemplate(SOTemplate const &type)
Blob getFieldVL(SField const &field) const
boost::transform_iterator< Transform, STObject::list_type::const_iterator > iterator
bool hasMatchingEntry(STBase const &)
bool clearFlag(std::uint32_t)
AccountID getAccountID(SField const &field) const
static std::vector< STBase const * > getSortedFields(STObject const &objToSort, WhichFields whichFields)
T & peekField(SField const &field)
STArray const & getFieldArray(SField const &field) const
uint160 getFieldH160(SField const &field) const
void setFieldCurrency(SField const &field, STCurrency const &)
STBase const * peekAtPField(SField const &field) const
STBase const * peekAtPIndex(int offset) const
void setFieldArray(SField const &field, STArray const &v)
void setFieldPathSet(SField const &field, STPathSet const &)
SField const & getFieldSType(int index) const
STObject(STObject const &)=default
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
bool isFlag(std::uint32_t) const
std::uint16_t getFieldU16(SField const &field) const
virtual ~STObject()=default
void setFieldH256(SField const &field, uint256 const &)
void setFieldNumber(SField const &field, STNumber const &)
bool setFlag(std::uint32_t)
std::uint32_t getFieldU32(SField const &field) const
void setFieldI32(SField const &field, std::int32_t)
STBase * copy(std::size_t n, void *buf) const override
void makeFieldAbsent(SField const &field)
STObject & peekFieldObject(SField const &field)
void setFieldU16(SField const &field, std::uint16_t)
Serializer getSerializer() const
std::uint64_t getFieldU64(SField const &field) const
STBase * makeFieldPresent(SField const &field)
void setFieldU8(SField const &field, unsigned char)
void set(SOTemplate const &)
void add(Serializer &s) const override
STObject(SOTemplate const &type, SField const &name, F &&f)
void setFieldAmount(SField const &field, STAmount const &)
bool delField(SField const &field)
STBase const & peekAtIndex(int offset) const
STBase & getField(SField const &field)
V const & getFieldByConstRef(SField const &field, V const &empty) const
STAmount const & getFieldAmount(SField const &field) const
std::int32_t getFieldI32(SField const &field) const
uint256 getSigningHash(HashPrefix prefix) const
T::value_type operator[](TypedField< T > const &f) const
Get the value of a field.
uint256 getHash(HashPrefix prefix) const
int getFieldIndex(SField const &field) const
STBase & getIndex(int offset)
ValueProxy< T > operator[](TypedField< T > const &f)
Get a modifiable field value.
void setFieldUsingAssignment(SField const &field, T const &value)
SerializedTypeID getSType() const override
std::string getFullText() const override
std::string getText() const override
bool isFieldPresent(SField const &field) const
static STObject makeInnerObject(SField const &name)
STCurrency const & getFieldCurrency(SField const &field) const
bool operator==(STObject const &o) const
void setAccountID(SField const &field, AccountID const &)
uint128 getFieldH128(SField const &field) const
void applyTemplateFromSField(SField const &)
OptionalProxy< T > at(OptionaledField< T > const &of)
Return a modifiable field value as std::optional.
ValueProxy< T > at(TypedField< T > const &f)
Get a modifiable field value.
void setFieldV256(SField const &field, STVector256 const &v)
void setFieldUsingSetValue(SField const &field, V value)
Json::Value getJson(JsonOptions=JsonOptions::none) const override
void setFieldH128(SField const &field, uint128 const &)
void setFieldU64(SField const &field, std::uint64_t)
bool isEquivalent(STBase const &t) const override
void setFieldU32(SField const &field, std::uint32_t)
STBase const & peekAtField(SField const &field) const
V getFieldByValue(SField const &field) const
STBase * move(std::size_t n, void *buf) override
OptionalProxy< T > operator[](OptionaledField< T > const &of)
Return a modifiable field value as std::optional.
std::size_t emplace_back(Args &&... args)
STBase * getPIndex(int offset)
STArray & peekFieldArray(SField const &field)
STNumber const & getFieldNumber(SField const &field) const
void reserve(std::size_t n)
STObject & operator=(STObject const &)=default
void addWithoutSigningFields(Serializer &s) const
void setFieldVL(SField const &field, Blob const &)
std::uint32_t getFlags() const
uint256 getFieldH256(SField const &field) const
void setFieldH160(SField const &field, base_uint< 160, Tag > const &v)
STVector256 const & getFieldV256(SField const &field) const
bool isDefault() 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.
Number operator*(Number const &x, Number const &y)
HashPrefix
Prefix for hashing functions.
SOEStyle
Kind of element in each entry of an SOTemplate.
void throwFieldNotFound(SField const &field)
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.