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>
35 #include <boost/optional.hpp>
48 Throw<std::runtime_error>(
"Field not found: " + field.getName());
107 boost::optional<typename std::decay<value_type>::type>;
119 explicit operator bool() const noexcept;
145 return rhs == boost::none;
167 if (lhs.engaged() != rhs.engaged())
169 return !lhs.engaged() || *lhs == *rhs;
175 return !(lhs == boost::none);
181 return !(rhs == boost::none);
187 return !(lhs == rhs);
193 return !(lhs == rhs);
199 return !(lhs == rhs);
256 transform_iterator<Transform, STObject::list_type::const_iterator>;
269 SField const& name) noexcept(
false);
294 return emplace(n, buf, std::move(*
this));
330 return mType ==
nullptr;
383 template <
class... Args>
411 return v_[offset].get();
416 return v_[offset].get();
421 return &
v_[offset].get();
426 return &
v_[offset].get();
482 typename T::value_type
494 boost::optional<std::decay_t<typename T::value_type>>
529 typename T::value_type
541 boost::optional<std::decay_t<typename T::value_type>>
616 if (
auto cf =
dynamic_cast<Bits*
>(rf))
619 Throw<std::runtime_error>(
"Wrong field type");
646 return !(*
this == o);
674 decltype(std::declval<T>().
value())>::type>::type>
688 const T* cf =
dynamic_cast<const T*
>(rf);
691 Throw<std::runtime_error>(
"Wrong field type");
701 template <
typename T,
typename V>
715 const T* cf =
dynamic_cast<const T*
>(rf);
718 Throw<std::runtime_error>(
"Wrong field type");
724 template <
typename T,
typename V>
738 T* cf =
dynamic_cast<T*
>(rf);
741 Throw<std::runtime_error>(
"Wrong field type");
743 cf->setValue(std::move(
value));
747 template <
typename T>
759 T* cf =
dynamic_cast<T*
>(rf);
762 Throw<std::runtime_error>(
"Wrong field type");
768 template <
typename T>
780 T* cf =
dynamic_cast<T*
>(rf);
783 Throw<std::runtime_error>(
"Wrong field type");
798 Throw<STObject::FieldErr>(
799 "Template field error '" + this->
f_->getName() +
"'");
812 auto const t = find();
816 Throw<STObject::FieldErr>(
817 "Missing field '" + this->f_->getName() +
"'");
825 return dynamic_cast<T const*
>(st_->peekAtPField(*f_));
835 st_->makeFieldAbsent(*f_);
840 t =
dynamic_cast<T*
>(st_->getPField(*f_,
true));
842 t =
dynamic_cast<T*
>(st_->makeFieldPresent(*f_));
844 *t = std::forward<U>(u);
854 this->assign(std::forward<U>(u));
861 return this->value();
882 return this->value();
887 T>::optional_type()
const
889 return optional_value();
896 return optional_value();
912 this->assign(std::move(*v));
934 this->assign(std::forward<U>(u));
948 return this->style_ ==
soeDEFAULT || this->find() !=
nullptr;
956 Throw<STObject::FieldErr>(
957 "Template field error '" + this->f_->getName() +
"'");
959 this->st_->delField(*this->f_);
961 this->st_->makeFieldAbsent(*this->f_);
970 return this->value();
976 typename T::value_type
983 boost::optional<std::decay_t<typename T::value_type>>
1004 typename T::value_type
1011 Throw<STObject::FieldErr>(
"Missing field '" + f.
getName() +
"'");
1012 auto const u =
dynamic_cast<T const*
>(b);
1018 Throw<STObject::FieldErr>(
"Missing field '" + f.
getName() +
"'");
1030 boost::optional<std::decay_t<typename T::value_type>>
1036 auto const u =
dynamic_cast<T const*
>(b);
1044 return typename T::value_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
STBase & getIndex(int offset)
typename T::value_type value_type
static std::vector< STBase const * > getSortedFields(STObject const &objToSort, WhichFields whichFields)
void setAccountID(SField const &field, AccountID const &)
bool engaged() const noexcept
const STArray & getFieldArray(SField const &field) const
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.
friend bool operator!=(OptionalProxy const &lhs, boost::none_t) noexcept
void setFieldV256(SField const &field, STVector256 const &v)
std::uint64_t getFieldU64(SField const &field) const
An immutable linear range of bytes.
const STVector256 & getFieldV256(SField const &field) const
friend bool operator!=(OptionalProxy const &lhs, optional_type const &rhs) noexcept
typename T::value_type value_type
unsigned char getFieldU8(SField const &field) const
STBase * copy(std::size_t n, void *buf) const override
Serializer getSerializer() const
uint128 getFieldH128(SField const &field) const
Indicate boost::optional field semantics.
OptionalProxy & operator=(OptionalProxy const &)=delete
void setFieldVL(SField const &field, Blob const &)
Blob getFieldVL(SField const &field) const
friend bool operator==(boost::none_t, OptionalProxy const &rhs) noexcept
void setValue(base_uint< Bits, Tag > const &v)
virtual ~STObject()=default
const STBase * peekAtPIndex(int offset) const
uint160 getFieldH160(SField const &field) const
const STBase & peekAtIndex(int offset) const
virtual std::string getFullText() const override
virtual bool isEquivalent(const STBase &t) const override
static STBase * emplace(std::size_t n, void *buf, T &&val)
Integers of any length that is a multiple of 32-bits.
void setFieldH160(SField const &field, base_uint< 160, Tag > const &v)
friend bool operator!=(optional_type const &lhs, OptionalProxy const &rhs) noexcept
virtual SerializedTypeID getSType() const override
OptionalProxy(OptionalProxy const &)=default
bool delField(SField const &field)
T & peekField(SField const &field)
typename T::value_type value_type
friend bool operator==(OptionalProxy const &lhs, boost::none_t) noexcept
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
void applyTemplate(const SOTemplate &type) noexcept(false)
HashPrefix
Prefix for hashing functions.
TypedField< T > const * f_
void setFieldU8(SField const &field, unsigned char)
STArray & peekFieldArray(SField const &field)
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)
virtual bool isDefault() const override
std::uint32_t getFlags() const
friend bool operator!=(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
void addWithoutSigningFields(Serializer &s) const
boost::optional< typename std::decay< value_type >::type > optional_type
void reserve(std::size_t n)
std::uint16_t getFieldU16(SField const &field) const
void setFieldUsingAssignment(SField const &field, T const &value)
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 applyTemplateFromSField(SField const &) noexcept(false)
STBase * move(std::size_t n, void *buf) override
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
STObject & peekFieldObject(SField const &field)
uint256 getSigningHash(HashPrefix prefix) const
const STBase * peekAtPField(SField const &field) const
virtual void add(Serializer &s) const override
A type which can be exported to a well known binary format.
STBase & getField(SField const &field)
std::string const & getName() const
bool isFieldPresent(SField const &field) const
STBase * getPIndex(int offset)
friend bool operator==(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
optional_type operator~() const
Explicit conversion to boost::optional.
Proxy(Proxy const &)=default
V const & getFieldByConstRef(SField const &field, V const &empty) const
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!=(boost::none_t, OptionalProxy const &rhs) noexcept
TypedField< T > const * f
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
void setFieldU64(SField const &field, std::uint64_t)
virtual 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
ValueProxy & operator=(ValueProxy const &)=delete
uint256 getHash(HashPrefix prefix) const
virtual std::string getText() const override
uint256 getFieldH256(SField const &field) const
value_type value_or(value_type val) const