20 #ifndef RIPPLE_PROTOCOL_STOBJECT_H_INCLUDED
21 #define RIPPLE_PROTOCOL_STOBJECT_H_INCLUDED
23 #include <ripple/basics/CountedObject.h>
24 #include <ripple/basics/FeeUnits.h>
25 #include <ripple/basics/Slice.h>
26 #include <ripple/basics/chrono.h>
27 #include <ripple/basics/contract.h>
28 #include <ripple/protocol/HashPrefix.h>
29 #include <ripple/protocol/SOTemplate.h>
30 #include <ripple/protocol/STAmount.h>
31 #include <ripple/protocol/STBase.h>
32 #include <ripple/protocol/STCurrency.h>
33 #include <ripple/protocol/STIssue.h>
34 #include <ripple/protocol/STPathSet.h>
35 #include <ripple/protocol/STVector256.h>
36 #include <ripple/protocol/impl/STVar.h>
37 #include <boost/iterator/transform_iterator.hpp>
52 Throw<std::runtime_error>(
"Field not found: " + field.getName());
83 transform_iterator<Transform, STObject::list_type::const_iterator>;
165 template <
class... Args>
256 typename T::value_type
303 typename T::value_type
439 decltype(std::declval<T>().value())>::type>::type>
448 template <
typename T,
typename V>
453 template <
typename T,
typename V>
458 template <
typename T>
463 template <
typename T>
543 explicit operator bool() const noexcept;
563 return !lhs.engaged();
569 return rhs == std::nullopt;
591 if (lhs.engaged() != rhs.engaged())
593 return !lhs.engaged() || *lhs == *rhs;
599 return !(lhs == std::nullopt);
605 return !(rhs == std::nullopt);
611 return !(lhs == rhs);
617 return !(lhs == rhs);
623 return !(lhs == rhs);
668 Throw<STObject::FieldErr>(
669 "Template field error '" + this->
f_->getName() +
"'");
682 auto const t = find();
687 Throw<STObject::FieldErr>(
"Value requested from invalid STObject.");
691 Throw<STObject::FieldErr>(
692 "Missing field '" + this->f_->getName() +
"'");
701 return dynamic_cast<T const*
>(st_->peekAtPField(*f_));
711 st_->makeFieldAbsent(*f_);
716 t =
dynamic_cast<T*
>(st_->getPField(*f_,
true));
718 t =
dynamic_cast<T*
>(st_->makeFieldPresent(*f_));
720 *t = std::forward<U>(u);
730 this->assign(std::forward<U>(u));
737 return this->value();
758 return this->value();
763 T>::optional_type()
const
765 return optional_value();
772 return optional_value();
788 this->assign(std::move(*v));
810 this->assign(std::forward<U>(u));
824 return this->style_ ==
soeDEFAULT || this->find() !=
nullptr;
832 Throw<STObject::FieldErr>(
833 "Template field error '" + this->f_->getName() +
"'");
835 this->st_->delField(*this->f_);
837 this->st_->makeFieldAbsent(*this->f_);
846 return this->value();
853 return engaged() ? this->value() : val;
898 return mType ==
nullptr;
918 template <
class... Args>
935 return v_[offset].get();
941 return v_[offset].get();
947 return &
v_[offset].get();
953 return &
v_[offset].get();
957 typename T::value_type
985 typename T::value_type
992 Throw<STObject::FieldErr>(
"Missing field: " + f.
getName());
994 if (
auto const u =
dynamic_cast<T const*
>(b))
998 assert(b->getSType() == STI_NOTPRESENT);
1001 Throw<STObject::FieldErr>(
"Missing optional field: " + f.
getName());
1017 return std::nullopt;
1018 auto const u =
dynamic_cast<T const*
>(b);
1022 assert(b->getSType() == STI_NOTPRESENT);
1024 return std::nullopt;
1026 return typename T::value_type{};
1045 template <
class Tag>
1054 if (rf->
getSType() == STI_NOTPRESENT)
1058 if (
auto cf =
dynamic_cast<Bits*
>(rf))
1061 Throw<std::runtime_error>(
"Wrong field type");
1067 return !(*
this == o);
1070 template <
typename T,
typename V>
1081 if (
id == STI_NOTPRESENT)
1084 const T* cf =
dynamic_cast<const T*
>(rf);
1087 Throw<std::runtime_error>(
"Wrong field type");
1097 template <
typename T,
typename V>
1108 if (
id == STI_NOTPRESENT)
1111 const T* cf =
dynamic_cast<const T*
>(rf);
1114 Throw<std::runtime_error>(
"Wrong field type");
1120 template <
typename T,
typename V>
1131 if (rf->
getSType() == STI_NOTPRESENT)
1134 T* cf =
dynamic_cast<T*
>(rf);
1137 Throw<std::runtime_error>(
"Wrong field type");
1139 cf->setValue(std::move(value));
1143 template <
typename T>
1152 if (rf->
getSType() == STI_NOTPRESENT)
1155 T* cf =
dynamic_cast<T*
>(rf);
1158 Throw<std::runtime_error>(
"Wrong field type");
1164 template <
typename T>
1173 if (rf->
getSType() == STI_NOTPRESENT)
1176 T* cf =
dynamic_cast<T*
>(rf);
1179 Throw<std::runtime_error>(
"Wrong field type");
SField const & getFieldSType(int index) const
const STBase & peekAtField(SField const &field) const
friend bool operator==(OptionalProxy const &lhs, optional_type const &rhs) noexcept
typename T::value_type value_type
static std::vector< STBase const * > getSortedFields(STObject const &objToSort, WhichFields whichFields)
void setAccountID(SField const &field, AccountID const &)
STObject(STObject const &)=default
bool engaged() const noexcept
const STArray & getFieldArray(SField const &field) const
void applyTemplate(const SOTemplate &type)
virtual SerializedTypeID getSType() const
SOEStyle style(SField const &sf) const
Tracks the number of instances of an object.
void makeFieldAbsent(SField const &field)
bool hasMatchingEntry(const STBase &)
A field with a type known at compile time.
void setFieldH128(SField const &field, uint128 const &)
void setFieldU16(SField const &field, std::uint16_t)
void setFieldIssue(SField const &field, STIssue const &)
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
void setFieldV256(SField const &field, STVector256 const &v)
std::uint64_t getFieldU64(SField const &field) const
An immutable linear range of bytes.
const STBase * peekAtPIndex(int offset) const
const STVector256 & getFieldV256(SField const &field) const
friend bool operator!=(OptionalProxy const &lhs, optional_type const &rhs) noexcept
typename T::value_type value_type
friend bool operator!=(OptionalProxy const &lhs, std::nullopt_t) noexcept
V const & getFieldByConstRef(SField const &field, V const &empty) const
unsigned char getFieldU8(SField const &field) const
Serializer getSerializer() const
uint128 getFieldH128(SField const &field) const
Indicate std::optional field semantics.
OptionalProxy & operator=(OptionalProxy const &)=delete
void setFieldCurrency(SField const &field, STCurrency const &)
STBase * move(std::size_t n, void *buf) override
void setFieldVL(SField const &field, Blob const &)
Blob getFieldVL(SField const &field) const
bool isDefault() const override
void setValue(base_uint< Bits, Tag > const &v)
friend bool operator==(std::nullopt_t, OptionalProxy const &rhs) noexcept
virtual ~STObject()=default
uint160 getFieldH160(SField const &field) const
const STCurrency & getFieldCurrency(SField const &field) const
std::string getFullText() const override
bool isEquivalent(const STBase &t) const override
const STBase & peekAtIndex(int offset) const
void setFieldH160(SField const &field, base_uint< 160, Tag > const &v)
friend bool operator!=(optional_type const &lhs, OptionalProxy const &rhs) noexcept
STObject & operator=(STObject const &)=default
OptionalProxy(OptionalProxy const &)=default
bool delField(SField const &field)
typename T::value_type value_type
STBase * copy(std::size_t n, void *buf) const override
Defines the fields and their attributes within a STObject.
void setFieldArray(SField const &field, STArray const &v)
boost::transform_iterator< Transform, STObject::list_type::const_iterator > iterator
HashPrefix
Prefix for hashing functions.
static STObject makeInnerObject(SField const &name, Rules const &rules)
TypedField< T > const * f_
void setFieldU8(SField const &field, unsigned char)
STArray & peekFieldArray(SField const &field)
std::optional< typename std::decay< value_type >::type > optional_type
bool operator==(const STObject &o) const
void setFieldAmount(SField const &field, STAmount const &)
bool operator!=(const STObject &o) const
AccountID getAccountID(SField const &field) const
void setFieldH256(SField const &field, uint256 const &)
SOEStyle
Kind of element in each entry of an SOTemplate.
void throwFieldNotFound(SField const &field)
bool clearFlag(std::uint32_t)
std::uint32_t getFlags() const
T runtime_error(T... args)
friend bool operator!=(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
void addWithoutSigningFields(Serializer &s) const
void reserve(std::size_t n)
std::uint16_t getFieldU16(SField const &field) const
void setFieldUsingAssignment(SField const &field, T const &value)
STObject(SOTemplate const &type, SField const &name, F &&f)
STBase * getPField(SField const &field, bool createOkay=false)
void setFieldPathSet(SField const &field, STPathSet const &)
int getFieldIndex(SField const &field) const
STBase * makeFieldPresent(SField const &field)
std::size_t emplace_back(Args &&... args)
ValueProxy(ValueProxy const &)=default
void add(Serializer &s) const override
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
STBase & getIndex(int offset)
STObject & peekFieldObject(SField const &field)
Note, should be treated as flags that can be | and &.
uint256 getSigningHash(HashPrefix prefix) const
const STBase * peekAtPField(SField const &field) const
A type which can be exported to a well known binary format.
STBase & getField(SField const &field)
SerializedTypeID getSType() const override
std::string const & getName() const
T & peekField(SField const &field)
bool isFieldPresent(SField const &field) const
friend bool operator==(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
optional_type operator~() const
Explicit conversion to std::optional.
Proxy(Proxy const &)=default
friend bool operator==(optional_type const &lhs, OptionalProxy const &rhs) noexcept
void setFieldUsingSetValue(SField const &field, V value)
bool setFlag(std::uint32_t)
bool isFlag(std::uint32_t) const
Rules controlling protocol behavior.
value_type operator*() const
Return the contained value.
friend bool operator!=(std::nullopt_t, OptionalProxy const &rhs) noexcept
TypedField< T > const * f
void applyTemplateFromSField(SField const &)
optional_type optional_value() const
T::value_type operator[](TypedField< T > const &f) const
Get the value of a field.
std::uint32_t getFieldU32(SField const &field) const
V getFieldByValue(SField const &field) const
value_type value_or(value_type val) const
void setFieldU64(SField const &field, std::uint64_t)
Json::Value getJson(JsonOptions options) const override
STPathSet const & getFieldPathSet(SField const &field) const
void set(const SOTemplate &)
void setFieldU32(SField const &field, std::uint32_t)
STAmount const & getFieldAmount(SField const &field) const
STBase * getPIndex(int offset)
ValueProxy & operator=(ValueProxy const &)=delete
uint256 getHash(HashPrefix prefix) const
std::string getText() const override
uint256 getFieldH256(SField const &field) const