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 ripple {
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
485 T const*
486 operator->() const;
487
488protected:
492
493 Proxy(Proxy const&) = default;
494
495 Proxy(STObject* st, TypedField<T> const* f);
496
497 T const*
498 find() const;
499
500 template <class U>
501 void
502 assign(U&& u);
503};
504
505// Constraint += and -= ValueProxy operators
506// to value types that support arithmetic operations
507template <typename U>
509
510template <class T>
512{
513private:
514 using value_type = typename T::value_type;
515
516public:
517 ValueProxy(ValueProxy const&) = default;
519 operator=(ValueProxy const&) = delete;
520
521 template <class U>
523 operator=(U&& u);
524
525 // Convenience operators for value types supporting
526 // arithmetic operations
527 template <IsArithmetic U>
529 operator+=(U const& u);
530
531 template <IsArithmetic U>
533 operator-=(U const& u);
534
535 operator value_type() const;
536
537 template <typename U>
538 friend bool
539 operator==(U const& lhs, STObject::ValueProxy<T> const& rhs)
540 {
541 return rhs.value() == lhs;
542 }
543
544private:
545 friend class STObject;
546
547 ValueProxy(STObject* st, TypedField<T> const* f);
548};
549
550template <class T>
552{
553private:
554 using value_type = typename T::value_type;
555
557
558public:
559 OptionalProxy(OptionalProxy const&) = default;
561 operator=(OptionalProxy const&) = delete;
562
568 explicit
569 operator bool() const noexcept;
570
571 operator optional_type() const;
572
575 operator~() const;
576
577 friend bool
578 operator==(OptionalProxy const& lhs, std::nullopt_t) noexcept
579 {
580 return !lhs.engaged();
581 }
582
583 friend bool
585 {
586 return rhs == std::nullopt;
587 }
588
589 friend bool
590 operator==(OptionalProxy const& lhs, optional_type const& rhs) noexcept
591 {
592 if (!lhs.engaged())
593 return !rhs;
594 if (!rhs)
595 return false;
596 return *lhs == *rhs;
597 }
598
599 friend bool
600 operator==(optional_type const& lhs, OptionalProxy const& rhs) noexcept
601 {
602 return rhs == lhs;
603 }
604
605 friend bool
606 operator==(OptionalProxy const& lhs, OptionalProxy const& rhs) noexcept
607 {
608 if (lhs.engaged() != rhs.engaged())
609 return false;
610 return !lhs.engaged() || *lhs == *rhs;
611 }
612
613 friend bool
615 {
616 return !(lhs == std::nullopt);
617 }
618
619 friend bool
621 {
622 return !(rhs == std::nullopt);
623 }
624
625 friend bool
626 operator!=(OptionalProxy const& lhs, optional_type const& rhs) noexcept
627 {
628 return !(lhs == rhs);
629 }
630
631 friend bool
632 operator!=(optional_type const& lhs, OptionalProxy const& rhs) noexcept
633 {
634 return !(lhs == rhs);
635 }
636
637 friend bool
638 operator!=(OptionalProxy const& lhs, OptionalProxy const& rhs) noexcept
639 {
640 return !(lhs == rhs);
641 }
642
643 // Emulate std::optional::value_or
645 value_or(value_type val) const;
646
652 operator=(optional_type const& v);
653
654 template <class U>
656 operator=(U&& u);
657
658private:
659 friend class STObject;
660
661 OptionalProxy(STObject* st, TypedField<T> const* f);
662
663 bool
664 engaged() const noexcept;
665
666 void
667 disengage();
668
670 optional_value() const;
671};
672
673class STObject::FieldErr : public std::runtime_error
674{
676};
677
678template <class T>
680{
681 if (st_->mType)
682 {
683 // STObject has associated template
684 if (!st_->peekAtPField(*f_))
685 Throw<STObject::FieldErr>(
686 "Template field error '" + this->f_->getName() + "'");
687 style_ = st_->mType->style(*f_);
688 }
689 else
690 {
692 }
693}
694
695template <class T>
696auto
698{
699 auto const t = find();
700 if (t)
701 return t->value();
702 if (style_ == soeINVALID)
703 {
704 Throw<STObject::FieldErr>("Value requested from invalid STObject.");
705 }
706 if (style_ != soeDEFAULT)
707 {
708 Throw<STObject::FieldErr>(
709 "Missing field '" + this->f_->getName() + "'");
710 }
711 return value_type{};
712}
713
714template <class T>
715auto
717{
718 return this->value();
719}
720
721template <class T>
722T const*
724{
725 return this->find();
726}
727
728template <class T>
729inline T const*
731{
732 return dynamic_cast<T const*>(st_->peekAtPField(*f_));
733}
734
735template <class T>
736template <class U>
737void
739{
740 if (style_ == soeDEFAULT && u == value_type{})
741 {
742 st_->makeFieldAbsent(*f_);
743 return;
744 }
745 T* t;
746 if (style_ == soeINVALID)
747 t = dynamic_cast<T*>(st_->getPField(*f_, true));
748 else
749 t = dynamic_cast<T*>(st_->makeFieldPresent(*f_));
750 XRPL_ASSERT(t, "ripple::STObject::Proxy::assign : type cast succeeded");
751 *t = std::forward<U>(u);
752}
753
754//------------------------------------------------------------------------------
755
756template <class T>
757template <class U>
760{
761 this->assign(std::forward<U>(u));
762 return *this;
763}
764
765template <typename T>
766template <IsArithmetic U>
769{
770 this->assign(this->value() + u);
771 return *this;
772}
773
774template <class T>
775template <IsArithmetic U>
778{
779 this->assign(this->value() - u);
780 return *this;
781}
782
783template <class T>
785{
786 return this->value();
787}
788
789template <class T>
791 : Proxy<T>(st, f)
792{
793}
794
795//------------------------------------------------------------------------------
796
797template <class T>
799{
800 return engaged();
801}
802
803template <class T>
805 T>::optional_type() const
806{
807 return optional_value();
808}
809
810template <class T>
813{
814 return optional_value();
815}
816
817template <class T>
818auto
820{
821 disengage();
822 return *this;
823}
824
825template <class T>
826auto
828{
829 if (v)
830 this->assign(std::move(*v));
831 else
832 disengage();
833 return *this;
834}
835
836template <class T>
837auto
839{
840 if (v)
841 this->assign(*v);
842 else
843 disengage();
844 return *this;
845}
846
847template <class T>
848template <class U>
851{
852 this->assign(std::forward<U>(u));
853 return *this;
854}
855
856template <class T>
861
862template <class T>
863bool
865{
866 return this->style_ == soeDEFAULT || this->find() != nullptr;
867}
868
869template <class T>
870void
872{
873 if (this->style_ == soeREQUIRED || this->style_ == soeDEFAULT)
874 Throw<STObject::FieldErr>(
875 "Template field error '" + this->f_->getName() + "'");
876 if (this->style_ == soeINVALID)
877 this->st_->delField(*this->f_);
878 else
879 this->st_->makeFieldAbsent(*this->f_);
880}
881
882template <class T>
883auto
885{
886 if (!engaged())
887 return std::nullopt;
888 return this->value();
889}
890
891template <class T>
894{
895 return engaged() ? this->value() : val;
896}
897
898//------------------------------------------------------------------------------
899
900inline STBase const&
902{
903 return e.get();
904}
905
906//------------------------------------------------------------------------------
907
908inline STObject::STObject(SerialIter&& sit, SField const& name)
909 : STObject(sit, name)
910{
911}
912
915{
916 return iterator(v_.begin());
917}
918
921{
922 return iterator(v_.end());
923}
924
925inline bool
927{
928 return v_.empty();
929}
930
931inline void
936
937inline bool
939{
940 return mType == nullptr;
941}
942
943inline void
948
949// VFALCO NOTE does this return an expensive copy of an object with a
950// dynamic buffer?
951// VFALCO TODO Remove this function and fix the few callers.
952inline Serializer
954{
955 Serializer s;
956 add(s, withAllFields);
957 return s;
958}
959
960template <class... Args>
961inline std::size_t
963{
965 return v_.size() - 1;
966}
967
968inline int
970{
971 return v_.size();
972}
973
974inline STBase const&
975STObject::peekAtIndex(int offset) const
976{
977 return v_[offset].get();
978}
979
980inline STBase&
982{
983 return v_[offset].get();
984}
985
986inline STBase const*
987STObject::peekAtPIndex(int offset) const
988{
989 return &v_[offset].get();
990}
991
992inline STBase*
994{
995 return &v_[offset].get();
996}
997
998template <class T>
999typename T::value_type
1001{
1002 return at(f);
1003}
1004
1005template <class T>
1008{
1009 return at(of);
1010}
1011
1012template <class T>
1013inline auto
1015{
1016 return at(f);
1017}
1018
1019template <class T>
1020inline auto
1022{
1023 return at(of);
1024}
1025
1026template <class T>
1027typename T::value_type
1029{
1030 auto const b = peekAtPField(f);
1031 if (!b)
1032 // This is a free object (no constraints)
1033 // with no template
1034 Throw<STObject::FieldErr>("Missing field: " + f.getName());
1035
1036 if (auto const u = dynamic_cast<T const*>(b))
1037 return u->value();
1038
1039 XRPL_ASSERT(
1040 mType,
1041 "ripple::STObject::at(TypedField auto) : field template non-null");
1042 XRPL_ASSERT(
1043 b->getSType() == STI_NOTPRESENT,
1044 "ripple::STObject::at(TypedField auto) : type not present");
1045
1046 if (mType->style(f) == soeOPTIONAL)
1047 Throw<STObject::FieldErr>("Missing optional field: " + f.getName());
1048
1049 XRPL_ASSERT(
1050 mType->style(f) == soeDEFAULT,
1051 "ripple::STObject::at(TypedField auto) : template style is default");
1052
1053 // Used to help handle the case where value_type is a const reference,
1054 // otherwise we would return the address of a temporary.
1055 static std::decay_t<typename T::value_type> const dv{};
1056 return dv;
1057}
1058
1059template <class T>
1062{
1063 auto const b = peekAtPField(*of.f);
1064 if (!b)
1065 return std::nullopt;
1066 auto const u = dynamic_cast<T const*>(b);
1067 if (!u)
1068 {
1069 XRPL_ASSERT(
1070 mType,
1071 "ripple::STObject::at(OptionaledField auto) : field template "
1072 "non-null");
1073 XRPL_ASSERT(
1074 b->getSType() == STI_NOTPRESENT,
1075 "ripple::STObject::at(OptionaledField auto) : type not present");
1076 if (mType->style(*of.f) == soeOPTIONAL)
1077 return std::nullopt;
1078 XRPL_ASSERT(
1079 mType->style(*of.f) == soeDEFAULT,
1080 "ripple::STObject::at(OptionaledField auto) : template style is "
1081 "default");
1082 return typename T::value_type{};
1083 }
1084 return u->value();
1085}
1086
1087template <class T>
1088inline auto
1090{
1091 return ValueProxy<T>(this, &f);
1092}
1093
1094template <class T>
1095inline auto
1097{
1098 return OptionalProxy<T>(this, of.f);
1099}
1100
1101template <class Tag>
1102void
1104{
1105 STBase* rf = getPField(field, true);
1106
1107 if (!rf)
1108 throwFieldNotFound(field);
1109
1110 if (rf->getSType() == STI_NOTPRESENT)
1111 rf = makeFieldPresent(field);
1112
1113 using Bits = STBitString<160>;
1114 if (auto cf = dynamic_cast<Bits*>(rf))
1115 cf->setValue(v);
1116 else
1117 Throw<std::runtime_error>("Wrong field type");
1118}
1119
1120inline bool
1122{
1123 return !(*this == o);
1124}
1125
1126template <typename T, typename V>
1127V
1129{
1130 STBase const* rf = peekAtPField(field);
1131
1132 if (!rf)
1133 throwFieldNotFound(field);
1134
1135 SerializedTypeID id = rf->getSType();
1136
1137 if (id == STI_NOTPRESENT)
1138 return V(); // optional field not present
1139
1140 T const* cf = dynamic_cast<T const*>(rf);
1141
1142 if (!cf)
1143 Throw<std::runtime_error>("Wrong field type");
1144
1145 return cf->value();
1146}
1147
1148// Implementations for getting (most) fields that return by const reference.
1149//
1150// If an absent optional field is deserialized we don't have anything
1151// obvious to return. So we insist on having the call provide an
1152// 'empty' value we return in that circumstance.
1153template <typename T, typename V>
1154V const&
1155STObject::getFieldByConstRef(SField const& field, V const& empty) const
1156{
1157 STBase const* rf = peekAtPField(field);
1158
1159 if (!rf)
1160 throwFieldNotFound(field);
1161
1162 SerializedTypeID id = rf->getSType();
1163
1164 if (id == STI_NOTPRESENT)
1165 return empty; // optional field not present
1166
1167 T const* cf = dynamic_cast<T const*>(rf);
1168
1169 if (!cf)
1170 Throw<std::runtime_error>("Wrong field type");
1171
1172 return *cf;
1173}
1174
1175// Implementation for setting most fields with a setValue() method.
1176template <typename T, typename V>
1177void
1179{
1180 static_assert(!std::is_lvalue_reference<V>::value, "");
1181
1182 STBase* rf = getPField(field, true);
1183
1184 if (!rf)
1185 throwFieldNotFound(field);
1186
1187 if (rf->getSType() == STI_NOTPRESENT)
1188 rf = makeFieldPresent(field);
1189
1190 T* cf = dynamic_cast<T*>(rf);
1191
1192 if (!cf)
1193 Throw<std::runtime_error>("Wrong field type");
1194
1195 cf->setValue(std::move(value));
1196}
1197
1198// Implementation for setting fields using assignment
1199template <typename T>
1200void
1201STObject::setFieldUsingAssignment(SField const& field, T const& value)
1202{
1203 STBase* rf = getPField(field, true);
1204
1205 if (!rf)
1206 throwFieldNotFound(field);
1207
1208 if (rf->getSType() == STI_NOTPRESENT)
1209 rf = makeFieldPresent(field);
1210
1211 T* cf = dynamic_cast<T*>(rf);
1212
1213 if (!cf)
1214 Throw<std::runtime_error>("Wrong field type");
1215
1216 (*cf) = value;
1217}
1218
1219// Implementation for peeking STObjects and STArrays
1220template <typename T>
1221T&
1223{
1224 STBase* rf = getPField(field, true);
1225
1226 if (!rf)
1227 throwFieldNotFound(field);
1228
1229 if (rf->getSType() == STI_NOTPRESENT)
1230 rf = makeFieldPresent(field);
1231
1232 T* cf = dynamic_cast<T*>(rf);
1233
1234 if (!cf)
1235 Throw<std::runtime_error>("Wrong field type");
1236
1237 return *cf;
1238}
1239
1240} // namespace ripple
1241
1242#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:626
friend bool operator==(OptionalProxy const &lhs, optional_type const &rhs) noexcept
Definition STObject.h:590
friend bool operator==(optional_type const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:600
friend bool operator==(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:606
optional_type operator~() const
Explicit conversion to std::optional.
Definition STObject.h:812
OptionalProxy(OptionalProxy const &)=default
value_type value_or(value_type val) const
Definition STObject.h:893
friend bool operator!=(OptionalProxy const &lhs, std::nullopt_t) noexcept
Definition STObject.h:614
friend bool operator!=(std::nullopt_t, OptionalProxy const &rhs) noexcept
Definition STObject.h:620
std::enable_if_t< std::is_assignable_v< T, U >, OptionalProxy & > operator=(U &&u)
typename T::value_type value_type
Definition STObject.h:554
OptionalProxy & operator=(OptionalProxy const &)=delete
optional_type optional_value() const
Definition STObject.h:884
std::optional< typename std::decay< value_type >::type > optional_type
Definition STObject.h:556
friend bool operator!=(optional_type const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:632
friend bool operator==(std::nullopt_t, OptionalProxy const &rhs) noexcept
Definition STObject.h:584
bool engaged() const noexcept
Definition STObject.h:864
friend bool operator!=(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:638
typename T::value_type value_type
Definition STObject.h:477
T const * find() const
Definition STObject.h:730
Proxy(Proxy const &)=default
TypedField< T > const * f_
Definition STObject.h:491
value_type value() const
Definition STObject.h:697
value_type operator*() const
Definition STObject.h:716
T const * operator->() const
Definition STObject.h:723
ValueProxy & operator-=(U const &u)
typename T::value_type value_type
Definition STObject.h:514
ValueProxy & operator+=(U const &u)
ValueProxy & operator=(ValueProxy const &)=delete
std::enable_if_t< std::is_assignable_v< T, U >, ValueProxy & > operator=(U &&u)
ValueProxy(ValueProxy const &)=default
friend bool operator==(U const &lhs, STObject::ValueProxy< T > const &rhs)
Definition STObject.h:539
STPathSet const & getFieldPathSet(SField const &field) const
Definition STObject.cpp:659
unsigned char getFieldU8(SField const &field) const
Definition STObject.cpp:584
uint192 getFieldH192(SField const &field) const
Definition STObject.cpp:620
STBase * getPField(SField const &field, bool createOkay=false)
Definition STObject.cpp:449
void setFieldIssue(SField const &field, STIssue const &)
Definition STObject.cpp:804
bool operator!=(STObject const &o) const
Definition STObject.h:1121
SOTemplate const * mType
Definition STObject.h:61
void applyTemplate(SOTemplate const &type)
Definition STObject.cpp:153
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:644
STObject getFieldObject(SField const &field) const
Definition STObject.cpp:673
boost::transform_iterator< Transform, STObject::list_type::const_iterator > iterator
Definition STObject.h:65
bool hasMatchingEntry(STBase const &)
Definition STObject.cpp:280
bool clearFlag(std::uint32_t)
Definition STObject.cpp:500
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:638
static std::vector< STBase const * > getSortedFields(STObject const &objToSort, WhichFields whichFields)
Definition STObject.cpp:916
T & peekField(SField const &field)
Definition STObject.h:1222
STArray const & getFieldArray(SField const &field) const
Definition STObject.cpp:683
uint160 getFieldH160(SField const &field) const
Definition STObject.cpp:614
void setFieldCurrency(SField const &field, STCurrency const &)
Definition STObject.cpp:798
STBase const * peekAtPField(SField const &field) const
Definition STObject.cpp:438
STBase const * peekAtPIndex(int offset) const
Definition STObject.h:987
void setFieldArray(SField const &field, STArray const &v)
Definition STObject.cpp:822
void setFieldPathSet(SField const &field, STPathSet const &)
Definition STObject.cpp:816
iterator end() const
Definition STObject.h:920
SField const & getFieldSType(int index) const
Definition STObject.cpp:432
void setFieldObject(SField const &field, STObject const &v)
Definition STObject.cpp:828
STObject(STObject const &)=default
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1028
bool isFlag(std::uint32_t) const
Definition STObject.cpp:512
std::uint16_t getFieldU16(SField const &field) const
Definition STObject.cpp:590
virtual ~STObject()=default
void setFieldH256(SField const &field, uint256 const &)
Definition STObject.cpp:756
void setFieldNumber(SField const &field, STNumber const &)
Definition STObject.cpp:810
bool setFlag(std::uint32_t)
Definition STObject.cpp:488
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:596
void setFieldI32(SField const &field, std::int32_t)
Definition STObject.cpp:762
STBase * copy(std::size_t n, void *buf) const override
Definition STObject.cpp:98
void makeFieldAbsent(SField const &field)
Definition STObject.cpp:551
STObject & peekFieldObject(SField const &field)
Definition STObject.cpp:476
int getCount() const
Definition STObject.h:969
void setFieldU16(SField const &field, std::uint16_t)
Definition STObject.cpp:732
Serializer getSerializer() const
Definition STObject.h:953
std::uint64_t getFieldU64(SField const &field) const
Definition STObject.cpp:602
STBase * makeFieldPresent(SField const &field)
Definition STObject.cpp:529
void setFieldU8(SField const &field, unsigned char)
Definition STObject.cpp:726
void set(SOTemplate const &)
Definition STObject.cpp:137
void add(Serializer &s) const override
Definition STObject.cpp:122
STObject(SOTemplate const &type, SField const &name, F &&f)
Definition STObject.h:71
void setFieldAmount(SField const &field, STAmount const &)
Definition STObject.cpp:792
bool delField(SField const &field)
Definition STObject.cpp:566
STBase const & peekAtIndex(int offset) const
Definition STObject.h:975
STBase & getField(SField const &field)
Definition STObject.cpp:421
V const & getFieldByConstRef(SField const &field, V const &empty) const
STAmount const & getFieldAmount(SField const &field) const
Definition STObject.cpp:652
std::int32_t getFieldI32(SField const &field) const
Definition STObject.cpp:632
uint256 getSigningHash(HashPrefix prefix) const
Definition STObject.cpp:385
T::value_type operator[](TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1000
uint256 getHash(HashPrefix prefix) const
Definition STObject.cpp:376
int getFieldIndex(SField const &field) const
Definition STObject.cpp:394
STBase & getIndex(int offset)
Definition STObject.h:981
ValueProxy< T > operator[](TypedField< T > const &f)
Get a modifiable field value.
bool isFree() const
Definition STObject.h:938
void setFieldUsingAssignment(SField const &field, T const &value)
Definition STObject.h:1201
list_type v_
Definition STObject.h:60
bool empty() const
Definition STObject.h:926
SerializedTypeID getSType() const override
Definition STObject.cpp:110
std::string getFullText() const override
Definition STObject.cpp:291
std::string getText() const override
Definition STObject.cpp:322
iterator begin() const
Definition STObject.h:914
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:465
static STObject makeInnerObject(SField const &name)
Definition STObject.cpp:76
STCurrency const & getFieldCurrency(SField const &field) const
Definition STObject.cpp:690
bool operator==(STObject const &o) const
Definition STObject.cpp:847
void setAccountID(SField const &field, AccountID const &)
Definition STObject.cpp:774
uint128 getFieldH128(SField const &field) const
Definition STObject.cpp:608
void applyTemplateFromSField(SField const &)
Definition STObject.cpp:207
OptionalProxy< T > at(OptionaledField< T > const &of)
Return a modifiable field value as std::optional.
ValueProxy< T > at(TypedField< T > const &f)
Get a modifiable field value.
void setFieldV256(SField const &field, STVector256 const &v)
Definition STObject.cpp:768
void setFieldUsingSetValue(SField const &field, V value)
Definition STObject.h:1178
Json::Value getJson(JsonOptions=JsonOptions::none) const override
Definition STObject.cpp:834
void setFieldH128(SField const &field, uint128 const &)
Definition STObject.cpp:750
void setFieldU64(SField const &field, std::uint64_t)
Definition STObject.cpp:744
bool isEquivalent(STBase const &t) const override
Definition STObject.cpp:341
void setFieldU32(SField const &field, std::uint32_t)
Definition STObject.cpp:738
STBase const & peekAtField(SField const &field) const
Definition STObject.cpp:410
V getFieldByValue(SField const &field) const
STBase * move(std::size_t n, void *buf) override
Definition STObject.cpp:104
OptionalProxy< T > operator[](OptionaledField< T > const &of)
Return a modifiable field value as std::optional.
std::size_t emplace_back(Args &&... args)
Definition STObject.h:962
STBase * getPIndex(int offset)
Definition STObject.h:993
STArray & peekFieldArray(SField const &field)
Definition STObject.cpp:482
STNumber const & getFieldNumber(SField const &field) const
Definition STObject.cpp:697
void reserve(std::size_t n)
Definition STObject.h:932
STObject & operator=(STObject const &)=default
void addWithoutSigningFields(Serializer &s) const
Definition STObject.h:944
void setFieldVL(SField const &field, Blob const &)
Definition STObject.cpp:780
std::uint32_t getFlags() const
Definition STObject.cpp:518
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:626
void setFieldH160(SField const &field, base_uint< 160, Tag > const &v)
Definition STObject.h:1103
STVector256 const & getFieldV256(SField const &field) const
Definition STObject.cpp:666
bool isDefault() const override
Definition STObject.cpp:116
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
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
SerializedTypeID
Definition SField.h:91
Number operator*(Number const &x, Number const &y)
Definition Number.h:289
HashPrefix
Prefix for hashing functions.
Definition HashPrefix.h:36
SOEStyle
Kind of element in each entry of an SOTemplate.
Definition SOTemplate.h:14
@ soeOPTIONAL
Definition SOTemplate.h:17
@ soeREQUIRED
Definition SOTemplate.h:16
@ soeDEFAULT
Definition SOTemplate.h:18
@ soeINVALID
Definition SOTemplate.h:15
void throwFieldNotFound(SField const &field)
Definition STObject.h:32
STL namespace.
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:901
A field with a type known at compile time.
Definition SField.h:301