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/STIssue.h>
33 #include <ripple/protocol/STPathSet.h>
34 #include <ripple/protocol/STVector256.h>
35 #include <ripple/protocol/impl/STVar.h>
36 #include <boost/iterator/transform_iterator.hpp>
51 Throw<std::runtime_error>(
"Field not found: " + field.getName());
82 transform_iterator<Transform, STObject::list_type::const_iterator>;
164 template <
class... Args>
253 typename T::value_type
300 typename T::value_type
434 decltype(std::declval<T>().value())>::type>::type>
443 template <
typename T,
typename V>
448 template <
typename T,
typename V>
453 template <
typename T>
458 template <
typename T>
538 explicit operator bool() const noexcept;
558 return !lhs.engaged();
564 return rhs == std::nullopt;
586 if (lhs.engaged() != rhs.engaged())
588 return !lhs.engaged() || *lhs == *rhs;
594 return !(lhs == std::nullopt);
600 return !(rhs == std::nullopt);
606 return !(lhs == rhs);
612 return !(lhs == rhs);
618 return !(lhs == rhs);
663 Throw<STObject::FieldErr>(
664 "Template field error '" + this->
f_->getName() +
"'");
677 auto const t = find();
682 Throw<STObject::FieldErr>(
"Value requested from invalid STObject.");
686 Throw<STObject::FieldErr>(
687 "Missing field '" + this->f_->getName() +
"'");
696 return dynamic_cast<T const*
>(st_->peekAtPField(*f_));
706 st_->makeFieldAbsent(*f_);
711 t =
dynamic_cast<T*
>(st_->getPField(*f_,
true));
713 t =
dynamic_cast<T*
>(st_->makeFieldPresent(*f_));
715 *t = std::forward<U>(u);
725 this->assign(std::forward<U>(u));
732 return this->value();
753 return this->value();
758 T>::optional_type()
const
760 return optional_value();
767 return optional_value();
783 this->assign(std::move(*v));
805 this->assign(std::forward<U>(u));
819 return this->style_ ==
soeDEFAULT || this->find() !=
nullptr;
827 Throw<STObject::FieldErr>(
828 "Template field error '" + this->f_->getName() +
"'");
830 this->st_->delField(*this->f_);
832 this->st_->makeFieldAbsent(*this->f_);
841 return this->value();
848 return engaged() ? this->value() : val;
893 return mType ==
nullptr;
913 template <
class... Args>
930 return v_[offset].get();
936 return v_[offset].get();
942 return &
v_[offset].get();
948 return &
v_[offset].get();
952 typename T::value_type
980 typename T::value_type
987 Throw<STObject::FieldErr>(
"Missing field: " + f.
getName());
989 if (
auto const u =
dynamic_cast<T const*
>(b))
993 assert(b->getSType() == STI_NOTPRESENT);
996 Throw<STObject::FieldErr>(
"Missing optional field: " + f.
getName());
1012 return std::nullopt;
1013 auto const u =
dynamic_cast<T const*
>(b);
1017 assert(b->getSType() == STI_NOTPRESENT);
1019 return std::nullopt;
1021 return typename T::value_type{};
1040 template <
class Tag>
1049 if (rf->
getSType() == STI_NOTPRESENT)
1053 if (
auto cf =
dynamic_cast<Bits*
>(rf))
1056 Throw<std::runtime_error>(
"Wrong field type");
1062 return !(*
this == o);
1065 template <
typename T,
typename V>
1076 if (
id == STI_NOTPRESENT)
1079 const T* cf =
dynamic_cast<const T*
>(rf);
1082 Throw<std::runtime_error>(
"Wrong field type");
1092 template <
typename T,
typename V>
1103 if (
id == STI_NOTPRESENT)
1106 const T* cf =
dynamic_cast<const T*
>(rf);
1109 Throw<std::runtime_error>(
"Wrong field type");
1115 template <
typename T,
typename V>
1126 if (rf->
getSType() == STI_NOTPRESENT)
1129 T* cf =
dynamic_cast<T*
>(rf);
1132 Throw<std::runtime_error>(
"Wrong field type");
1134 cf->setValue(std::move(value));
1138 template <
typename T>
1147 if (rf->
getSType() == STI_NOTPRESENT)
1150 T* cf =
dynamic_cast<T*
>(rf);
1153 Throw<std::runtime_error>(
"Wrong field type");
1159 template <
typename T>
1168 if (rf->
getSType() == STI_NOTPRESENT)
1171 T* cf =
dynamic_cast<T*
>(rf);
1174 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
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
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