rippled
Loading...
Searching...
No Matches
STObject.h
1#pragma once
2
3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/basics/Slice.h>
5#include <xrpl/basics/chrono.h>
6#include <xrpl/basics/contract.h>
7#include <xrpl/beast/utility/instrumentation.h>
8#include <xrpl/protocol/HashPrefix.h>
9#include <xrpl/protocol/SOTemplate.h>
10#include <xrpl/protocol/STAmount.h>
11#include <xrpl/protocol/STBase.h>
12#include <xrpl/protocol/STCurrency.h>
13#include <xrpl/protocol/STIssue.h>
14#include <xrpl/protocol/STPathSet.h>
15#include <xrpl/protocol/STVector256.h>
16#include <xrpl/protocol/Units.h>
17#include <xrpl/protocol/detail/STVar.h>
18
19#include <boost/iterator/transform_iterator.hpp>
20
21#include <optional>
22#include <stdexcept>
23#include <type_traits>
24#include <utility>
25
26namespace xrpl {
27
28class STArray;
29
30inline void
32{
33 Throw<std::runtime_error>("Field not found: " + field.getName());
34}
35
36class STObject : public STBase, public CountedObject<STObject>
37{
38 // Proxy value for a STBase derived class
39 template <class T>
40 class Proxy;
41 template <class T>
42 class ValueProxy;
43 template <class T>
44 class OptionalProxy;
45
46 struct Transform
47 {
48 explicit Transform() = default;
49
52
53 STBase const&
54 operator()(detail::STVar const& e) const;
55 };
56
58
61
62public:
63 using iterator = boost::transform_iterator<Transform, STObject::list_type::const_iterator>;
64
65 virtual ~STObject() = default;
66 STObject(STObject const&) = default;
67
68 template <typename F>
69 STObject(SOTemplate const& type, SField const& name, F&& f) : STObject(type, name)
70 {
71 f(*this);
72 }
73
75 operator=(STObject const&) = default;
78 operator=(STObject&& other);
79
80 STObject(SOTemplate const& type, SField const& name);
81 STObject(SOTemplate const& type, SerialIter& sit, SField const& name);
82 STObject(SerialIter& sit, SField const& name, int depth = 0);
83 STObject(SerialIter&& sit, SField const& name);
84 explicit STObject(SField const& name);
85
86 static STObject
87 makeInnerObject(SField const& name);
88
90 begin() const;
91
93 end() const;
94
95 bool
96 empty() const;
97
98 void
100
101 void
102 applyTemplate(SOTemplate const& type);
103
104 void
106
107 bool
108 isFree() const;
109
110 void
111 set(SOTemplate const&);
112
113 bool
114 set(SerialIter& u, int depth = 0);
115
117 getSType() const override;
118
119 bool
120 isEquivalent(STBase const& t) const override;
121
122 bool
123 isDefault() const override;
124
125 void
126 add(Serializer& s) const override;
127
129 getFullText() const override;
130
132 getText() const override;
133
134 // TODO(tom): options should be an enum.
136
137 void
139
141 getSerializer() const;
142
143 template <class... Args>
145 emplace_back(Args&&... args);
146
147 int
148 getCount() const;
149
152 bool isFlag(std::uint32_t) const;
153
155 getFlags() const;
156
157 uint256
158 getHash(HashPrefix prefix) const;
159
160 uint256
161 getSigningHash(HashPrefix prefix) const;
162
163 STBase const&
164 peekAtIndex(int offset) const;
165
166 STBase&
167 getIndex(int offset);
168
169 STBase const*
170 peekAtPIndex(int offset) const;
171
172 STBase*
173 getPIndex(int offset);
174
175 int
176 getFieldIndex(SField const& field) const;
177
178 SField const&
179 getFieldSType(int index) const;
180
181 STBase const&
182 peekAtField(SField const& field) const;
183
184 STBase&
185 getField(SField const& field);
186
187 STBase const*
188 peekAtPField(SField const& field) const;
189
190 STBase*
191 getPField(SField const& field, bool createOkay = false);
192
193 // these throw if the field type doesn't match, or return default values
194 // if the field is optional but not present
195 unsigned char
196 getFieldU8(SField const& field) const;
198 getFieldU16(SField const& field) const;
200 getFieldU32(SField const& field) const;
202 getFieldU64(SField const& field) const;
203 uint128
204 getFieldH128(SField const& field) const;
205
206 uint160
207 getFieldH160(SField const& field) const;
208 uint192
209 getFieldH192(SField const& field) const;
210 uint256
211 getFieldH256(SField const& field) const;
213 getFieldI32(SField const& field) const;
215 getAccountID(SField const& field) const;
216
217 Blob
218 getFieldVL(SField const& field) const;
219 STAmount const&
220 getFieldAmount(SField const& field) const;
221 STPathSet const&
222 getFieldPathSet(SField const& field) const;
223 STVector256 const&
224 getFieldV256(SField const& field) const;
225 // If not found, returns an object constructed with the given field
227 getFieldObject(SField const& field) const;
228 STArray const&
229 getFieldArray(SField const& field) const;
230 STCurrency const&
231 getFieldCurrency(SField const& field) const;
232 STNumber const&
233 getFieldNumber(SField const& field) const;
234
242 template <class T>
243 typename T::value_type
244 operator[](TypedField<T> const& f) const;
245
254 template <class T>
256 operator[](OptionaledField<T> const& of) const;
257
265 template <class T>
268
278 template <class T>
281
289 template <class T>
290 typename T::value_type
291 at(TypedField<T> const& f) const;
292
301 template <class T>
303 at(OptionaledField<T> const& of) const;
304
312 template <class T>
314 at(TypedField<T> const& f);
315
325 template <class T>
328
332 void
334
335 void
336 set(STBase&& v);
337
338 void
339 setFieldU8(SField const& field, unsigned char);
340 void
341 setFieldU16(SField const& field, std::uint16_t);
342 void
343 setFieldU32(SField const& field, std::uint32_t);
344 void
345 setFieldU64(SField const& field, std::uint64_t);
346 void
347 setFieldH128(SField const& field, uint128 const&);
348 void
349 setFieldH256(SField const& field, uint256 const&);
350 void
351 setFieldI32(SField const& field, std::int32_t);
352 void
353 setFieldVL(SField const& field, Blob const&);
354 void
355 setFieldVL(SField const& field, Slice const&);
356
357 void
358 setAccountID(SField const& field, AccountID const&);
359
360 void
361 setFieldAmount(SField const& field, STAmount const&);
362 void
363 setFieldIssue(SField const& field, STIssue const&);
364 void
365 setFieldCurrency(SField const& field, STCurrency const&);
366 void
367 setFieldNumber(SField const& field, STNumber const&);
368 void
369 setFieldPathSet(SField const& field, STPathSet const&);
370 void
371 setFieldV256(SField const& field, STVector256 const& v);
372 void
373 setFieldArray(SField const& field, STArray const& v);
374 void
375 setFieldObject(SField const& field, STObject const& v);
376
377 template <class Tag>
378 void
379 setFieldH160(SField const& field, base_uint<160, Tag> const& v);
380
381 STObject&
382 peekFieldObject(SField const& field);
383 STArray&
384 peekFieldArray(SField const& field);
385
386 bool
387 isFieldPresent(SField const& field) const;
388 STBase*
389 makeFieldPresent(SField const& field);
390 void
391 makeFieldAbsent(SField const& field);
392 bool
393 delField(SField const& field);
394 void
395 delField(int index);
396
398 getStyle(SField const& field) const;
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 =
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>
511template <typename U, typename Value = typename U::value_type, typename Unit = typename U::unit_type>
514template <typename U, typename Value = typename U::value_type>
516template <typename U>
518
519template <class T, class U>
520concept Addable = requires(T t, U u) { t = t + u; };
521template <typename T, typename U>
523
524template <class T>
526{
527private:
528 using value_type = typename T::value_type;
529
530public:
531 ValueProxy(ValueProxy const&) = default;
533 operator=(ValueProxy const&) = delete;
534
535 template <class U>
537 operator=(U&& u);
538
539 // Convenience operators for value types supporting
540 // arithmetic operations
541 template <IsArithmetic U>
544 operator+=(U const& u);
545
546 template <IsArithmetic U>
549 operator-=(U const& u);
550
551 operator value_type() const;
552
553 template <typename U>
554 friend bool
555 operator==(U const& lhs, STObject::ValueProxy<T> const& rhs)
556 {
557 return rhs.value() == lhs;
558 }
559
560private:
561 friend class STObject;
562
563 ValueProxy(STObject* st, TypedField<T> const* f);
564};
565
566template <class T>
568{
569private:
570 using value_type = typename T::value_type;
571
573
574public:
575 OptionalProxy(OptionalProxy const&) = default;
577 operator=(OptionalProxy const&) = delete;
578
584 explicit
585 operator bool() const noexcept;
586
587 operator optional_type() const;
588
591 operator~() const;
592
593 friend bool
594 operator==(OptionalProxy const& lhs, std::nullopt_t) noexcept
595 {
596 return !lhs.engaged();
597 }
598
599 friend bool
601 {
602 return rhs == std::nullopt;
603 }
604
605 friend bool
606 operator==(OptionalProxy const& lhs, optional_type const& rhs) noexcept
607 {
608 if (!lhs.engaged())
609 return !rhs;
610 if (!rhs)
611 return false;
612 return *lhs == *rhs;
613 }
614
615 friend bool
616 operator==(optional_type const& lhs, OptionalProxy const& rhs) noexcept
617 {
618 return rhs == lhs;
619 }
620
621 friend bool
622 operator==(OptionalProxy const& lhs, OptionalProxy const& rhs) noexcept
623 {
624 if (lhs.engaged() != rhs.engaged())
625 return false;
626 return !lhs.engaged() || *lhs == *rhs;
627 }
628
629 friend bool
631 {
632 return !(lhs == std::nullopt);
633 }
634
635 friend bool
637 {
638 return !(rhs == std::nullopt);
639 }
640
641 friend bool
642 operator!=(OptionalProxy const& lhs, optional_type const& rhs) noexcept
643 {
644 return !(lhs == rhs);
645 }
646
647 friend bool
648 operator!=(optional_type const& lhs, OptionalProxy const& rhs) noexcept
649 {
650 return !(lhs == rhs);
651 }
652
653 friend bool
654 operator!=(OptionalProxy const& lhs, OptionalProxy const& rhs) noexcept
655 {
656 return !(lhs == rhs);
657 }
658
659 // Emulate std::optional::value_or
661 value_or(value_type val) const;
662
668 operator=(optional_type const& v);
669
670 template <class U>
672 operator=(U&& u);
673
674private:
675 friend class STObject;
676
677 OptionalProxy(STObject* st, TypedField<T> const* f);
678
679 bool
680 engaged() const noexcept;
681
682 void
683 disengage();
684
686 optional_value() const;
687};
688
689class STObject::FieldErr : public std::runtime_error
690{
692};
693
694template <class T>
696{
697 if (st_->mType)
698 {
699 // STObject has associated template
700 if (!st_->peekAtPField(*f_))
701 Throw<STObject::FieldErr>("Template field error '" + this->f_->getName() + "'");
702 style_ = st_->mType->style(*f_);
703 }
704 else
705 {
707 }
708}
709
710template <class T>
711auto
713{
714 auto const t = find();
715 if (t)
716 return t->value();
717 if (style_ == soeINVALID)
718 {
719 Throw<STObject::FieldErr>("Value requested from invalid STObject.");
720 }
721 if (style_ != soeDEFAULT)
722 {
723 Throw<STObject::FieldErr>("Missing field '" + this->f_->getName() + "'");
724 }
725 return value_type{};
726}
727
728template <class T>
729auto
731{
732 return this->value();
733}
734
737template <class T>
738T const*
740{
741 return this->find();
742}
743
744template <class T>
745inline T const*
747{
748 return dynamic_cast<T const*>(st_->peekAtPField(*f_));
749}
750
751template <class T>
752template <class U>
753void
755{
756 if (style_ == soeDEFAULT && u == value_type{})
757 {
758 st_->makeFieldAbsent(*f_);
759 return;
760 }
761 T* t;
762 if (style_ == soeINVALID)
763 t = dynamic_cast<T*>(st_->getPField(*f_, true));
764 else
765 t = dynamic_cast<T*>(st_->makeFieldPresent(*f_));
766 XRPL_ASSERT(t, "xrpl::STObject::Proxy::assign : type cast succeeded");
767 *t = std::forward<U>(u);
768}
769
770//------------------------------------------------------------------------------
771
772template <class T>
773template <class U>
776{
777 this->assign(std::forward<U>(u));
778 return *this;
779}
780
781template <typename T>
782template <IsArithmetic U>
786{
787 this->assign(this->value() + u);
788 return *this;
789}
790
791template <class T>
792template <IsArithmetic U>
796{
797 this->assign(this->value() - u);
798 return *this;
799}
800
801template <class T>
803{
804 return this->value();
805}
806
807template <class T>
811
812//------------------------------------------------------------------------------
813
814template <class T>
816{
817 return engaged();
818}
819
820template <class T>
822{
823 return optional_value();
824}
825
826template <class T>
829{
830 return optional_value();
831}
832
833template <class T>
834auto
836{
837 disengage();
838 return *this;
839}
840
841template <class T>
842auto
844{
845 if (v)
846 this->assign(std::move(*v));
847 else
848 disengage();
849 return *this;
850}
851
852template <class T>
853auto
855{
856 if (v)
857 this->assign(*v);
858 else
859 disengage();
860 return *this;
861}
862
863template <class T>
864template <class U>
867{
868 this->assign(std::forward<U>(u));
869 return *this;
870}
871
872template <class T>
876
877template <class T>
878bool
880{
881 return this->style_ == soeDEFAULT || this->find() != nullptr;
882}
883
884template <class T>
885void
887{
888 if (this->style_ == soeREQUIRED || this->style_ == soeDEFAULT)
889 Throw<STObject::FieldErr>("Template field error '" + this->f_->getName() + "'");
890 if (this->style_ == soeINVALID)
891 this->st_->delField(*this->f_);
892 else
893 this->st_->makeFieldAbsent(*this->f_);
894}
895
896template <class T>
897auto
899{
900 if (!engaged())
901 return std::nullopt;
902 return this->value();
903}
904
905template <class T>
908{
909 return engaged() ? this->value() : val;
910}
911
912//------------------------------------------------------------------------------
913
914inline STBase const&
916{
917 return e.get();
918}
919
920//------------------------------------------------------------------------------
921
922inline STObject::STObject(SerialIter&& sit, SField const& name) : STObject(sit, name)
923{
924}
925
928{
929 return iterator(v_.begin());
930}
931
934{
935 return iterator(v_.end());
936}
937
938inline bool
940{
941 return v_.empty();
942}
943
944inline void
949
950inline bool
952{
953 return mType == nullptr;
954}
955
956inline void
961
962// VFALCO NOTE does this return an expensive copy of an object with a
963// dynamic buffer?
964// VFALCO TODO Remove this function and fix the few callers.
965inline Serializer
967{
968 Serializer s;
969 add(s, withAllFields);
970 return s;
971}
972
973template <class... Args>
974inline std::size_t
976{
978 return v_.size() - 1;
979}
980
981inline int
983{
984 return v_.size();
985}
986
987inline STBase const&
988STObject::peekAtIndex(int offset) const
989{
990 return v_[offset].get();
991}
992
993inline STBase&
995{
996 return v_[offset].get();
997}
998
999inline STBase const*
1000STObject::peekAtPIndex(int offset) const
1001{
1002 return &v_[offset].get();
1003}
1004
1005inline STBase*
1007{
1008 return &v_[offset].get();
1009}
1010
1011template <class T>
1012typename T::value_type
1014{
1015 return at(f);
1016}
1017
1018template <class T>
1021{
1022 return at(of);
1023}
1024
1025template <class T>
1026inline auto
1028{
1029 return at(f);
1030}
1031
1032template <class T>
1033inline auto
1035{
1036 return at(of);
1037}
1038
1039template <class T>
1040typename T::value_type
1042{
1043 auto const b = peekAtPField(f);
1044 if (!b)
1045 // This is a free object (no constraints)
1046 // with no template
1047 Throw<STObject::FieldErr>("Missing field: " + f.getName());
1048
1049 if (auto const u = dynamic_cast<T const*>(b))
1050 return u->value();
1051
1052 XRPL_ASSERT(mType, "xrpl::STObject::at(TypedField auto) : field template non-null");
1053 XRPL_ASSERT(b->getSType() == STI_NOTPRESENT, "xrpl::STObject::at(TypedField auto) : type not present");
1054
1055 if (mType->style(f) == soeOPTIONAL)
1056 Throw<STObject::FieldErr>("Missing optional field: " + f.getName());
1057
1058 XRPL_ASSERT(mType->style(f) == soeDEFAULT, "xrpl::STObject::at(TypedField auto) : template style is default");
1059
1060 // Used to help handle the case where value_type is a const reference,
1061 // otherwise we would return the address of a temporary.
1062 static std::decay_t<typename T::value_type> const dv{};
1063 return dv;
1064}
1065
1066template <class T>
1069{
1070 auto const b = peekAtPField(*of.f);
1071 if (!b)
1072 return std::nullopt;
1073 auto const u = dynamic_cast<T const*>(b);
1074 if (!u)
1075 {
1076 XRPL_ASSERT(
1077 mType,
1078 "xrpl::STObject::at(OptionaledField auto) : field template "
1079 "non-null");
1080 XRPL_ASSERT(b->getSType() == STI_NOTPRESENT, "xrpl::STObject::at(OptionaledField auto) : type not present");
1081 if (mType->style(*of.f) == soeOPTIONAL)
1082 return std::nullopt;
1083 XRPL_ASSERT(
1084 mType->style(*of.f) == soeDEFAULT,
1085 "xrpl::STObject::at(OptionaledField auto) : template style is "
1086 "default");
1087 return typename T::value_type{};
1088 }
1089 return u->value();
1090}
1091
1092template <class T>
1093inline auto
1095{
1096 return ValueProxy<T>(this, &f);
1097}
1098
1099template <class T>
1100inline auto
1102{
1103 return OptionalProxy<T>(this, of.f);
1104}
1105
1106template <class Tag>
1107void
1109{
1110 STBase* rf = getPField(field, true);
1111
1112 if (!rf)
1113 throwFieldNotFound(field);
1114
1115 if (rf->getSType() == STI_NOTPRESENT)
1116 rf = makeFieldPresent(field);
1117
1118 using Bits = STBitString<160>;
1119 if (auto cf = dynamic_cast<Bits*>(rf))
1120 cf->setValue(v);
1121 else
1122 Throw<std::runtime_error>("Wrong field type");
1123}
1124
1125inline bool
1127{
1128 return !(*this == o);
1129}
1130
1131template <typename T, typename V>
1132V
1134{
1135 STBase const* rf = peekAtPField(field);
1136
1137 if (!rf)
1138 throwFieldNotFound(field);
1139
1140 SerializedTypeID id = rf->getSType();
1141
1142 if (id == STI_NOTPRESENT)
1143 return V(); // optional field not present
1144
1145 T const* cf = dynamic_cast<T const*>(rf);
1146
1147 if (!cf)
1148 Throw<std::runtime_error>("Wrong field type");
1149
1150 return cf->value();
1151}
1152
1153// Implementations for getting (most) fields that return by const reference.
1154//
1155// If an absent optional field is deserialized we don't have anything
1156// obvious to return. So we insist on having the call provide an
1157// 'empty' value we return in that circumstance.
1158template <typename T, typename V>
1159V const&
1160STObject::getFieldByConstRef(SField const& field, V const& empty) const
1161{
1162 STBase const* rf = peekAtPField(field);
1163
1164 if (!rf)
1165 throwFieldNotFound(field);
1166
1167 SerializedTypeID id = rf->getSType();
1168
1169 if (id == STI_NOTPRESENT)
1170 return empty; // optional field not present
1171
1172 T const* cf = dynamic_cast<T const*>(rf);
1173
1174 if (!cf)
1175 Throw<std::runtime_error>("Wrong field type");
1176
1177 return *cf;
1178}
1179
1180// Implementation for setting most fields with a setValue() method.
1181template <typename T, typename V>
1182void
1184{
1185 static_assert(!std::is_lvalue_reference<V>::value, "");
1186
1187 STBase* rf = getPField(field, true);
1188
1189 if (!rf)
1190 throwFieldNotFound(field);
1191
1192 if (rf->getSType() == STI_NOTPRESENT)
1193 rf = makeFieldPresent(field);
1194
1195 T* cf = dynamic_cast<T*>(rf);
1196
1197 if (!cf)
1198 Throw<std::runtime_error>("Wrong field type");
1199
1200 cf->setValue(std::move(value));
1201}
1202
1203// Implementation for setting fields using assignment
1204template <typename T>
1205void
1206STObject::setFieldUsingAssignment(SField const& field, T const& 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) = value;
1222}
1223
1224// Implementation for peeking STObjects and STArrays
1225template <typename T>
1226T&
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 return *cf;
1243}
1244
1245} // namespace xrpl
T begin(T... args)
Represents a JSON value.
Definition json_value.h:130
Tracks the number of instances of an object.
Identifies fields.
Definition SField.h:126
std::string const & getName() const
Definition SField.h:193
Defines the fields and their attributes within a STObject.
Definition SOTemplate.h:88
SOEStyle style(SField const &sf) const
Definition SOTemplate.h:139
A type which can be exported to a well known binary format.
Definition STBase.h:115
virtual SerializedTypeID getSType() const
Definition STBase.cpp:56
void setValue(base_uint< Bits, Tag > const &v)
A serializable number.
Definition STNumber.h:35
friend bool operator!=(OptionalProxy const &lhs, optional_type const &rhs) noexcept
Definition STObject.h:642
friend bool operator==(OptionalProxy const &lhs, optional_type const &rhs) noexcept
Definition STObject.h:606
friend bool operator==(optional_type const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:616
friend bool operator==(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:622
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:828
std::optional< typename std::decay< value_type >::type > optional_type
Definition STObject.h:572
typename T::value_type value_type
Definition STObject.h:570
friend bool operator!=(OptionalProxy const &lhs, std::nullopt_t) noexcept
Definition STObject.h:630
friend bool operator!=(std::nullopt_t, OptionalProxy const &rhs) noexcept
Definition STObject.h:636
OptionalProxy & operator=(OptionalProxy const &)=delete
bool engaged() const noexcept
Definition STObject.h:879
friend bool operator!=(optional_type const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:648
friend bool operator==(std::nullopt_t, OptionalProxy const &rhs) noexcept
Definition STObject.h:600
value_type value_or(value_type val) const
Definition STObject.h:907
optional_type optional_value() const
Definition STObject.h:898
friend bool operator!=(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:654
void assign(U &&u)
Definition STObject.h:754
Proxy(Proxy const &)=default
value_type operator*() const
Definition STObject.h:730
T const * operator->() const
Do not use operator->() unless the field is required, or you've checked that it's set.
Definition STObject.h:739
value_type value() const
Definition STObject.h:712
T const * find() const
Definition STObject.h:746
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:528
ValueProxy & operator+=(U const &u)
ValueProxy & operator-=(U const &u)
friend bool operator==(U const &lhs, STObject::ValueProxy< T > const &rhs)
Definition STObject.h:555
std::enable_if_t< std::is_assignable_v< T, U >, ValueProxy & > operator=(U &&u)
void setFieldU8(SField const &field, unsigned char)
Definition STObject.cpp:706
SField const & getFieldSType(int index) const
Definition STObject.cpp:406
uint192 getFieldH192(SField const &field) const
Definition STObject.cpp:600
bool isFree() const
Definition STObject.h:951
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1041
STBase const * peekAtPIndex(int offset) const
Definition STObject.h:1000
Json::Value getJson(JsonOptions=JsonOptions::none) const override
Definition STObject.cpp:814
STCurrency const & getFieldCurrency(SField const &field) const
Definition STObject.cpp:670
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:624
void addWithoutSigningFields(Serializer &s) const
Definition STObject.h:957
void setFieldIssue(SField const &field, STIssue const &)
Definition STObject.cpp:784
uint128 getFieldH128(SField const &field) const
Definition STObject.cpp:588
iterator begin() const
Definition STObject.h:927
bool operator==(STObject const &o) const
Definition STObject.cpp:827
bool isEquivalent(STBase const &t) const override
Definition STObject.cpp:327
bool empty() const
Definition STObject.h:939
void setFieldNumber(SField const &field, STNumber const &)
Definition STObject.cpp:790
void setFieldV256(SField const &field, STVector256 const &v)
Definition STObject.cpp:748
void setFieldU64(SField const &field, std::uint64_t)
Definition STObject.cpp:724
unsigned char getFieldU8(SField const &field) const
Definition STObject.cpp:564
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:576
STBase const & peekAtIndex(int offset) const
Definition STObject.h:988
bool hasMatchingEntry(STBase const &)
Definition STObject.cpp:266
V const & getFieldByConstRef(SField const &field, V const &empty) const
STNumber const & getFieldNumber(SField const &field) const
Definition STObject.cpp:677
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:760
void reserve(std::size_t n)
Definition STObject.h:945
T::value_type operator[](TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1013
std::size_t emplace_back(Args &&... args)
Definition STObject.h:975
iterator end() const
Definition STObject.h:933
void applyTemplate(SOTemplate const &type)
Definition STObject.cpp:148
int getFieldIndex(SField const &field) const
Definition STObject.cpp:368
uint256 getHash(HashPrefix prefix) const
Definition STObject.cpp:350
void setFieldI32(SField const &field, std::int32_t)
Definition STObject.cpp:742
virtual ~STObject()=default
std::string getFullText() const override
Definition STObject.cpp:277
SOTemplate const * mType
Definition STObject.h:60
void setFieldU32(SField const &field, std::uint32_t)
Definition STObject.cpp:718
list_type v_
Definition STObject.h:59
STArray & peekFieldArray(SField const &field)
Definition STObject.cpp:456
std::string getText() const override
Definition STObject.cpp:308
STArray const & getFieldArray(SField const &field) const
Definition STObject.cpp:663
void setFieldArray(SField const &field, STArray const &v)
Definition STObject.cpp:802
STObject & peekFieldObject(SField const &field)
Definition STObject.cpp:450
SOEStyle getStyle(SField const &field) const
Definition STObject.cpp:558
STBase & getField(SField const &field)
Definition STObject.cpp:395
void setFieldAmount(SField const &field, STAmount const &)
Definition STObject.cpp:772
void add(Serializer &s) const override
Definition STObject.cpp:117
Serializer getSerializer() const
Definition STObject.h:966
bool isFlag(std::uint32_t) const
Definition STObject.cpp:486
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:439
STObject & operator=(STObject const &)=default
STObject(STObject const &)=default
int getCount() const
Definition STObject.h:982
ValueProxy< T > operator[](TypedField< T > const &f)
Get a modifiable field value.
SerializedTypeID getSType() const override
Definition STObject.cpp:105
void setFieldU16(SField const &field, std::uint16_t)
Definition STObject.cpp:712
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:606
static STObject makeInnerObject(SField const &name)
Definition STObject.cpp:72
std::int32_t getFieldI32(SField const &field) const
Definition STObject.cpp:612
STBase const & peekAtField(SField const &field) const
Definition STObject.cpp:384
void set(SOTemplate const &)
Definition STObject.cpp:132
STObject(SOTemplate const &type, SField const &name, F &&f)
Definition STObject.h:69
uint256 getSigningHash(HashPrefix prefix) const
Definition STObject.cpp:359
bool clearFlag(std::uint32_t)
Definition STObject.cpp:474
void setFieldCurrency(SField const &field, STCurrency const &)
Definition STObject.cpp:778
std::uint64_t getFieldU64(SField const &field) const
Definition STObject.cpp:582
void setFieldPathSet(SField const &field, STPathSet const &)
Definition STObject.cpp:796
STBase * move(std::size_t n, void *buf) override
Definition STObject.cpp:99
static std::vector< STBase const * > getSortedFields(STObject const &objToSort, WhichFields whichFields)
Definition STObject.cpp:894
STBase * getPField(SField const &field, bool createOkay=false)
Definition STObject.cpp:423
STBase * makeFieldPresent(SField const &field)
Definition STObject.cpp:503
STBase const * peekAtPField(SField const &field) const
Definition STObject.cpp:412
void applyTemplateFromSField(SField const &)
Definition STObject.cpp:197
bool setFlag(std::uint32_t)
Definition STObject.cpp:462
void setFieldObject(SField const &field, STObject const &v)
Definition STObject.cpp:808
bool operator!=(STObject const &o) const
Definition STObject.h:1126
void setFieldH128(SField const &field, uint128 const &)
Definition STObject.cpp:730
STObject getFieldObject(SField const &field) const
Definition STObject.cpp:653
T & peekField(SField const &field)
Definition STObject.h:1227
void setFieldH160(SField const &field, base_uint< 160, Tag > const &v)
Definition STObject.h:1108
void setFieldUsingSetValue(SField const &field, V value)
Definition STObject.h:1183
void setAccountID(SField const &field, AccountID const &)
Definition STObject.cpp:754
void setFieldUsingAssignment(SField const &field, T const &value)
Definition STObject.h:1206
bool delField(SField const &field)
Definition STObject.cpp:540
STBase & getIndex(int offset)
Definition STObject.h:994
uint160 getFieldH160(SField const &field) const
Definition STObject.cpp:594
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:618
STBase * getPIndex(int offset)
Definition STObject.h:1006
STVector256 const & getFieldV256(SField const &field) const
Definition STObject.cpp:646
STPathSet const & getFieldPathSet(SField const &field) const
Definition STObject.cpp:639
bool isDefault() const override
Definition STObject.cpp:111
V getFieldByValue(SField const &field) const
void makeFieldAbsent(SField const &field)
Definition STObject.cpp:525
ValueProxy< T > at(TypedField< T > const &f)
Get a modifiable field value.
void setFieldH256(SField const &field, uint256 const &)
Definition STObject.cpp:736
boost::transform_iterator< Transform, STObject::list_type::const_iterator > iterator
Definition STObject.h:63
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:570
STAmount const & getFieldAmount(SField const &field) const
Definition STObject.cpp:632
std::uint32_t getFlags() const
Definition STObject.cpp:492
STBase * copy(std::size_t n, void *buf) const override
Definition STObject.cpp:93
An immutable linear range of bytes.
Definition Slice.h:26
STBase & get()
Definition STVar.h:74
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:5
void throwFieldNotFound(SField const &field)
Definition STObject.h:31
SOEStyle
Kind of element in each entry of an SOTemplate.
Definition SOTemplate.h:13
@ soeINVALID
Definition SOTemplate.h:14
@ soeOPTIONAL
Definition SOTemplate.h:16
@ soeDEFAULT
Definition SOTemplate.h:17
@ soeREQUIRED
Definition SOTemplate.h:15
Number operator*(Number const &x, Number const &y)
Definition Number.h:646
SerializedTypeID
Definition SField.h:90
HashPrefix
Prefix for hashing functions.
Definition HashPrefix.h:34
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:17
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:915
A field with a type known at compile time.
Definition SField.h:301