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/STPathSet.h>
32 #include <ripple/protocol/STVector256.h>
33 #include <ripple/protocol/impl/STVar.h>
34 #include <boost/iterator/transform_iterator.hpp>
48 Throw<std::runtime_error>(
"Field not found: " + field.getName());
79 transform_iterator<Transform, STObject::list_type::const_iterator>;
158 template <
class... Args>
247 typename T::value_type
294 typename T::value_type
426 decltype(std::declval<T>().value())>::type>::type>
435 template <
typename T,
typename V>
440 template <
typename T,
typename V>
445 template <
typename T>
450 template <
typename T>
530 explicit operator bool() const noexcept;
550 return !lhs.engaged();
556 return rhs == std::nullopt;
578 if (lhs.engaged() != rhs.engaged())
580 return !lhs.engaged() || *lhs == *rhs;
586 return !(lhs == std::nullopt);
592 return !(rhs == std::nullopt);
598 return !(lhs == rhs);
604 return !(lhs == rhs);
610 return !(lhs == rhs);
655 Throw<STObject::FieldErr>(
656 "Template field error '" + this->
f_->getName() +
"'");
669 auto const t = find();
674 Throw<STObject::FieldErr>(
"Value requested from invalid STObject.");
678 Throw<STObject::FieldErr>(
679 "Missing field '" + this->f_->getName() +
"'");
688 return dynamic_cast<T const*
>(st_->peekAtPField(*f_));
698 st_->makeFieldAbsent(*f_);
703 t =
dynamic_cast<T*
>(st_->getPField(*f_,
true));
705 t =
dynamic_cast<T*
>(st_->makeFieldPresent(*f_));
707 *t = std::forward<U>(u);
717 this->assign(std::forward<U>(u));
724 return this->value();
745 return this->value();
750 T>::optional_type()
const
752 return optional_value();
759 return optional_value();
775 this->assign(std::move(*v));
797 this->assign(std::forward<U>(u));
811 return this->style_ ==
soeDEFAULT || this->find() !=
nullptr;
819 Throw<STObject::FieldErr>(
820 "Template field error '" + this->f_->getName() +
"'");
822 this->st_->delField(*this->f_);
824 this->st_->makeFieldAbsent(*this->f_);
833 return this->value();
840 return engaged() ? this->value() : val;
885 return mType ==
nullptr;
905 template <
class... Args>
922 return v_[offset].get();
928 return v_[offset].get();
934 return &
v_[offset].get();
940 return &
v_[offset].get();
944 typename T::value_type
972 typename T::value_type
979 Throw<STObject::FieldErr>(
"Missing field: " + f.
getName());
981 if (
auto const u =
dynamic_cast<T const*
>(b))
988 Throw<STObject::FieldErr>(
"Missing optional field: " + f.
getName());
1004 return std::nullopt;
1005 auto const u =
dynamic_cast<T const*
>(b);
1011 return std::nullopt;
1013 return typename T::value_type{};
1032 template <
class Tag>
1045 if (
auto cf =
dynamic_cast<Bits*
>(rf))
1048 Throw<std::runtime_error>(
"Wrong field type");
1054 return !(*
this == o);
1057 template <
typename T,
typename V>
1071 const T* cf =
dynamic_cast<const T*
>(rf);
1074 Throw<std::runtime_error>(
"Wrong field type");
1084 template <
typename T,
typename V>
1098 const T* cf =
dynamic_cast<const T*
>(rf);
1101 Throw<std::runtime_error>(
"Wrong field type");
1107 template <
typename T,
typename V>
1121 T* cf =
dynamic_cast<T*
>(rf);
1124 Throw<std::runtime_error>(
"Wrong field type");
1126 cf->setValue(std::move(value));
1130 template <
typename T>
1142 T* cf =
dynamic_cast<T*
>(rf);
1145 Throw<std::runtime_error>(
"Wrong field type");
1151 template <
typename T>
1163 T* cf =
dynamic_cast<T*
>(rf);
1166 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)
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.
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)
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
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