20 #ifndef RIPPLE_PROTOCOL_STOBJECT_H_INCLUDED
21 #define RIPPLE_PROTOCOL_STOBJECT_H_INCLUDED
23 #include <ripple/basics/chrono.h>
24 #include <ripple/basics/contract.h>
25 #include <ripple/basics/CountedObject.h>
26 #include <ripple/basics/FeeUnits.h>
27 #include <ripple/basics/Slice.h>
28 #include <ripple/protocol/HashPrefix.h>
29 #include <ripple/protocol/STAmount.h>
30 #include <ripple/protocol/STPathSet.h>
31 #include <ripple/protocol/STVector256.h>
32 #include <ripple/protocol/SOTemplate.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());
62 typename T::value_type;
71 T
const*
find()
const;
82 typename T::value_type;
90 std::is_assignable_v<T, U>,
107 typename T::value_type;
121 explicit operator bool() const noexcept;
137 friend
bool operator==(
139 boost::none_t) noexcept
148 return rhs == boost::none;
173 if (lhs.engaged() != rhs.engaged())
175 return ! lhs.engaged() || *lhs == *rhs;
180 boost::none_t) noexcept
182 return ! (lhs == boost::none);
188 return ! (rhs == boost::none);
195 return ! (lhs == rhs);
202 return ! (lhs == rhs);
209 return ! (lhs == rhs);
218 std::is_assignable_v<T, U>,
261 using iterator = boost::transform_iterator<
277 SField const& name,
int depth = 0) noexcept (false);
298 return emplace(n, buf, std::move(*
this));
327 return mType ==
nullptr;
369 template <
class... Args>
392 return v_[offset].get();
396 return v_[offset].get();
400 return &
v_[offset].get();
404 return &
v_[offset].get();
441 typename T::value_type
449 boost::optional<std::decay_t<typename T::value_type>>
506 if (
auto cf =
dynamic_cast<Bits*
> (rf))
509 Throw<std::runtime_error> (
"Wrong field type");
526 return ! (*
this == o);
552 template <
typename T,
typename V =
554 decltype (std::declval <T> ().
value ())>::type >::type >
567 const T* cf =
dynamic_cast<const T*
> (rf);
570 Throw<std::runtime_error> (
"Wrong field type");
580 template <
typename T,
typename V>
593 const T* cf =
dynamic_cast<const T*
> (rf);
596 Throw<std::runtime_error> (
"Wrong field type");
602 template <
typename T,
typename V>
615 T* cf =
dynamic_cast<T*
> (rf);
618 Throw<std::runtime_error> (
"Wrong field type");
620 cf->setValue (std::move (
value));
624 template <
typename T>
635 T* cf =
dynamic_cast<T*
> (rf);
638 Throw<std::runtime_error> (
"Wrong field type");
644 template <
typename T>
655 T* cf =
dynamic_cast<T*
> (rf);
658 Throw<std::runtime_error> (
"Wrong field type");
675 Throw<STObject::FieldErr> (
676 "Template field error '" + this->
f_->getName() +
"'");
690 auto const t = find();
694 Throw<STObject::FieldErr> (
695 "Missing field '" + this->f_->getName() +
"'");
704 return dynamic_cast<T const*
>(
705 st_->peekAtPField(*f_));
716 st_->makeFieldAbsent(*f_);
721 t =
dynamic_cast<T*
>(
722 st_->getPField(*f_,
true));
724 t =
dynamic_cast<T*
>(
725 st_->makeFieldPresent(*f_));
727 *t = std::forward<U>(u);
735 std::is_assignable_v<T, U>,
739 this->assign(std::forward<U>(u));
746 return this->value();
769 return this->value();
776 return optional_value();
783 return optional_value();
801 this->assign(std::move(*v));
822 std::is_assignable_v<T, U>,
826 this->assign(std::forward<U>(u));
842 || this->find() !=
nullptr;
851 Throw<STObject::FieldErr> (
852 "Template field error '" + this->f_->getName() +
"'");
854 this->st_->delField(*this->f_);
856 this->st_->makeFieldAbsent(*this->f_);
866 return this->value();
872 typename T::value_type
879 Throw<STObject::FieldErr> (
880 "Missing field '" + f.
getName() +
"'");
882 dynamic_cast<T const*
>(b);
888 Throw<STObject::FieldErr> (
889 "Missing field '" + f.
getName() +
"'");
895 typename T::value_type>
const dv{};
902 boost::optional<std::decay_t<typename T::value_type>>
909 dynamic_cast<T const*
>(b);
917 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)
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)
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)
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)
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)
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 &)
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)
boost::transform_iterator< Transform, STObject::list_type::const_iterator > iterator
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
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 &)
static char const * getCountedObjectName()
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
boost::optional< typename std::decay< value_type >::type > optional_type
optional_type optional_value() const
T::value_type operator[](TypedField< T > const &f) const
Return 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