rippled
Loading...
Searching...
No Matches
STObject.h
1#ifndef XRPL_PROTOCOL_STOBJECT_H_INCLUDED
2#define XRPL_PROTOCOL_STOBJECT_H_INCLUDED
3
4#include <xrpl/basics/CountedObject.h>
5#include <xrpl/basics/Slice.h>
6#include <xrpl/basics/chrono.h>
7#include <xrpl/basics/contract.h>
8#include <xrpl/beast/utility/instrumentation.h>
9#include <xrpl/protocol/HashPrefix.h>
10#include <xrpl/protocol/SOTemplate.h>
11#include <xrpl/protocol/STAmount.h>
12#include <xrpl/protocol/STBase.h>
13#include <xrpl/protocol/STCurrency.h>
14#include <xrpl/protocol/STIssue.h>
15#include <xrpl/protocol/STPathSet.h>
16#include <xrpl/protocol/STVector256.h>
17#include <xrpl/protocol/Units.h>
18#include <xrpl/protocol/detail/STVar.h>
19
20#include <boost/iterator/transform_iterator.hpp>
21
22#include <optional>
23#include <stdexcept>
24#include <type_traits>
25#include <utility>
26
27namespace xrpl {
28
29class STArray;
30
31inline void
33{
34 Throw<std::runtime_error>("Field not found: " + field.getName());
35}
36
37class STObject : public STBase, public CountedObject<STObject>
38{
39 // Proxy value for a STBase derived class
40 template <class T>
41 class Proxy;
42 template <class T>
43 class ValueProxy;
44 template <class T>
45 class OptionalProxy;
46
47 struct Transform
48 {
49 explicit Transform() = default;
50
53
54 STBase const&
55 operator()(detail::STVar const& e) const;
56 };
57
59
62
63public:
64 using iterator = boost::
65 transform_iterator<Transform, STObject::list_type::const_iterator>;
66
67 virtual ~STObject() = default;
68 STObject(STObject const&) = default;
69
70 template <typename F>
71 STObject(SOTemplate const& type, SField const& name, F&& f)
72 : STObject(type, name)
73 {
74 f(*this);
75 }
76
78 operator=(STObject const&) = default;
81 operator=(STObject&& other);
82
83 STObject(SOTemplate const& type, SField const& name);
84 STObject(SOTemplate const& type, SerialIter& sit, SField const& name);
85 STObject(SerialIter& sit, SField const& name, int depth = 0);
86 STObject(SerialIter&& sit, SField const& name);
87 explicit STObject(SField const& name);
88
89 static STObject
90 makeInnerObject(SField const& name);
91
93 begin() const;
94
96 end() const;
97
98 bool
99 empty() const;
100
101 void
103
104 void
105 applyTemplate(SOTemplate const& type);
106
107 void
109
110 bool
111 isFree() const;
112
113 void
114 set(SOTemplate const&);
115
116 bool
117 set(SerialIter& u, int depth = 0);
118
120 getSType() const override;
121
122 bool
123 isEquivalent(STBase const& t) const override;
124
125 bool
126 isDefault() const override;
127
128 void
129 add(Serializer& s) const override;
130
132 getFullText() const override;
133
135 getText() const override;
136
137 // TODO(tom): options should be an enum.
139
140 void
142
144 getSerializer() const;
145
146 template <class... Args>
148 emplace_back(Args&&... args);
149
150 int
151 getCount() const;
152
155 bool isFlag(std::uint32_t) const;
156
158 getFlags() const;
159
160 uint256
161 getHash(HashPrefix prefix) const;
162
163 uint256
164 getSigningHash(HashPrefix prefix) const;
165
166 STBase const&
167 peekAtIndex(int offset) const;
168
169 STBase&
170 getIndex(int offset);
171
172 STBase const*
173 peekAtPIndex(int offset) const;
174
175 STBase*
176 getPIndex(int offset);
177
178 int
179 getFieldIndex(SField const& field) const;
180
181 SField const&
182 getFieldSType(int index) const;
183
184 STBase const&
185 peekAtField(SField const& field) const;
186
187 STBase&
188 getField(SField const& field);
189
190 STBase const*
191 peekAtPField(SField const& field) const;
192
193 STBase*
194 getPField(SField const& field, bool createOkay = false);
195
196 // these throw if the field type doesn't match, or return default values
197 // if the field is optional but not present
198 unsigned char
199 getFieldU8(SField const& field) const;
201 getFieldU16(SField const& field) const;
203 getFieldU32(SField const& field) const;
205 getFieldU64(SField const& field) const;
206 uint128
207 getFieldH128(SField const& field) const;
208
209 uint160
210 getFieldH160(SField const& field) const;
211 uint192
212 getFieldH192(SField const& field) const;
213 uint256
214 getFieldH256(SField const& field) const;
216 getFieldI32(SField const& field) const;
218 getAccountID(SField const& field) const;
219
220 Blob
221 getFieldVL(SField const& field) const;
222 STAmount const&
223 getFieldAmount(SField const& field) const;
224 STPathSet const&
225 getFieldPathSet(SField const& field) const;
226 STVector256 const&
227 getFieldV256(SField const& field) const;
228 // If not found, returns an object constructed with the given field
230 getFieldObject(SField const& field) const;
231 STArray const&
232 getFieldArray(SField const& field) const;
233 STCurrency const&
234 getFieldCurrency(SField const& field) const;
235 STNumber const&
236 getFieldNumber(SField const& field) const;
237
245 template <class T>
246 typename T::value_type
247 operator[](TypedField<T> const& f) const;
248
257 template <class T>
259 operator[](OptionaledField<T> const& of) const;
260
268 template <class T>
271
281 template <class T>
284
292 template <class T>
293 typename T::value_type
294 at(TypedField<T> const& f) const;
295
304 template <class T>
306 at(OptionaledField<T> const& of) const;
307
315 template <class T>
317 at(TypedField<T> const& f);
318
328 template <class T>
331
335 void
337
338 void
339 set(STBase&& v);
340
341 void
342 setFieldU8(SField const& field, unsigned char);
343 void
344 setFieldU16(SField const& field, std::uint16_t);
345 void
346 setFieldU32(SField const& field, std::uint32_t);
347 void
348 setFieldU64(SField const& field, std::uint64_t);
349 void
350 setFieldH128(SField const& field, uint128 const&);
351 void
352 setFieldH256(SField const& field, uint256 const&);
353 void
354 setFieldI32(SField const& field, std::int32_t);
355 void
356 setFieldVL(SField const& field, Blob const&);
357 void
358 setFieldVL(SField const& field, Slice const&);
359
360 void
361 setAccountID(SField const& field, AccountID const&);
362
363 void
364 setFieldAmount(SField const& field, STAmount const&);
365 void
366 setFieldIssue(SField const& field, STIssue const&);
367 void
368 setFieldCurrency(SField const& field, STCurrency const&);
369 void
370 setFieldNumber(SField const& field, STNumber const&);
371 void
372 setFieldPathSet(SField const& field, STPathSet const&);
373 void
374 setFieldV256(SField const& field, STVector256 const& v);
375 void
376 setFieldArray(SField const& field, STArray const& v);
377 void
378 setFieldObject(SField const& field, STObject const& v);
379
380 template <class Tag>
381 void
382 setFieldH160(SField const& field, base_uint<160, Tag> const& v);
383
384 STObject&
385 peekFieldObject(SField const& field);
386 STArray&
387 peekFieldArray(SField const& field);
388
389 bool
390 isFieldPresent(SField const& field) const;
391 STBase*
392 makeFieldPresent(SField const& field);
393 void
394 makeFieldAbsent(SField const& field);
395 bool
396 delField(SField const& field);
397 void
398 delField(int index);
399
400 bool
401 hasMatchingEntry(STBase const&);
402
403 bool
404 operator==(STObject const& o) const;
405 bool
406 operator!=(STObject const& o) const;
407
408 class FieldErr;
409
410private:
411 enum WhichFields : bool {
412 // These values are carefully chosen to do the right thing if passed
413 // to SField::shouldInclude (bool)
415 withAllFields = true
416 };
417
418 void
419 add(Serializer& s, WhichFields whichFields) const;
420
421 // Sort the entries in an STObject into the order that they will be
422 // serialized. Note: they are not sorted into pointer value order, they
423 // are sorted by SField::fieldCode.
425 getSortedFields(STObject const& objToSort, WhichFields whichFields);
426
427 // Implementation for getting (most) fields that return by value.
428 //
429 // The remove_cv and remove_reference are necessitated by the STBitString
430 // types. Their value() returns by const ref. We return those types
431 // by value.
432 template <
433 typename T,
434 typename V = typename std::remove_cv<typename std::remove_reference<
435 decltype(std::declval<T>().value())>::type>::type>
436 V
437 getFieldByValue(SField const& field) const;
438
439 // Implementations for getting (most) fields that return by const reference.
440 //
441 // If an absent optional field is deserialized we don't have anything
442 // obvious to return. So we insist on having the call provide an
443 // 'empty' value we return in that circumstance.
444 template <typename T, typename V>
445 V const&
446 getFieldByConstRef(SField const& field, V const& empty) const;
447
448 // Implementation for setting most fields with a setValue() method.
449 template <typename T, typename V>
450 void
451 setFieldUsingSetValue(SField const& field, V value);
452
453 // Implementation for setting fields using assignment
454 template <typename T>
455 void
456 setFieldUsingAssignment(SField const& field, T const& value);
457
458 // Implementation for peeking STObjects and STArrays
459 template <typename T>
460 T&
461 peekField(SField const& field);
462
463 STBase*
464 copy(std::size_t n, void* buf) const override;
465 STBase*
466 move(std::size_t n, void* buf) override;
467
468 friend class detail::STVar;
469};
470
471//------------------------------------------------------------------------------
472
473template <class T>
475{
476public:
477 using value_type = typename T::value_type;
478
480 value() const;
481
483 operator*() const;
484
487 T const*
488 operator->() const;
489
490protected:
494
495 Proxy(Proxy const&) = default;
496
497 Proxy(STObject* st, TypedField<T> const* f);
498
499 T const*
500 find() const;
501
502 template <class U>
503 void
504 assign(U&& u);
505};
506
507// Constraint += and -= ValueProxy operators
508// to value types that support arithmetic operations
509template <typename U>
512template <
513 typename U,
514 typename Value = typename U::value_type,
515 typename Unit = typename U::unit_type>
519template <typename U, typename Value = typename U::value_type>
521template <typename U>
524
525template <class T, class U>
526concept Addable = requires(T t, U u) { t = t + u; };
527template <typename T, typename U>
530
531template <class T>
533{
534private:
535 using value_type = typename T::value_type;
536
537public:
538 ValueProxy(ValueProxy const&) = default;
540 operator=(ValueProxy const&) = delete;
541
542 template <class U>
544 operator=(U&& u);
545
546 // Convenience operators for value types supporting
547 // arithmetic operations
548 template <IsArithmetic U>
551 operator+=(U const& u);
552
553 template <IsArithmetic U>
556 operator-=(U const& u);
557
558 operator value_type() const;
559
560 template <typename U>
561 friend bool
562 operator==(U const& lhs, STObject::ValueProxy<T> const& rhs)
563 {
564 return rhs.value() == lhs;
565 }
566
567private:
568 friend class STObject;
569
570 ValueProxy(STObject* st, TypedField<T> const* f);
571};
572
573template <class T>
575{
576private:
577 using value_type = typename T::value_type;
578
580
581public:
582 OptionalProxy(OptionalProxy const&) = default;
584 operator=(OptionalProxy const&) = delete;
585
591 explicit
592 operator bool() const noexcept;
593
594 operator optional_type() const;
595
598 operator~() const;
599
600 friend bool
601 operator==(OptionalProxy const& lhs, std::nullopt_t) noexcept
602 {
603 return !lhs.engaged();
604 }
605
606 friend bool
608 {
609 return rhs == std::nullopt;
610 }
611
612 friend bool
613 operator==(OptionalProxy const& lhs, optional_type const& rhs) noexcept
614 {
615 if (!lhs.engaged())
616 return !rhs;
617 if (!rhs)
618 return false;
619 return *lhs == *rhs;
620 }
621
622 friend bool
623 operator==(optional_type const& lhs, OptionalProxy const& rhs) noexcept
624 {
625 return rhs == lhs;
626 }
627
628 friend bool
629 operator==(OptionalProxy const& lhs, OptionalProxy const& rhs) noexcept
630 {
631 if (lhs.engaged() != rhs.engaged())
632 return false;
633 return !lhs.engaged() || *lhs == *rhs;
634 }
635
636 friend bool
638 {
639 return !(lhs == std::nullopt);
640 }
641
642 friend bool
644 {
645 return !(rhs == std::nullopt);
646 }
647
648 friend bool
649 operator!=(OptionalProxy const& lhs, optional_type const& rhs) noexcept
650 {
651 return !(lhs == rhs);
652 }
653
654 friend bool
655 operator!=(optional_type const& lhs, OptionalProxy const& rhs) noexcept
656 {
657 return !(lhs == rhs);
658 }
659
660 friend bool
661 operator!=(OptionalProxy const& lhs, OptionalProxy const& rhs) noexcept
662 {
663 return !(lhs == rhs);
664 }
665
666 // Emulate std::optional::value_or
668 value_or(value_type val) const;
669
675 operator=(optional_type const& v);
676
677 template <class U>
679 operator=(U&& u);
680
681private:
682 friend class STObject;
683
684 OptionalProxy(STObject* st, TypedField<T> const* f);
685
686 bool
687 engaged() const noexcept;
688
689 void
690 disengage();
691
693 optional_value() const;
694};
695
696class STObject::FieldErr : public std::runtime_error
697{
699};
700
701template <class T>
703{
704 if (st_->mType)
705 {
706 // STObject has associated template
707 if (!st_->peekAtPField(*f_))
708 Throw<STObject::FieldErr>(
709 "Template field error '" + this->f_->getName() + "'");
710 style_ = st_->mType->style(*f_);
711 }
712 else
713 {
715 }
716}
717
718template <class T>
719auto
721{
722 auto const t = find();
723 if (t)
724 return t->value();
725 if (style_ == soeINVALID)
726 {
727 Throw<STObject::FieldErr>("Value requested from invalid STObject.");
728 }
729 if (style_ != soeDEFAULT)
730 {
731 Throw<STObject::FieldErr>(
732 "Missing field '" + this->f_->getName() + "'");
733 }
734 return value_type{};
735}
736
737template <class T>
738auto
740{
741 return this->value();
742}
743
746template <class T>
747T const*
749{
750 return this->find();
751}
752
753template <class T>
754inline T const*
756{
757 return dynamic_cast<T const*>(st_->peekAtPField(*f_));
758}
759
760template <class T>
761template <class U>
762void
764{
765 if (style_ == soeDEFAULT && u == value_type{})
766 {
767 st_->makeFieldAbsent(*f_);
768 return;
769 }
770 T* t;
771 if (style_ == soeINVALID)
772 t = dynamic_cast<T*>(st_->getPField(*f_, true));
773 else
774 t = dynamic_cast<T*>(st_->makeFieldPresent(*f_));
775 XRPL_ASSERT(t, "xrpl::STObject::Proxy::assign : type cast succeeded");
776 *t = std::forward<U>(u);
777}
778
779//------------------------------------------------------------------------------
780
781template <class T>
782template <class U>
785{
786 this->assign(std::forward<U>(u));
787 return *this;
788}
789
790template <typename T>
791template <IsArithmetic U>
795{
796 this->assign(this->value() + u);
797 return *this;
798}
799
800template <class T>
801template <IsArithmetic U>
805{
806 this->assign(this->value() - u);
807 return *this;
808}
809
810template <class T>
812{
813 return this->value();
814}
815
816template <class T>
818 : Proxy<T>(st, f)
819{
820}
821
822//------------------------------------------------------------------------------
823
824template <class T>
826{
827 return engaged();
828}
829
830template <class T>
832 T>::optional_type() const
833{
834 return optional_value();
835}
836
837template <class T>
840{
841 return optional_value();
842}
843
844template <class T>
845auto
847{
848 disengage();
849 return *this;
850}
851
852template <class T>
853auto
855{
856 if (v)
857 this->assign(std::move(*v));
858 else
859 disengage();
860 return *this;
861}
862
863template <class T>
864auto
866{
867 if (v)
868 this->assign(*v);
869 else
870 disengage();
871 return *this;
872}
873
874template <class T>
875template <class U>
878{
879 this->assign(std::forward<U>(u));
880 return *this;
881}
882
883template <class T>
888
889template <class T>
890bool
892{
893 return this->style_ == soeDEFAULT || this->find() != nullptr;
894}
895
896template <class T>
897void
899{
900 if (this->style_ == soeREQUIRED || this->style_ == soeDEFAULT)
901 Throw<STObject::FieldErr>(
902 "Template field error '" + this->f_->getName() + "'");
903 if (this->style_ == soeINVALID)
904 this->st_->delField(*this->f_);
905 else
906 this->st_->makeFieldAbsent(*this->f_);
907}
908
909template <class T>
910auto
912{
913 if (!engaged())
914 return std::nullopt;
915 return this->value();
916}
917
918template <class T>
921{
922 return engaged() ? this->value() : val;
923}
924
925//------------------------------------------------------------------------------
926
927inline STBase const&
929{
930 return e.get();
931}
932
933//------------------------------------------------------------------------------
934
935inline STObject::STObject(SerialIter&& sit, SField const& name)
936 : STObject(sit, name)
937{
938}
939
942{
943 return iterator(v_.begin());
944}
945
948{
949 return iterator(v_.end());
950}
951
952inline bool
954{
955 return v_.empty();
956}
957
958inline void
963
964inline bool
966{
967 return mType == nullptr;
968}
969
970inline void
975
976// VFALCO NOTE does this return an expensive copy of an object with a
977// dynamic buffer?
978// VFALCO TODO Remove this function and fix the few callers.
979inline Serializer
981{
982 Serializer s;
983 add(s, withAllFields);
984 return s;
985}
986
987template <class... Args>
988inline std::size_t
990{
992 return v_.size() - 1;
993}
994
995inline int
997{
998 return v_.size();
999}
1000
1001inline STBase const&
1002STObject::peekAtIndex(int offset) const
1003{
1004 return v_[offset].get();
1005}
1006
1007inline STBase&
1009{
1010 return v_[offset].get();
1011}
1012
1013inline STBase const*
1014STObject::peekAtPIndex(int offset) const
1015{
1016 return &v_[offset].get();
1017}
1018
1019inline STBase*
1021{
1022 return &v_[offset].get();
1023}
1024
1025template <class T>
1026typename T::value_type
1028{
1029 return at(f);
1030}
1031
1032template <class T>
1035{
1036 return at(of);
1037}
1038
1039template <class T>
1040inline auto
1042{
1043 return at(f);
1044}
1045
1046template <class T>
1047inline auto
1049{
1050 return at(of);
1051}
1052
1053template <class T>
1054typename T::value_type
1056{
1057 auto const b = peekAtPField(f);
1058 if (!b)
1059 // This is a free object (no constraints)
1060 // with no template
1061 Throw<STObject::FieldErr>("Missing field: " + f.getName());
1062
1063 if (auto const u = dynamic_cast<T const*>(b))
1064 return u->value();
1065
1066 XRPL_ASSERT(
1067 mType, "xrpl::STObject::at(TypedField auto) : field template non-null");
1068 XRPL_ASSERT(
1069 b->getSType() == STI_NOTPRESENT,
1070 "xrpl::STObject::at(TypedField auto) : type not present");
1071
1072 if (mType->style(f) == soeOPTIONAL)
1073 Throw<STObject::FieldErr>("Missing optional field: " + f.getName());
1074
1075 XRPL_ASSERT(
1076 mType->style(f) == soeDEFAULT,
1077 "xrpl::STObject::at(TypedField auto) : template style is default");
1078
1079 // Used to help handle the case where value_type is a const reference,
1080 // otherwise we would return the address of a temporary.
1081 static std::decay_t<typename T::value_type> const dv{};
1082 return dv;
1083}
1084
1085template <class T>
1088{
1089 auto const b = peekAtPField(*of.f);
1090 if (!b)
1091 return std::nullopt;
1092 auto const u = dynamic_cast<T const*>(b);
1093 if (!u)
1094 {
1095 XRPL_ASSERT(
1096 mType,
1097 "xrpl::STObject::at(OptionaledField auto) : field template "
1098 "non-null");
1099 XRPL_ASSERT(
1100 b->getSType() == STI_NOTPRESENT,
1101 "xrpl::STObject::at(OptionaledField auto) : type not present");
1102 if (mType->style(*of.f) == soeOPTIONAL)
1103 return std::nullopt;
1104 XRPL_ASSERT(
1105 mType->style(*of.f) == soeDEFAULT,
1106 "xrpl::STObject::at(OptionaledField auto) : template style is "
1107 "default");
1108 return typename T::value_type{};
1109 }
1110 return u->value();
1111}
1112
1113template <class T>
1114inline auto
1116{
1117 return ValueProxy<T>(this, &f);
1118}
1119
1120template <class T>
1121inline auto
1123{
1124 return OptionalProxy<T>(this, of.f);
1125}
1126
1127template <class Tag>
1128void
1130{
1131 STBase* rf = getPField(field, true);
1132
1133 if (!rf)
1134 throwFieldNotFound(field);
1135
1136 if (rf->getSType() == STI_NOTPRESENT)
1137 rf = makeFieldPresent(field);
1138
1139 using Bits = STBitString<160>;
1140 if (auto cf = dynamic_cast<Bits*>(rf))
1141 cf->setValue(v);
1142 else
1143 Throw<std::runtime_error>("Wrong field type");
1144}
1145
1146inline bool
1148{
1149 return !(*this == o);
1150}
1151
1152template <typename T, typename V>
1153V
1155{
1156 STBase const* rf = peekAtPField(field);
1157
1158 if (!rf)
1159 throwFieldNotFound(field);
1160
1161 SerializedTypeID id = rf->getSType();
1162
1163 if (id == STI_NOTPRESENT)
1164 return V(); // optional field not present
1165
1166 T const* cf = dynamic_cast<T const*>(rf);
1167
1168 if (!cf)
1169 Throw<std::runtime_error>("Wrong field type");
1170
1171 return cf->value();
1172}
1173
1174// Implementations for getting (most) fields that return by const reference.
1175//
1176// If an absent optional field is deserialized we don't have anything
1177// obvious to return. So we insist on having the call provide an
1178// 'empty' value we return in that circumstance.
1179template <typename T, typename V>
1180V const&
1181STObject::getFieldByConstRef(SField const& field, V const& empty) const
1182{
1183 STBase const* rf = peekAtPField(field);
1184
1185 if (!rf)
1186 throwFieldNotFound(field);
1187
1188 SerializedTypeID id = rf->getSType();
1189
1190 if (id == STI_NOTPRESENT)
1191 return empty; // optional field not present
1192
1193 T const* cf = dynamic_cast<T const*>(rf);
1194
1195 if (!cf)
1196 Throw<std::runtime_error>("Wrong field type");
1197
1198 return *cf;
1199}
1200
1201// Implementation for setting most fields with a setValue() method.
1202template <typename T, typename V>
1203void
1205{
1206 static_assert(!std::is_lvalue_reference<V>::value, "");
1207
1208 STBase* rf = getPField(field, true);
1209
1210 if (!rf)
1211 throwFieldNotFound(field);
1212
1213 if (rf->getSType() == STI_NOTPRESENT)
1214 rf = makeFieldPresent(field);
1215
1216 T* cf = dynamic_cast<T*>(rf);
1217
1218 if (!cf)
1219 Throw<std::runtime_error>("Wrong field type");
1220
1221 cf->setValue(std::move(value));
1222}
1223
1224// Implementation for setting fields using assignment
1225template <typename T>
1226void
1227STObject::setFieldUsingAssignment(SField const& field, T const& value)
1228{
1229 STBase* rf = getPField(field, true);
1230
1231 if (!rf)
1232 throwFieldNotFound(field);
1233
1234 if (rf->getSType() == STI_NOTPRESENT)
1235 rf = makeFieldPresent(field);
1236
1237 T* cf = dynamic_cast<T*>(rf);
1238
1239 if (!cf)
1240 Throw<std::runtime_error>("Wrong field type");
1241
1242 (*cf) = value;
1243}
1244
1245// Implementation for peeking STObjects and STArrays
1246template <typename T>
1247T&
1249{
1250 STBase* rf = getPField(field, true);
1251
1252 if (!rf)
1253 throwFieldNotFound(field);
1254
1255 if (rf->getSType() == STI_NOTPRESENT)
1256 rf = makeFieldPresent(field);
1257
1258 T* cf = dynamic_cast<T*>(rf);
1259
1260 if (!cf)
1261 Throw<std::runtime_error>("Wrong field type");
1262
1263 return *cf;
1264}
1265
1266} // namespace xrpl
1267
1268#endif
T begin(T... args)
Represents a JSON value.
Definition json_value.h:131
Tracks the number of instances of an object.
Identifies fields.
Definition SField.h:127
std::string const & getName() const
Definition SField.h:192
Defines the fields and their attributes within a STObject.
Definition SOTemplate.h:94
SOEStyle style(SField const &sf) const
Definition SOTemplate.h:147
A type which can be exported to a well known binary format.
Definition STBase.h:116
virtual SerializedTypeID getSType() const
Definition STBase.cpp:56
void setValue(base_uint< Bits, Tag > const &v)
A serializable number.
Definition STNumber.h:24
friend bool operator!=(OptionalProxy const &lhs, optional_type const &rhs) noexcept
Definition STObject.h:649
friend bool operator==(OptionalProxy const &lhs, optional_type const &rhs) noexcept
Definition STObject.h:613
friend bool operator==(optional_type const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:623
friend bool operator==(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:629
std::enable_if_t< std::is_assignable_v< T, U >, OptionalProxy & > operator=(U &&u)
OptionalProxy(OptionalProxy const &)=default
optional_type operator~() const
Explicit conversion to std::optional.
Definition STObject.h:839
std::optional< typename std::decay< value_type >::type > optional_type
Definition STObject.h:579
typename T::value_type value_type
Definition STObject.h:577
friend bool operator!=(OptionalProxy const &lhs, std::nullopt_t) noexcept
Definition STObject.h:637
friend bool operator!=(std::nullopt_t, OptionalProxy const &rhs) noexcept
Definition STObject.h:643
OptionalProxy & operator=(OptionalProxy const &)=delete
bool engaged() const noexcept
Definition STObject.h:891
friend bool operator!=(optional_type const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:655
friend bool operator==(std::nullopt_t, OptionalProxy const &rhs) noexcept
Definition STObject.h:607
value_type value_or(value_type val) const
Definition STObject.h:920
optional_type optional_value() const
Definition STObject.h:911
friend bool operator!=(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:661
void assign(U &&u)
Definition STObject.h:763
Proxy(Proxy const &)=default
value_type operator*() const
Definition STObject.h:739
T const * operator->() const
Do not use operator->() unless the field is required, or you've checked that it's set.
Definition STObject.h:748
value_type value() const
Definition STObject.h:720
T const * find() const
Definition STObject.h:755
typename T::value_type value_type
Definition STObject.h:477
TypedField< T > const * f_
Definition STObject.h:493
ValueProxy(ValueProxy const &)=default
ValueProxy & operator=(ValueProxy const &)=delete
typename T::value_type value_type
Definition STObject.h:535
ValueProxy & operator+=(U const &u)
ValueProxy & operator-=(U const &u)
friend bool operator==(U const &lhs, STObject::ValueProxy< T > const &rhs)
Definition STObject.h:562
std::enable_if_t< std::is_assignable_v< T, U >, ValueProxy & > operator=(U &&u)
void setFieldU8(SField const &field, unsigned char)
Definition STObject.cpp:726
SField const & getFieldSType(int index) const
Definition STObject.cpp:432
uint192 getFieldH192(SField const &field) const
Definition STObject.cpp:620
bool isFree() const
Definition STObject.h:965
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1055
STBase const * peekAtPIndex(int offset) const
Definition STObject.h:1014
Json::Value getJson(JsonOptions=JsonOptions::none) const override
Definition STObject.cpp:834
STCurrency const & getFieldCurrency(SField const &field) const
Definition STObject.cpp:690
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:644
void addWithoutSigningFields(Serializer &s) const
Definition STObject.h:971
void setFieldIssue(SField const &field, STIssue const &)
Definition STObject.cpp:804
uint128 getFieldH128(SField const &field) const
Definition STObject.cpp:608
iterator begin() const
Definition STObject.h:941
bool operator==(STObject const &o) const
Definition STObject.cpp:847
bool isEquivalent(STBase const &t) const override
Definition STObject.cpp:341
bool empty() const
Definition STObject.h:953
void setFieldNumber(SField const &field, STNumber const &)
Definition STObject.cpp:810
void setFieldV256(SField const &field, STVector256 const &v)
Definition STObject.cpp:768
void setFieldU64(SField const &field, std::uint64_t)
Definition STObject.cpp:744
unsigned char getFieldU8(SField const &field) const
Definition STObject.cpp:584
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:596
STBase const & peekAtIndex(int offset) const
Definition STObject.h:1002
bool hasMatchingEntry(STBase const &)
Definition STObject.cpp:280
V const & getFieldByConstRef(SField const &field, V const &empty) const
STNumber const & getFieldNumber(SField const &field) const
Definition STObject.cpp:697
OptionalProxy< T > at(OptionaledField< T > const &of)
Return a modifiable field value as std::optional.
void setFieldVL(SField const &field, Blob const &)
Definition STObject.cpp:780
void reserve(std::size_t n)
Definition STObject.h:959
T::value_type operator[](TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1027
std::size_t emplace_back(Args &&... args)
Definition STObject.h:989
boost::transform_iterator< Transform, STObject::list_type::const_iterator > iterator
Definition STObject.h:65
iterator end() const
Definition STObject.h:947
void applyTemplate(SOTemplate const &type)
Definition STObject.cpp:153
int getFieldIndex(SField const &field) const
Definition STObject.cpp:394
uint256 getHash(HashPrefix prefix) const
Definition STObject.cpp:376
void setFieldI32(SField const &field, std::int32_t)
Definition STObject.cpp:762
virtual ~STObject()=default
std::string getFullText() const override
Definition STObject.cpp:291
SOTemplate const * mType
Definition STObject.h:61
void setFieldU32(SField const &field, std::uint32_t)
Definition STObject.cpp:738
list_type v_
Definition STObject.h:60
STArray & peekFieldArray(SField const &field)
Definition STObject.cpp:482
std::string getText() const override
Definition STObject.cpp:322
STArray const & getFieldArray(SField const &field) const
Definition STObject.cpp:683
void setFieldArray(SField const &field, STArray const &v)
Definition STObject.cpp:822
STObject & peekFieldObject(SField const &field)
Definition STObject.cpp:476
STBase & getField(SField const &field)
Definition STObject.cpp:421
void setFieldAmount(SField const &field, STAmount const &)
Definition STObject.cpp:792
void add(Serializer &s) const override
Definition STObject.cpp:122
Serializer getSerializer() const
Definition STObject.h:980
bool isFlag(std::uint32_t) const
Definition STObject.cpp:512
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:465
STObject & operator=(STObject const &)=default
STObject(STObject const &)=default
int getCount() const
Definition STObject.h:996
ValueProxy< T > operator[](TypedField< T > const &f)
Get a modifiable field value.
SerializedTypeID getSType() const override
Definition STObject.cpp:110
void setFieldU16(SField const &field, std::uint16_t)
Definition STObject.cpp:732
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:626
static STObject makeInnerObject(SField const &name)
Definition STObject.cpp:76
std::int32_t getFieldI32(SField const &field) const
Definition STObject.cpp:632
STBase const & peekAtField(SField const &field) const
Definition STObject.cpp:410
void set(SOTemplate const &)
Definition STObject.cpp:137
STObject(SOTemplate const &type, SField const &name, F &&f)
Definition STObject.h:71
uint256 getSigningHash(HashPrefix prefix) const
Definition STObject.cpp:385
bool clearFlag(std::uint32_t)
Definition STObject.cpp:500
void setFieldCurrency(SField const &field, STCurrency const &)
Definition STObject.cpp:798
std::uint64_t getFieldU64(SField const &field) const
Definition STObject.cpp:602
void setFieldPathSet(SField const &field, STPathSet const &)
Definition STObject.cpp:816
STBase * move(std::size_t n, void *buf) override
Definition STObject.cpp:104
static std::vector< STBase const * > getSortedFields(STObject const &objToSort, WhichFields whichFields)
Definition STObject.cpp:916
STBase * getPField(SField const &field, bool createOkay=false)
Definition STObject.cpp:449
STBase * makeFieldPresent(SField const &field)
Definition STObject.cpp:529
STBase const * peekAtPField(SField const &field) const
Definition STObject.cpp:438
void applyTemplateFromSField(SField const &)
Definition STObject.cpp:207
bool setFlag(std::uint32_t)
Definition STObject.cpp:488
void setFieldObject(SField const &field, STObject const &v)
Definition STObject.cpp:828
bool operator!=(STObject const &o) const
Definition STObject.h:1147
void setFieldH128(SField const &field, uint128 const &)
Definition STObject.cpp:750
STObject getFieldObject(SField const &field) const
Definition STObject.cpp:673
T & peekField(SField const &field)
Definition STObject.h:1248
void setFieldH160(SField const &field, base_uint< 160, Tag > const &v)
Definition STObject.h:1129
void setFieldUsingSetValue(SField const &field, V value)
Definition STObject.h:1204
void setAccountID(SField const &field, AccountID const &)
Definition STObject.cpp:774
void setFieldUsingAssignment(SField const &field, T const &value)
Definition STObject.h:1227
bool delField(SField const &field)
Definition STObject.cpp:566
STBase & getIndex(int offset)
Definition STObject.h:1008
uint160 getFieldH160(SField const &field) const
Definition STObject.cpp:614
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:638
STBase * getPIndex(int offset)
Definition STObject.h:1020
STVector256 const & getFieldV256(SField const &field) const
Definition STObject.cpp:666
STPathSet const & getFieldPathSet(SField const &field) const
Definition STObject.cpp:659
bool isDefault() const override
Definition STObject.cpp:116
V getFieldByValue(SField const &field) const
void makeFieldAbsent(SField const &field)
Definition STObject.cpp:551
ValueProxy< T > at(TypedField< T > const &f)
Get a modifiable field value.
void setFieldH256(SField const &field, uint256 const &)
Definition STObject.cpp:756
OptionalProxy< T > operator[](OptionaledField< T > const &of)
Return a modifiable field value as std::optional.
std::uint16_t getFieldU16(SField const &field) const
Definition STObject.cpp:590
STAmount const & getFieldAmount(SField const &field) const
Definition STObject.cpp:652
std::uint32_t getFlags() const
Definition STObject.cpp:518
STBase * copy(std::size_t n, void *buf) const override
Definition STObject.cpp:98
An immutable linear range of bytes.
Definition Slice.h:27
STBase & get()
Definition STVar.h:75
T emplace_back(T... args)
T empty(T... args)
T end(T... args)
T is_same_v
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
void throwFieldNotFound(SField const &field)
Definition STObject.h:32
SOEStyle
Kind of element in each entry of an SOTemplate.
Definition SOTemplate.h:14
@ soeINVALID
Definition SOTemplate.h:15
@ soeOPTIONAL
Definition SOTemplate.h:17
@ soeDEFAULT
Definition SOTemplate.h:18
@ soeREQUIRED
Definition SOTemplate.h:16
Number operator*(Number const &x, Number const &y)
Definition Number.h:287
SerializedTypeID
Definition SField.h:91
HashPrefix
Prefix for hashing functions.
Definition HashPrefix.h:36
T reserve(T... args)
T runtime_error(T... args)
T size(T... args)
Note, should be treated as flags that can be | and &.
Definition STBase.h:18
Indicate std::optional field semantics.
Definition SField.h:311
TypedField< T > const * f
Definition SField.h:312
STBase const & operator()(detail::STVar const &e) const
Definition STObject.h:928
A field with a type known at compile time.
Definition SField.h:301