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>
265 typename T::value_type
312 typename T::value_type
463 template <
typename T,
typename V>
468 template <
typename T,
typename V>
473 template <
typename T>
478 template <
typename T>
546 template <IsArithmetic U>
550 template <IsArithmetic U>
556 template <
typename U>
560 return rhs.
value() == lhs;
588 operator bool() const noexcept;
599 return !lhs.engaged();
627 if (lhs.engaged() != rhs.engaged())
629 return !lhs.engaged() || *lhs == *rhs;
647 return !(lhs == rhs);
653 return !(lhs == rhs);
659 return !(lhs == rhs);
704 Throw<STObject::FieldErr>(
705 "Template field error '" + this->
f_->getName() +
"'");
718 auto const t = find();
723 Throw<STObject::FieldErr>(
"Value requested from invalid STObject.");
727 Throw<STObject::FieldErr>(
728 "Missing field '" + this->f_->getName() +
"'");
737 return this->value();
751 return dynamic_cast<T const*
>(st_->peekAtPField(*f_));
761 st_->makeFieldAbsent(*f_);
766 t =
dynamic_cast<T*
>(st_->getPField(*f_,
true));
768 t =
dynamic_cast<T*
>(st_->makeFieldPresent(*f_));
769 XRPL_ASSERT(t,
"ripple::STObject::Proxy::assign : type cast succeeded");
785template <IsArithmetic U>
789 this->assign(this->value() + u);
794template <IsArithmetic U>
798 this->assign(this->value() - u);
805 return this->value();
824 T>::optional_type()
const
826 return optional_value();
833 return optional_value();
849 this->assign(std::move(*v));
885 return this->style_ ==
soeDEFAULT || this->find() !=
nullptr;
893 Throw<STObject::FieldErr>(
894 "Template field error '" + this->f_->getName() +
"'");
896 this->st_->delField(*this->f_);
898 this->st_->makeFieldAbsent(*this->f_);
907 return this->value();
914 return engaged() ? this->value() : val;
959 return mType ==
nullptr;
979template <
class... Args>
996 return v_[offset].get();
1002 return v_[offset].get();
1008 return &
v_[offset].get();
1014 return &
v_[offset].get();
1018typename T::value_type
1046typename T::value_type
1053 Throw<STObject::FieldErr>(
"Missing field: " + f.
getName());
1055 if (
auto const u =
dynamic_cast<T const*
>(b))
1060 "ripple::STObject::at(TypedField auto) : field template non-null");
1062 b->getSType() == STI_NOTPRESENT,
1063 "ripple::STObject::at(TypedField auto) : type not present");
1066 Throw<STObject::FieldErr>(
"Missing optional field: " + f.
getName());
1070 "ripple::STObject::at(TypedField auto) : template style is default");
1085 auto const u =
dynamic_cast<T const*
>(b);
1090 "ripple::STObject::at(OptionaledField auto) : field template "
1093 b->getSType() == STI_NOTPRESENT,
1094 "ripple::STObject::at(OptionaledField auto) : type not present");
1099 "ripple::STObject::at(OptionaledField auto) : template style is "
1101 return typename T::value_type{};
1129 if (rf->
getSType() == STI_NOTPRESENT)
1133 if (
auto cf =
dynamic_cast<Bits*
>(rf))
1136 Throw<std::runtime_error>(
"Wrong field type");
1142 return !(*
this == o);
1145template <
typename T,
typename V>
1156 if (
id == STI_NOTPRESENT)
1159 T
const* cf =
dynamic_cast<T const*
>(rf);
1162 Throw<std::runtime_error>(
"Wrong field type");
1172template <
typename T,
typename V>
1183 if (
id == STI_NOTPRESENT)
1186 T
const* cf =
dynamic_cast<T const*
>(rf);
1189 Throw<std::runtime_error>(
"Wrong field type");
1195template <
typename T,
typename V>
1206 if (rf->
getSType() == STI_NOTPRESENT)
1209 T* cf =
dynamic_cast<T*
>(rf);
1212 Throw<std::runtime_error>(
"Wrong field type");
1214 cf->setValue(std::move(value));
1218template <
typename T>
1227 if (rf->
getSType() == STI_NOTPRESENT)
1230 T* cf =
dynamic_cast<T*
>(rf);
1233 Throw<std::runtime_error>(
"Wrong field type");
1239template <
typename T>
1248 if (rf->
getSType() == STI_NOTPRESENT)
1251 T* cf =
dynamic_cast<T*
>(rf);
1254 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
STObject getFieldObject(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
void setFieldObject(SField const &field, STObject const &v)
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.