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
401 getStyle(SField const& field) const;
402
403 bool
404 hasMatchingEntry(STBase const&);
405
406 bool
407 operator==(STObject const& o) const;
408 bool
409 operator!=(STObject const& o) const;
410
411 class FieldErr;
412
413private:
414 enum WhichFields : bool {
415 // These values are carefully chosen to do the right thing if passed
416 // to SField::shouldInclude (bool)
418 withAllFields = true
419 };
420
421 void
422 add(Serializer& s, WhichFields whichFields) const;
423
424 // Sort the entries in an STObject into the order that they will be
425 // serialized. Note: they are not sorted into pointer value order, they
426 // are sorted by SField::fieldCode.
428 getSortedFields(STObject const& objToSort, WhichFields whichFields);
429
430 // Implementation for getting (most) fields that return by value.
431 //
432 // The remove_cv and remove_reference are necessitated by the STBitString
433 // types. Their value() returns by const ref. We return those types
434 // by value.
435 template <
436 typename T,
437 typename V = typename std::remove_cv<typename std::remove_reference<
438 decltype(std::declval<T>().value())>::type>::type>
439 V
440 getFieldByValue(SField const& field) const;
441
442 // Implementations for getting (most) fields that return by const reference.
443 //
444 // If an absent optional field is deserialized we don't have anything
445 // obvious to return. So we insist on having the call provide an
446 // 'empty' value we return in that circumstance.
447 template <typename T, typename V>
448 V const&
449 getFieldByConstRef(SField const& field, V const& empty) const;
450
451 // Implementation for setting most fields with a setValue() method.
452 template <typename T, typename V>
453 void
454 setFieldUsingSetValue(SField const& field, V value);
455
456 // Implementation for setting fields using assignment
457 template <typename T>
458 void
459 setFieldUsingAssignment(SField const& field, T const& value);
460
461 // Implementation for peeking STObjects and STArrays
462 template <typename T>
463 T&
464 peekField(SField const& field);
465
466 STBase*
467 copy(std::size_t n, void* buf) const override;
468 STBase*
469 move(std::size_t n, void* buf) override;
470
471 friend class detail::STVar;
472};
473
474//------------------------------------------------------------------------------
475
476template <class T>
478{
479public:
480 using value_type = typename T::value_type;
481
483 value() const;
484
486 operator*() const;
487
490 T const*
491 operator->() const;
492
493protected:
497
498 Proxy(Proxy const&) = default;
499
500 Proxy(STObject* st, TypedField<T> const* f);
501
502 T const*
503 find() const;
504
505 template <class U>
506 void
507 assign(U&& u);
508};
509
510// Constraint += and -= ValueProxy operators
511// to value types that support arithmetic operations
512template <typename U>
515template <
516 typename U,
517 typename Value = typename U::value_type,
518 typename Unit = typename U::unit_type>
522template <typename U, typename Value = typename U::value_type>
524template <typename U>
527
528template <class T, class U>
529concept Addable = requires(T t, U u) { t = t + u; };
530template <typename T, typename U>
533
534template <class T>
536{
537private:
538 using value_type = typename T::value_type;
539
540public:
541 ValueProxy(ValueProxy const&) = default;
543 operator=(ValueProxy const&) = delete;
544
545 template <class U>
547 operator=(U&& u);
548
549 // Convenience operators for value types supporting
550 // arithmetic operations
551 template <IsArithmetic U>
554 operator+=(U const& u);
555
556 template <IsArithmetic U>
559 operator-=(U const& u);
560
561 operator value_type() const;
562
563 template <typename U>
564 friend bool
565 operator==(U const& lhs, STObject::ValueProxy<T> const& rhs)
566 {
567 return rhs.value() == lhs;
568 }
569
570private:
571 friend class STObject;
572
573 ValueProxy(STObject* st, TypedField<T> const* f);
574};
575
576template <class T>
578{
579private:
580 using value_type = typename T::value_type;
581
583
584public:
585 OptionalProxy(OptionalProxy const&) = default;
587 operator=(OptionalProxy const&) = delete;
588
594 explicit
595 operator bool() const noexcept;
596
597 operator optional_type() const;
598
601 operator~() const;
602
603 friend bool
604 operator==(OptionalProxy const& lhs, std::nullopt_t) noexcept
605 {
606 return !lhs.engaged();
607 }
608
609 friend bool
611 {
612 return rhs == std::nullopt;
613 }
614
615 friend bool
616 operator==(OptionalProxy const& lhs, optional_type const& rhs) noexcept
617 {
618 if (!lhs.engaged())
619 return !rhs;
620 if (!rhs)
621 return false;
622 return *lhs == *rhs;
623 }
624
625 friend bool
626 operator==(optional_type const& lhs, OptionalProxy const& rhs) noexcept
627 {
628 return rhs == lhs;
629 }
630
631 friend bool
632 operator==(OptionalProxy const& lhs, OptionalProxy const& rhs) noexcept
633 {
634 if (lhs.engaged() != rhs.engaged())
635 return false;
636 return !lhs.engaged() || *lhs == *rhs;
637 }
638
639 friend bool
641 {
642 return !(lhs == std::nullopt);
643 }
644
645 friend bool
647 {
648 return !(rhs == std::nullopt);
649 }
650
651 friend bool
652 operator!=(OptionalProxy const& lhs, optional_type const& rhs) noexcept
653 {
654 return !(lhs == rhs);
655 }
656
657 friend bool
658 operator!=(optional_type const& lhs, OptionalProxy const& rhs) noexcept
659 {
660 return !(lhs == rhs);
661 }
662
663 friend bool
664 operator!=(OptionalProxy const& lhs, OptionalProxy const& rhs) noexcept
665 {
666 return !(lhs == rhs);
667 }
668
669 // Emulate std::optional::value_or
671 value_or(value_type val) const;
672
678 operator=(optional_type const& v);
679
680 template <class U>
682 operator=(U&& u);
683
684private:
685 friend class STObject;
686
687 OptionalProxy(STObject* st, TypedField<T> const* f);
688
689 bool
690 engaged() const noexcept;
691
692 void
693 disengage();
694
696 optional_value() const;
697};
698
699class STObject::FieldErr : public std::runtime_error
700{
702};
703
704template <class T>
706{
707 if (st_->mType)
708 {
709 // STObject has associated template
710 if (!st_->peekAtPField(*f_))
711 Throw<STObject::FieldErr>(
712 "Template field error '" + this->f_->getName() + "'");
713 style_ = st_->mType->style(*f_);
714 }
715 else
716 {
718 }
719}
720
721template <class T>
722auto
724{
725 auto const t = find();
726 if (t)
727 return t->value();
728 if (style_ == soeINVALID)
729 {
730 Throw<STObject::FieldErr>("Value requested from invalid STObject.");
731 }
732 if (style_ != soeDEFAULT)
733 {
734 Throw<STObject::FieldErr>(
735 "Missing field '" + this->f_->getName() + "'");
736 }
737 return value_type{};
738}
739
740template <class T>
741auto
743{
744 return this->value();
745}
746
749template <class T>
750T const*
752{
753 return this->find();
754}
755
756template <class T>
757inline T const*
759{
760 return dynamic_cast<T const*>(st_->peekAtPField(*f_));
761}
762
763template <class T>
764template <class U>
765void
767{
768 if (style_ == soeDEFAULT && u == value_type{})
769 {
770 st_->makeFieldAbsent(*f_);
771 return;
772 }
773 T* t;
774 if (style_ == soeINVALID)
775 t = dynamic_cast<T*>(st_->getPField(*f_, true));
776 else
777 t = dynamic_cast<T*>(st_->makeFieldPresent(*f_));
778 XRPL_ASSERT(t, "xrpl::STObject::Proxy::assign : type cast succeeded");
779 *t = std::forward<U>(u);
780}
781
782//------------------------------------------------------------------------------
783
784template <class T>
785template <class U>
788{
789 this->assign(std::forward<U>(u));
790 return *this;
791}
792
793template <typename T>
794template <IsArithmetic U>
798{
799 this->assign(this->value() + u);
800 return *this;
801}
802
803template <class T>
804template <IsArithmetic U>
808{
809 this->assign(this->value() - u);
810 return *this;
811}
812
813template <class T>
815{
816 return this->value();
817}
818
819template <class T>
821 : Proxy<T>(st, f)
822{
823}
824
825//------------------------------------------------------------------------------
826
827template <class T>
829{
830 return engaged();
831}
832
833template <class T>
835 T>::optional_type() const
836{
837 return optional_value();
838}
839
840template <class T>
843{
844 return optional_value();
845}
846
847template <class T>
848auto
850{
851 disengage();
852 return *this;
853}
854
855template <class T>
856auto
858{
859 if (v)
860 this->assign(std::move(*v));
861 else
862 disengage();
863 return *this;
864}
865
866template <class T>
867auto
869{
870 if (v)
871 this->assign(*v);
872 else
873 disengage();
874 return *this;
875}
876
877template <class T>
878template <class U>
881{
882 this->assign(std::forward<U>(u));
883 return *this;
884}
885
886template <class T>
891
892template <class T>
893bool
895{
896 return this->style_ == soeDEFAULT || this->find() != nullptr;
897}
898
899template <class T>
900void
902{
903 if (this->style_ == soeREQUIRED || this->style_ == soeDEFAULT)
904 Throw<STObject::FieldErr>(
905 "Template field error '" + this->f_->getName() + "'");
906 if (this->style_ == soeINVALID)
907 this->st_->delField(*this->f_);
908 else
909 this->st_->makeFieldAbsent(*this->f_);
910}
911
912template <class T>
913auto
915{
916 if (!engaged())
917 return std::nullopt;
918 return this->value();
919}
920
921template <class T>
924{
925 return engaged() ? this->value() : val;
926}
927
928//------------------------------------------------------------------------------
929
930inline STBase const&
932{
933 return e.get();
934}
935
936//------------------------------------------------------------------------------
937
938inline STObject::STObject(SerialIter&& sit, SField const& name)
939 : STObject(sit, name)
940{
941}
942
945{
946 return iterator(v_.begin());
947}
948
951{
952 return iterator(v_.end());
953}
954
955inline bool
957{
958 return v_.empty();
959}
960
961inline void
966
967inline bool
969{
970 return mType == nullptr;
971}
972
973inline void
978
979// VFALCO NOTE does this return an expensive copy of an object with a
980// dynamic buffer?
981// VFALCO TODO Remove this function and fix the few callers.
982inline Serializer
984{
985 Serializer s;
986 add(s, withAllFields);
987 return s;
988}
989
990template <class... Args>
991inline std::size_t
993{
995 return v_.size() - 1;
996}
997
998inline int
1000{
1001 return v_.size();
1002}
1003
1004inline STBase const&
1005STObject::peekAtIndex(int offset) const
1006{
1007 return v_[offset].get();
1008}
1009
1010inline STBase&
1012{
1013 return v_[offset].get();
1014}
1015
1016inline STBase const*
1017STObject::peekAtPIndex(int offset) const
1018{
1019 return &v_[offset].get();
1020}
1021
1022inline STBase*
1024{
1025 return &v_[offset].get();
1026}
1027
1028template <class T>
1029typename T::value_type
1031{
1032 return at(f);
1033}
1034
1035template <class T>
1038{
1039 return at(of);
1040}
1041
1042template <class T>
1043inline auto
1045{
1046 return at(f);
1047}
1048
1049template <class T>
1050inline auto
1052{
1053 return at(of);
1054}
1055
1056template <class T>
1057typename T::value_type
1059{
1060 auto const b = peekAtPField(f);
1061 if (!b)
1062 // This is a free object (no constraints)
1063 // with no template
1064 Throw<STObject::FieldErr>("Missing field: " + f.getName());
1065
1066 if (auto const u = dynamic_cast<T const*>(b))
1067 return u->value();
1068
1069 XRPL_ASSERT(
1070 mType, "xrpl::STObject::at(TypedField auto) : field template non-null");
1071 XRPL_ASSERT(
1072 b->getSType() == STI_NOTPRESENT,
1073 "xrpl::STObject::at(TypedField auto) : type not present");
1074
1075 if (mType->style(f) == soeOPTIONAL)
1076 Throw<STObject::FieldErr>("Missing optional field: " + f.getName());
1077
1078 XRPL_ASSERT(
1079 mType->style(f) == soeDEFAULT,
1080 "xrpl::STObject::at(TypedField auto) : template style is default");
1081
1082 // Used to help handle the case where value_type is a const reference,
1083 // otherwise we would return the address of a temporary.
1084 static std::decay_t<typename T::value_type> const dv{};
1085 return dv;
1086}
1087
1088template <class T>
1091{
1092 auto const b = peekAtPField(*of.f);
1093 if (!b)
1094 return std::nullopt;
1095 auto const u = dynamic_cast<T const*>(b);
1096 if (!u)
1097 {
1098 XRPL_ASSERT(
1099 mType,
1100 "xrpl::STObject::at(OptionaledField auto) : field template "
1101 "non-null");
1102 XRPL_ASSERT(
1103 b->getSType() == STI_NOTPRESENT,
1104 "xrpl::STObject::at(OptionaledField auto) : type not present");
1105 if (mType->style(*of.f) == soeOPTIONAL)
1106 return std::nullopt;
1107 XRPL_ASSERT(
1108 mType->style(*of.f) == soeDEFAULT,
1109 "xrpl::STObject::at(OptionaledField auto) : template style is "
1110 "default");
1111 return typename T::value_type{};
1112 }
1113 return u->value();
1114}
1115
1116template <class T>
1117inline auto
1119{
1120 return ValueProxy<T>(this, &f);
1121}
1122
1123template <class T>
1124inline auto
1126{
1127 return OptionalProxy<T>(this, of.f);
1128}
1129
1130template <class Tag>
1131void
1133{
1134 STBase* rf = getPField(field, true);
1135
1136 if (!rf)
1137 throwFieldNotFound(field);
1138
1139 if (rf->getSType() == STI_NOTPRESENT)
1140 rf = makeFieldPresent(field);
1141
1142 using Bits = STBitString<160>;
1143 if (auto cf = dynamic_cast<Bits*>(rf))
1144 cf->setValue(v);
1145 else
1146 Throw<std::runtime_error>("Wrong field type");
1147}
1148
1149inline bool
1151{
1152 return !(*this == o);
1153}
1154
1155template <typename T, typename V>
1156V
1158{
1159 STBase const* rf = peekAtPField(field);
1160
1161 if (!rf)
1162 throwFieldNotFound(field);
1163
1164 SerializedTypeID id = rf->getSType();
1165
1166 if (id == STI_NOTPRESENT)
1167 return V(); // optional field not present
1168
1169 T const* cf = dynamic_cast<T const*>(rf);
1170
1171 if (!cf)
1172 Throw<std::runtime_error>("Wrong field type");
1173
1174 return cf->value();
1175}
1176
1177// Implementations for getting (most) fields that return by const reference.
1178//
1179// If an absent optional field is deserialized we don't have anything
1180// obvious to return. So we insist on having the call provide an
1181// 'empty' value we return in that circumstance.
1182template <typename T, typename V>
1183V const&
1184STObject::getFieldByConstRef(SField const& field, V const& empty) const
1185{
1186 STBase const* rf = peekAtPField(field);
1187
1188 if (!rf)
1189 throwFieldNotFound(field);
1190
1191 SerializedTypeID id = rf->getSType();
1192
1193 if (id == STI_NOTPRESENT)
1194 return empty; // optional field not present
1195
1196 T const* cf = dynamic_cast<T const*>(rf);
1197
1198 if (!cf)
1199 Throw<std::runtime_error>("Wrong field type");
1200
1201 return *cf;
1202}
1203
1204// Implementation for setting most fields with a setValue() method.
1205template <typename T, typename V>
1206void
1208{
1209 static_assert(!std::is_lvalue_reference<V>::value, "");
1210
1211 STBase* rf = getPField(field, true);
1212
1213 if (!rf)
1214 throwFieldNotFound(field);
1215
1216 if (rf->getSType() == STI_NOTPRESENT)
1217 rf = makeFieldPresent(field);
1218
1219 T* cf = dynamic_cast<T*>(rf);
1220
1221 if (!cf)
1222 Throw<std::runtime_error>("Wrong field type");
1223
1224 cf->setValue(std::move(value));
1225}
1226
1227// Implementation for setting fields using assignment
1228template <typename T>
1229void
1230STObject::setFieldUsingAssignment(SField const& field, T const& value)
1231{
1232 STBase* rf = getPField(field, true);
1233
1234 if (!rf)
1235 throwFieldNotFound(field);
1236
1237 if (rf->getSType() == STI_NOTPRESENT)
1238 rf = makeFieldPresent(field);
1239
1240 T* cf = dynamic_cast<T*>(rf);
1241
1242 if (!cf)
1243 Throw<std::runtime_error>("Wrong field type");
1244
1245 (*cf) = value;
1246}
1247
1248// Implementation for peeking STObjects and STArrays
1249template <typename T>
1250T&
1252{
1253 STBase* rf = getPField(field, true);
1254
1255 if (!rf)
1256 throwFieldNotFound(field);
1257
1258 if (rf->getSType() == STI_NOTPRESENT)
1259 rf = makeFieldPresent(field);
1260
1261 T* cf = dynamic_cast<T*>(rf);
1262
1263 if (!cf)
1264 Throw<std::runtime_error>("Wrong field type");
1265
1266 return *cf;
1267}
1268
1269} // namespace xrpl
1270
1271#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:195
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:36
friend bool operator!=(OptionalProxy const &lhs, optional_type const &rhs) noexcept
Definition STObject.h:652
friend bool operator==(OptionalProxy const &lhs, optional_type const &rhs) noexcept
Definition STObject.h:616
friend bool operator==(optional_type const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:626
friend bool operator==(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:632
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:842
std::optional< typename std::decay< value_type >::type > optional_type
Definition STObject.h:582
typename T::value_type value_type
Definition STObject.h:580
friend bool operator!=(OptionalProxy const &lhs, std::nullopt_t) noexcept
Definition STObject.h:640
friend bool operator!=(std::nullopt_t, OptionalProxy const &rhs) noexcept
Definition STObject.h:646
OptionalProxy & operator=(OptionalProxy const &)=delete
bool engaged() const noexcept
Definition STObject.h:894
friend bool operator!=(optional_type const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:658
friend bool operator==(std::nullopt_t, OptionalProxy const &rhs) noexcept
Definition STObject.h:610
value_type value_or(value_type val) const
Definition STObject.h:923
optional_type optional_value() const
Definition STObject.h:914
friend bool operator!=(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
Definition STObject.h:664
void assign(U &&u)
Definition STObject.h:766
Proxy(Proxy const &)=default
value_type operator*() const
Definition STObject.h:742
T const * operator->() const
Do not use operator->() unless the field is required, or you've checked that it's set.
Definition STObject.h:751
value_type value() const
Definition STObject.h:723
T const * find() const
Definition STObject.h:758
typename T::value_type value_type
Definition STObject.h:480
TypedField< T > const * f_
Definition STObject.h:496
ValueProxy(ValueProxy const &)=default
ValueProxy & operator=(ValueProxy const &)=delete
typename T::value_type value_type
Definition STObject.h:538
ValueProxy & operator+=(U const &u)
ValueProxy & operator-=(U const &u)
friend bool operator==(U const &lhs, STObject::ValueProxy< T > const &rhs)
Definition STObject.h:565
std::enable_if_t< std::is_assignable_v< T, U >, ValueProxy & > operator=(U &&u)
void setFieldU8(SField const &field, unsigned char)
Definition STObject.cpp:732
SField const & getFieldSType(int index) const
Definition STObject.cpp:432
uint192 getFieldH192(SField const &field) const
Definition STObject.cpp:626
bool isFree() const
Definition STObject.h:968
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1058
STBase const * peekAtPIndex(int offset) const
Definition STObject.h:1017
Json::Value getJson(JsonOptions=JsonOptions::none) const override
Definition STObject.cpp:840
STCurrency const & getFieldCurrency(SField const &field) const
Definition STObject.cpp:696
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:650
void addWithoutSigningFields(Serializer &s) const
Definition STObject.h:974
void setFieldIssue(SField const &field, STIssue const &)
Definition STObject.cpp:810
uint128 getFieldH128(SField const &field) const
Definition STObject.cpp:614
iterator begin() const
Definition STObject.h:944
bool operator==(STObject const &o) const
Definition STObject.cpp:853
bool isEquivalent(STBase const &t) const override
Definition STObject.cpp:341
bool empty() const
Definition STObject.h:956
void setFieldNumber(SField const &field, STNumber const &)
Definition STObject.cpp:816
void setFieldV256(SField const &field, STVector256 const &v)
Definition STObject.cpp:774
void setFieldU64(SField const &field, std::uint64_t)
Definition STObject.cpp:750
unsigned char getFieldU8(SField const &field) const
Definition STObject.cpp:590
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:602
STBase const & peekAtIndex(int offset) const
Definition STObject.h:1005
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:703
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:786
void reserve(std::size_t n)
Definition STObject.h:962
T::value_type operator[](TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1030
std::size_t emplace_back(Args &&... args)
Definition STObject.h:992
boost::transform_iterator< Transform, STObject::list_type::const_iterator > iterator
Definition STObject.h:65
iterator end() const
Definition STObject.h:950
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:768
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:744
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:689
void setFieldArray(SField const &field, STArray const &v)
Definition STObject.cpp:828
STObject & peekFieldObject(SField const &field)
Definition STObject.cpp:476
SOEStyle getStyle(SField const &field) const
Definition STObject.cpp:584
STBase & getField(SField const &field)
Definition STObject.cpp:421
void setFieldAmount(SField const &field, STAmount const &)
Definition STObject.cpp:798
void add(Serializer &s) const override
Definition STObject.cpp:122
Serializer getSerializer() const
Definition STObject.h:983
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:999
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:738
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:632
static STObject makeInnerObject(SField const &name)
Definition STObject.cpp:76
std::int32_t getFieldI32(SField const &field) const
Definition STObject.cpp:638
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:804
std::uint64_t getFieldU64(SField const &field) const
Definition STObject.cpp:608
void setFieldPathSet(SField const &field, STPathSet const &)
Definition STObject.cpp:822
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:922
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:834
bool operator!=(STObject const &o) const
Definition STObject.h:1150
void setFieldH128(SField const &field, uint128 const &)
Definition STObject.cpp:756
STObject getFieldObject(SField const &field) const
Definition STObject.cpp:679
T & peekField(SField const &field)
Definition STObject.h:1251
void setFieldH160(SField const &field, base_uint< 160, Tag > const &v)
Definition STObject.h:1132
void setFieldUsingSetValue(SField const &field, V value)
Definition STObject.h:1207
void setAccountID(SField const &field, AccountID const &)
Definition STObject.cpp:780
void setFieldUsingAssignment(SField const &field, T const &value)
Definition STObject.h:1230
bool delField(SField const &field)
Definition STObject.cpp:566
STBase & getIndex(int offset)
Definition STObject.h:1011
uint160 getFieldH160(SField const &field) const
Definition STObject.cpp:620
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:644
STBase * getPIndex(int offset)
Definition STObject.h:1023
STVector256 const & getFieldV256(SField const &field) const
Definition STObject.cpp:672
STPathSet const & getFieldPathSet(SField const &field) const
Definition STObject.cpp:665
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:762
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:596
STAmount const & getFieldAmount(SField const &field) const
Definition STObject.cpp:658
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:675
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:314
TypedField< T > const * f
Definition SField.h:315
STBase const & operator()(detail::STVar const &e) const
Definition STObject.h:931
A field with a type known at compile time.
Definition SField.h:304