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/STIssue.h>
32 #include <ripple/protocol/STPathSet.h>
33 #include <ripple/protocol/STVector256.h>
34 #include <ripple/protocol/impl/STVar.h>
35 #include <boost/iterator/transform_iterator.hpp>
49 Throw<std::runtime_error>(
"Field not found: " + field.getName());
80 transform_iterator<Transform, STObject::list_type::const_iterator>;
159 template <
class... Args>
248 typename T::value_type
295 typename T::value_type
429 decltype(std::declval<T>().value())>::type>::type>
438 template <
typename T,
typename V>
443 template <
typename T,
typename V>
448 template <
typename T>
453 template <
typename T>
533 explicit operator bool() const noexcept;
553 return !lhs.engaged();
559 return rhs == std::nullopt;
581 if (lhs.engaged() != rhs.engaged())
583 return !lhs.engaged() || *lhs == *rhs;
589 return !(lhs == std::nullopt);
595 return !(rhs == std::nullopt);
601 return !(lhs == rhs);
607 return !(lhs == rhs);
613 return !(lhs == rhs);
658 Throw<STObject::FieldErr>(
659 "Template field error '" + this->
f_->getName() +
"'");
672 auto const t = find();
677 Throw<STObject::FieldErr>(
"Value requested from invalid STObject.");
681 Throw<STObject::FieldErr>(
682 "Missing field '" + this->f_->getName() +
"'");
691 return dynamic_cast<T const*
>(st_->peekAtPField(*f_));
701 st_->makeFieldAbsent(*f_);
706 t =
dynamic_cast<T*
>(st_->getPField(*f_,
true));
708 t =
dynamic_cast<T*
>(st_->makeFieldPresent(*f_));
710 *t = std::forward<U>(u);
720 this->assign(std::forward<U>(u));
727 return this->value();
748 return this->value();
753 T>::optional_type()
const
755 return optional_value();
762 return optional_value();
778 this->assign(std::move(*v));
800 this->assign(std::forward<U>(u));
814 return this->style_ ==
soeDEFAULT || this->find() !=
nullptr;
822 Throw<STObject::FieldErr>(
823 "Template field error '" + this->f_->getName() +
"'");
825 this->st_->delField(*this->f_);
827 this->st_->makeFieldAbsent(*this->f_);
836 return this->value();
843 return engaged() ? this->value() : val;
888 return mType ==
nullptr;
908 template <
class... Args>
925 return v_[offset].get();
931 return v_[offset].get();
937 return &
v_[offset].get();
943 return &
v_[offset].get();
947 typename T::value_type
975 typename T::value_type
982 Throw<STObject::FieldErr>(
"Missing field: " + f.
getName());
984 if (
auto const u =
dynamic_cast<T const*
>(b))
991 Throw<STObject::FieldErr>(
"Missing optional field: " + f.
getName());
1007 return std::nullopt;
1008 auto const u =
dynamic_cast<T const*
>(b);
1014 return std::nullopt;
1016 return typename T::value_type{};
1035 template <
class Tag>
1048 if (
auto cf =
dynamic_cast<Bits*
>(rf))
1051 Throw<std::runtime_error>(
"Wrong field type");
1057 return !(*
this == o);
1060 template <
typename T,
typename V>
1074 const T* cf =
dynamic_cast<const T*
>(rf);
1077 Throw<std::runtime_error>(
"Wrong field type");
1087 template <
typename T,
typename V>
1101 const T* cf =
dynamic_cast<const T*
>(rf);
1104 Throw<std::runtime_error>(
"Wrong field type");
1110 template <
typename T,
typename V>
1124 T* cf =
dynamic_cast<T*
>(rf);
1127 Throw<std::runtime_error>(
"Wrong field type");
1129 cf->setValue(std::move(value));
1133 template <
typename T>
1145 T* cf =
dynamic_cast<T*
>(rf);
1148 Throw<std::runtime_error>(
"Wrong field type");
1154 template <
typename T>
1166 T* cf =
dynamic_cast<T*
>(rf);
1169 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.
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