rippled
STObject.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_PROTOCOL_STOBJECT_H_INCLUDED
21 #define RIPPLE_PROTOCOL_STOBJECT_H_INCLUDED
22 
23 #include <ripple/basics/CountedObject.h>
24 #include <ripple/basics/FeeUnits.h>
25 #include <ripple/basics/Slice.h>
26 #include <ripple/basics/chrono.h>
27 #include <ripple/basics/contract.h>
28 #include <ripple/protocol/HashPrefix.h>
29 #include <ripple/protocol/SOTemplate.h>
30 #include <ripple/protocol/STAmount.h>
31 #include <ripple/protocol/STPathSet.h>
32 #include <ripple/protocol/STVector256.h>
33 #include <ripple/protocol/impl/STVar.h>
34 #include <boost/iterator/transform_iterator.hpp>
35 #include <cassert>
36 #include <optional>
37 #include <stdexcept>
38 #include <type_traits>
39 #include <utility>
40 
41 namespace ripple {
42 
43 class STArray;
44 
45 inline void
47 {
48  Throw<std::runtime_error>("Field not found: " + field.getName());
49 }
50 
51 class STObject : public STBase, public CountedObject<STObject>
52 {
53  // Proxy value for a STBase derived class
54  template <class T>
55  class Proxy;
56  template <class T>
57  class ValueProxy;
58  template <class T>
60 
61  struct Transform
62  {
63  explicit Transform() = default;
64 
67 
68  STBase const&
69  operator()(detail::STVar const& e) const;
70  };
71 
73 
75  SOTemplate const* mType;
76 
77 public:
78  using iterator = boost::
79  transform_iterator<Transform, STObject::list_type::const_iterator>;
80 
81  virtual ~STObject() = default;
82  STObject(STObject const&) = default;
83  STObject&
84  operator=(STObject const&) = default;
85  STObject(STObject&&);
86  STObject&
87  operator=(STObject&& other);
88 
89  STObject(const SOTemplate& type, SField const& name);
90  STObject(const SOTemplate& type, SerialIter& sit, SField const& name);
91  STObject(SerialIter& sit, SField const& name, int depth = 0);
92  STObject(SerialIter&& sit, SField const& name);
93  explicit STObject(SField const& name);
94 
95  iterator
96  begin() const;
97 
98  iterator
99  end() const;
100 
101  bool
102  empty() const;
103 
104  void
105  reserve(std::size_t n);
106 
107  void
108  applyTemplate(const SOTemplate& type);
109 
110  void
112 
113  bool
114  isFree() const;
115 
116  void
117  set(const SOTemplate&);
118 
119  bool
120  set(SerialIter& u, int depth = 0);
121 
123  getSType() const override;
124 
125  bool
126  isEquivalent(const STBase& t) const override;
127 
128  bool
129  isDefault() const override;
130 
131  void
132  add(Serializer& s) const override;
133 
135  getFullText() const override;
136 
138  getText() const override;
139 
140  // TODO(tom): options should be an enum.
142  getJson(JsonOptions options) const override;
143 
144  void
146 
147  Serializer
148  getSerializer() const;
149 
150  template <class... Args>
152  emplace_back(Args&&... args);
153 
154  int
155  getCount() const;
156 
157  bool setFlag(std::uint32_t);
158  bool clearFlag(std::uint32_t);
159  bool isFlag(std::uint32_t) const;
160 
162  getFlags() const;
163 
164  uint256
165  getHash(HashPrefix prefix) const;
166 
167  uint256
168  getSigningHash(HashPrefix prefix) const;
169 
170  const STBase&
171  peekAtIndex(int offset) const;
172 
173  STBase&
174  getIndex(int offset);
175 
176  const STBase*
177  peekAtPIndex(int offset) const;
178 
179  STBase*
180  getPIndex(int offset);
181 
182  int
183  getFieldIndex(SField const& field) const;
184 
185  SField const&
186  getFieldSType(int index) const;
187 
188  const STBase&
189  peekAtField(SField const& field) const;
190 
191  STBase&
192  getField(SField const& field);
193 
194  const STBase*
195  peekAtPField(SField const& field) const;
196 
197  STBase*
198  getPField(SField const& field, bool createOkay = false);
199 
200  // these throw if the field type doesn't match, or return default values
201  // if the field is optional but not present
202  unsigned char
203  getFieldU8(SField const& field) const;
205  getFieldU16(SField const& field) const;
207  getFieldU32(SField const& field) const;
209  getFieldU64(SField const& field) const;
210  uint128
211  getFieldH128(SField const& field) const;
212 
213  uint160
214  getFieldH160(SField const& field) const;
215  uint256
216  getFieldH256(SField const& field) const;
217  AccountID
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  const STVector256&
227  getFieldV256(SField const& field) const;
228  const STArray&
229  getFieldArray(SField const& field) const;
230 
238  template <class T>
239  typename T::value_type
240  operator[](TypedField<T> const& f) const;
241 
250  template <class T>
252  operator[](OptionaledField<T> const& of) const;
253 
261  template <class T>
263  operator[](TypedField<T> const& f);
264 
274  template <class T>
276  operator[](OptionaledField<T> const& of);
277 
285  template <class T>
286  typename T::value_type
287  at(TypedField<T> const& f) const;
288 
297  template <class T>
299  at(OptionaledField<T> const& of) const;
300 
308  template <class T>
310  at(TypedField<T> const& f);
311 
321  template <class T>
323  at(OptionaledField<T> const& of);
324 
328  void
330 
331  void
332  set(STBase* v);
333 
334  void
335  setFieldU8(SField const& field, unsigned char);
336  void
337  setFieldU16(SField const& field, std::uint16_t);
338  void
339  setFieldU32(SField const& field, std::uint32_t);
340  void
341  setFieldU64(SField const& field, std::uint64_t);
342  void
343  setFieldH128(SField const& field, uint128 const&);
344  void
345  setFieldH256(SField const& field, uint256 const&);
346  void
347  setFieldVL(SField const& field, Blob const&);
348  void
349  setFieldVL(SField const& field, Slice const&);
350 
351  void
352  setAccountID(SField const& field, AccountID const&);
353 
354  void
355  setFieldAmount(SField const& field, STAmount const&);
356  void
357  setFieldPathSet(SField const& field, STPathSet const&);
358  void
359  setFieldV256(SField const& field, STVector256 const& v);
360  void
361  setFieldArray(SField const& field, STArray const& v);
362 
363  template <class Tag>
364  void
365  setFieldH160(SField const& field, base_uint<160, Tag> const& v);
366 
367  STObject&
368  peekFieldObject(SField const& field);
369  STArray&
370  peekFieldArray(SField const& field);
371 
372  bool
373  isFieldPresent(SField const& field) const;
374  STBase*
375  makeFieldPresent(SField const& field);
376  void
377  makeFieldAbsent(SField const& field);
378  bool
379  delField(SField const& field);
380  void
381  delField(int index);
382 
383  bool
384  hasMatchingEntry(const STBase&);
385 
386  bool
387  operator==(const STObject& o) const;
388  bool
389  operator!=(const STObject& o) const;
390 
391  class FieldErr;
392 
393 private:
394  enum WhichFields : bool {
395  // These values are carefully chosen to do the right thing if passed
396  // to SField::shouldInclude (bool)
399  };
400 
401  void
402  add(Serializer& s, WhichFields whichFields) const;
403 
404  // Sort the entries in an STObject into the order that they will be
405  // serialized. Note: they are not sorted into pointer value order, they
406  // are sorted by SField::fieldCode.
408  getSortedFields(STObject const& objToSort, WhichFields whichFields);
409 
410  // Implementation for getting (most) fields that return by value.
411  //
412  // The remove_cv and remove_reference are necessitated by the STBitString
413  // types. Their value() returns by const ref. We return those types
414  // by value.
415  template <
416  typename T,
417  typename V = typename std::remove_cv<typename std::remove_reference<
418  decltype(std::declval<T>().value())>::type>::type>
419  V
420  getFieldByValue(SField const& field) const;
421 
422  // Implementations for getting (most) fields that return by const reference.
423  //
424  // If an absent optional field is deserialized we don't have anything
425  // obvious to return. So we insist on having the call provide an
426  // 'empty' value we return in that circumstance.
427  template <typename T, typename V>
428  V const&
429  getFieldByConstRef(SField const& field, V const& empty) const;
430 
431  // Implementation for setting most fields with a setValue() method.
432  template <typename T, typename V>
433  void
434  setFieldUsingSetValue(SField const& field, V value);
435 
436  // Implementation for setting fields using assignment
437  template <typename T>
438  void
439  setFieldUsingAssignment(SField const& field, T const& value);
440 
441  // Implementation for peeking STObjects and STArrays
442  template <typename T>
443  T&
444  peekField(SField const& field);
445 
446  STBase*
447  copy(std::size_t n, void* buf) const override;
448  STBase*
449  move(std::size_t n, void* buf) override;
450 
451  friend class detail::STVar;
452 };
453 
454 //------------------------------------------------------------------------------
455 
456 template <class T>
457 class STObject::Proxy
458 {
459 protected:
460  using value_type = typename T::value_type;
461 
465 
466  Proxy(Proxy const&) = default;
467 
468  Proxy(STObject* st, TypedField<T> const* f);
469 
470  value_type
471  value() const;
472 
473  T const*
474  find() const;
475 
476  template <class U>
477  void
478  assign(U&& u);
479 };
480 
481 template <class T>
482 class STObject::ValueProxy : private Proxy<T>
483 {
484 private:
485  using value_type = typename T::value_type;
486 
487 public:
488  ValueProxy(ValueProxy const&) = default;
489  ValueProxy&
490  operator=(ValueProxy const&) = delete;
491 
492  template <class U>
494  operator=(U&& u);
495 
496  operator value_type() const;
497 
498 private:
499  friend class STObject;
500 
501  ValueProxy(STObject* st, TypedField<T> const* f);
502 };
503 
504 template <class T>
505 class STObject::OptionalProxy : private Proxy<T>
506 {
507 private:
508  using value_type = typename T::value_type;
509 
511 
512 public:
513  OptionalProxy(OptionalProxy const&) = default;
515  operator=(OptionalProxy const&) = delete;
516 
522  explicit operator bool() const noexcept;
523 
530  value_type
531  operator*() const;
532 
533  operator optional_type() const;
534 
537  operator~() const;
538 
539  friend bool
540  operator==(OptionalProxy const& lhs, std::nullopt_t) noexcept
541  {
542  return !lhs.engaged();
543  }
544 
545  friend bool
547  {
548  return rhs == std::nullopt;
549  }
550 
551  friend bool
552  operator==(OptionalProxy const& lhs, optional_type const& rhs) noexcept
553  {
554  if (!lhs.engaged())
555  return !rhs;
556  if (!rhs)
557  return false;
558  return *lhs == *rhs;
559  }
560 
561  friend bool
562  operator==(optional_type const& lhs, OptionalProxy const& rhs) noexcept
563  {
564  return rhs == lhs;
565  }
566 
567  friend bool
568  operator==(OptionalProxy const& lhs, OptionalProxy const& rhs) noexcept
569  {
570  if (lhs.engaged() != rhs.engaged())
571  return false;
572  return !lhs.engaged() || *lhs == *rhs;
573  }
574 
575  friend bool
577  {
578  return !(lhs == std::nullopt);
579  }
580 
581  friend bool
583  {
584  return !(rhs == std::nullopt);
585  }
586 
587  friend bool
588  operator!=(OptionalProxy const& lhs, optional_type const& rhs) noexcept
589  {
590  return !(lhs == rhs);
591  }
592 
593  friend bool
594  operator!=(optional_type const& lhs, OptionalProxy const& rhs) noexcept
595  {
596  return !(lhs == rhs);
597  }
598 
599  friend bool
600  operator!=(OptionalProxy const& lhs, OptionalProxy const& rhs) noexcept
601  {
602  return !(lhs == rhs);
603  }
604 
605  // Emulate std::optional::value_or
606  value_type
607  value_or(value_type val) const;
608 
610  operator=(std::nullopt_t const&);
614  operator=(optional_type const& v);
615 
616  template <class U>
618  operator=(U&& u);
619 
620 private:
621  friend class STObject;
622 
623  OptionalProxy(STObject* st, TypedField<T> const* f);
624 
625  bool
626  engaged() const noexcept;
627 
628  void
629  disengage();
630 
632  optional_value() const;
633 };
634 
635 class STObject::FieldErr : public std::runtime_error
636 {
638 };
639 
640 template <class T>
641 STObject::Proxy<T>::Proxy(STObject* st, TypedField<T> const* f) : st_(st), f_(f)
642 {
643  if (st_->mType)
644  {
645  // STObject has associated template
646  if (!st_->peekAtPField(*f_))
647  Throw<STObject::FieldErr>(
648  "Template field error '" + this->f_->getName() + "'");
649  style_ = st_->mType->style(*f_);
650  }
651  else
652  {
653  style_ = soeINVALID;
654  }
655 }
656 
657 template <class T>
658 auto
660 {
661  auto const t = find();
662  if (t)
663  return t->value();
664  if (style_ != soeDEFAULT)
665  Throw<STObject::FieldErr>(
666  "Missing field '" + this->f_->getName() + "'");
667  return value_type{};
668 }
669 
670 template <class T>
671 inline T const*
673 {
674  return dynamic_cast<T const*>(st_->peekAtPField(*f_));
675 }
676 
677 template <class T>
678 template <class U>
679 void
681 {
682  if (style_ == soeDEFAULT && u == value_type{})
683  {
684  st_->makeFieldAbsent(*f_);
685  return;
686  }
687  T* t;
688  if (style_ == soeINVALID)
689  t = dynamic_cast<T*>(st_->getPField(*f_, true));
690  else
691  t = dynamic_cast<T*>(st_->makeFieldPresent(*f_));
692  assert(t);
693  *t = std::forward<U>(u);
694 }
695 
696 //------------------------------------------------------------------------------
697 
698 template <class T>
699 template <class U>
702 {
703  this->assign(std::forward<U>(u));
704  return *this;
705 }
706 
707 template <class T>
709 {
710  return this->value();
711 }
712 
713 template <class T>
715  : Proxy<T>(st, f)
716 {
717 }
718 
719 //------------------------------------------------------------------------------
720 
721 template <class T>
723 {
724  return engaged();
725 }
726 
727 template <class T>
728 auto
730 {
731  return this->value();
732 }
733 
734 template <class T>
736  T>::optional_type() const
737 {
738  return optional_value();
739 }
740 
741 template <class T>
744 {
745  return optional_value();
746 }
747 
748 template <class T>
749 auto
751 {
752  disengage();
753  return *this;
754 }
755 
756 template <class T>
757 auto
759 {
760  if (v)
761  this->assign(std::move(*v));
762  else
763  disengage();
764  return *this;
765 }
766 
767 template <class T>
768 auto
770 {
771  if (v)
772  this->assign(*v);
773  else
774  disengage();
775  return *this;
776 }
777 
778 template <class T>
779 template <class U>
782 {
783  this->assign(std::forward<U>(u));
784  return *this;
785 }
786 
787 template <class T>
789  : Proxy<T>(st, f)
790 {
791 }
792 
793 template <class T>
794 bool
796 {
797  return this->style_ == soeDEFAULT || this->find() != nullptr;
798 }
799 
800 template <class T>
801 void
803 {
804  if (this->style_ == soeREQUIRED || this->style_ == soeDEFAULT)
805  Throw<STObject::FieldErr>(
806  "Template field error '" + this->f_->getName() + "'");
807  if (this->style_ == soeINVALID)
808  this->st_->delField(*this->f_);
809  else
810  this->st_->makeFieldAbsent(*this->f_);
811 }
812 
813 template <class T>
814 auto
816 {
817  if (!engaged())
818  return std::nullopt;
819  return this->value();
820 }
821 
822 template <class T>
825 {
826  return engaged() ? this->value() : val;
827 }
828 
829 //------------------------------------------------------------------------------
830 
831 inline STBase const&
833 {
834  return e.get();
835 }
836 
837 //------------------------------------------------------------------------------
838 
839 inline STObject::STObject(SerialIter&& sit, SField const& name)
840  : STObject(sit, name)
841 {
842 }
843 
844 inline STObject::iterator
846 {
847  return iterator(v_.begin());
848 }
849 
850 inline STObject::iterator
852 {
853  return iterator(v_.end());
854 }
855 
856 inline bool
858 {
859  return v_.empty();
860 }
861 
862 inline void
864 {
865  v_.reserve(n);
866 }
867 
868 inline bool
870 {
871  return mType == nullptr;
872 }
873 
874 inline void
876 {
878 }
879 
880 // VFALCO NOTE does this return an expensive copy of an object with a
881 // dynamic buffer?
882 // VFALCO TODO Remove this function and fix the few callers.
883 inline Serializer
885 {
886  Serializer s;
887  add(s, withAllFields);
888  return s;
889 }
890 
891 template <class... Args>
892 inline std::size_t
893 STObject::emplace_back(Args&&... args)
894 {
895  v_.emplace_back(std::forward<Args>(args)...);
896  return v_.size() - 1;
897 }
898 
899 inline int
901 {
902  return v_.size();
903 }
904 
905 inline const STBase&
906 STObject::peekAtIndex(int offset) const
907 {
908  return v_[offset].get();
909 }
910 
911 inline STBase&
913 {
914  return v_[offset].get();
915 }
916 
917 inline const STBase*
918 STObject::peekAtPIndex(int offset) const
919 {
920  return &v_[offset].get();
921 }
922 
923 inline STBase*
925 {
926  return &v_[offset].get();
927 }
928 
929 template <class T>
930 typename T::value_type
932 {
933  return at(f);
934 }
935 
936 template <class T>
939 {
940  return at(of);
941 }
942 
943 template <class T>
944 inline auto
946 {
947  return at(f);
948 }
949 
950 template <class T>
951 inline auto
953 {
954  return at(of);
955 }
956 
957 template <class T>
958 typename T::value_type
960 {
961  auto const b = peekAtPField(f);
962  if (!b)
963  // This is a free object (no constraints)
964  // with no template
965  Throw<STObject::FieldErr>("Missing field '" + f.getName() + "'");
966  auto const u = dynamic_cast<T const*>(b);
967  if (!u)
968  {
969  assert(mType);
970  assert(b->getSType() == STI_NOTPRESENT);
971  if (mType->style(f) == soeOPTIONAL)
972  Throw<STObject::FieldErr>("Missing field '" + f.getName() + "'");
973  assert(mType->style(f) == soeDEFAULT);
974  // Handle the case where value_type is a
975  // const reference, otherwise we return
976  // the address of a temporary.
977  static std::decay_t<typename T::value_type> const dv{};
978  return dv;
979  }
980  return u->value();
981 }
982 
983 template <class T>
986 {
987  auto const b = peekAtPField(*of.f);
988  if (!b)
989  return std::nullopt;
990  auto const u = dynamic_cast<T const*>(b);
991  if (!u)
992  {
993  assert(mType);
994  assert(b->getSType() == STI_NOTPRESENT);
995  if (mType->style(*of.f) == soeOPTIONAL)
996  return std::nullopt;
997  assert(mType->style(*of.f) == soeDEFAULT);
998  return typename T::value_type{};
999  }
1000  return u->value();
1001 }
1002 
1003 template <class T>
1004 inline auto
1006 {
1007  return ValueProxy<T>(this, &f);
1008 }
1009 
1010 template <class T>
1011 inline auto
1013 {
1014  return OptionalProxy<T>(this, of.f);
1015 }
1016 
1017 template <class Tag>
1018 void
1020 {
1021  STBase* rf = getPField(field, true);
1022 
1023  if (!rf)
1024  throwFieldNotFound(field);
1025 
1026  if (rf->getSType() == STI_NOTPRESENT)
1027  rf = makeFieldPresent(field);
1028 
1029  using Bits = STBitString<160>;
1030  if (auto cf = dynamic_cast<Bits*>(rf))
1031  cf->setValue(v);
1032  else
1033  Throw<std::runtime_error>("Wrong field type");
1034 }
1035 
1036 inline bool
1038 {
1039  return !(*this == o);
1040 }
1041 
1042 template <typename T, typename V>
1043 V
1045 {
1046  const STBase* rf = peekAtPField(field);
1047 
1048  if (!rf)
1049  throwFieldNotFound(field);
1050 
1051  SerializedTypeID id = rf->getSType();
1052 
1053  if (id == STI_NOTPRESENT)
1054  return V(); // optional field not present
1055 
1056  const T* cf = dynamic_cast<const T*>(rf);
1057 
1058  if (!cf)
1059  Throw<std::runtime_error>("Wrong field type");
1060 
1061  return cf->value();
1062 }
1063 
1064 // Implementations for getting (most) fields that return by const reference.
1065 //
1066 // If an absent optional field is deserialized we don't have anything
1067 // obvious to return. So we insist on having the call provide an
1068 // 'empty' value we return in that circumstance.
1069 template <typename T, typename V>
1070 V const&
1071 STObject::getFieldByConstRef(SField const& field, V const& empty) const
1072 {
1073  const STBase* rf = peekAtPField(field);
1074 
1075  if (!rf)
1076  throwFieldNotFound(field);
1077 
1078  SerializedTypeID id = rf->getSType();
1079 
1080  if (id == STI_NOTPRESENT)
1081  return empty; // optional field not present
1082 
1083  const T* cf = dynamic_cast<const T*>(rf);
1084 
1085  if (!cf)
1086  Throw<std::runtime_error>("Wrong field type");
1087 
1088  return *cf;
1089 }
1090 
1091 // Implementation for setting most fields with a setValue() method.
1092 template <typename T, typename V>
1093 void
1095 {
1096  static_assert(!std::is_lvalue_reference<V>::value, "");
1097 
1098  STBase* rf = getPField(field, true);
1099 
1100  if (!rf)
1101  throwFieldNotFound(field);
1102 
1103  if (rf->getSType() == STI_NOTPRESENT)
1104  rf = makeFieldPresent(field);
1105 
1106  T* cf = dynamic_cast<T*>(rf);
1107 
1108  if (!cf)
1109  Throw<std::runtime_error>("Wrong field type");
1110 
1111  cf->setValue(std::move(value));
1112 }
1113 
1114 // Implementation for setting fields using assignment
1115 template <typename T>
1116 void
1117 STObject::setFieldUsingAssignment(SField const& field, T const& value)
1118 {
1119  STBase* rf = getPField(field, true);
1120 
1121  if (!rf)
1122  throwFieldNotFound(field);
1123 
1124  if (rf->getSType() == STI_NOTPRESENT)
1125  rf = makeFieldPresent(field);
1126 
1127  T* cf = dynamic_cast<T*>(rf);
1128 
1129  if (!cf)
1130  Throw<std::runtime_error>("Wrong field type");
1131 
1132  (*cf) = value;
1133 }
1134 
1135 // Implementation for peeking STObjects and STArrays
1136 template <typename T>
1137 T&
1139 {
1140  STBase* rf = getPField(field, true);
1141 
1142  if (!rf)
1143  throwFieldNotFound(field);
1144 
1145  if (rf->getSType() == STI_NOTPRESENT)
1146  rf = makeFieldPresent(field);
1147 
1148  T* cf = dynamic_cast<T*>(rf);
1149 
1150  if (!cf)
1151  Throw<std::runtime_error>("Wrong field type");
1152 
1153  return *cf;
1154 }
1155 
1156 } // namespace ripple
1157 
1158 #endif
ripple::STObject::getFieldSType
SField const & getFieldSType(int index) const
Definition: STObject.cpp:395
ripple::STObject::peekAtField
const STBase & peekAtField(SField const &field) const
Definition: STObject.cpp:373
ripple::STObject::OptionalProxy::operator==
friend bool operator==(OptionalProxy const &lhs, optional_type const &rhs) noexcept
Definition: STObject.h:552
ripple::STObject::OptionalProxy::value_type
typename T::value_type value_type
Definition: STObject.h:508
ripple::STObject::getSortedFields
static std::vector< STBase const * > getSortedFields(STObject const &objToSort, WhichFields whichFields)
Definition: STObject.cpp:806
ripple::STObject::setAccountID
void setAccountID(SField const &field, AccountID const &)
Definition: STObject.cpp:689
ripple::STBase::STBase
STBase()
Definition: STBase.cpp:27
ripple::STObject::STObject
STObject(STObject const &)=default
ripple::STObject::OptionalProxy::engaged
bool engaged() const noexcept
Definition: STObject.h:795
ripple::STObject::getFieldArray
const STArray & getFieldArray(SField const &field) const
Definition: STObject.cpp:624
ripple::STObject::applyTemplate
void applyTemplate(const SOTemplate &type)
Definition: STObject.cpp:116
ripple::STBase::getSType
virtual SerializedTypeID getSType() const
Definition: STBase.cpp:69
ripple::SOTemplate::style
SOEStyle style(SField const &sf) const
Definition: SOTemplate.h:136
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
ripple::STObject::makeFieldAbsent
void makeFieldAbsent(SField const &field)
Definition: STObject.cpp:514
std::string
STL class.
ripple::STObject::hasMatchingEntry
bool hasMatchingEntry(const STBase &)
Definition: STObject.cpp:243
utility
ripple::TypedField
A field with a type known at compile time.
Definition: SField.h:281
std::is_lvalue_reference
ripple::STObject::setFieldH128
void setFieldH128(SField const &field, uint128 const &)
Definition: STObject.cpp:671
ripple::STObject::setFieldU16
void setFieldU16(SField const &field, std::uint16_t)
Definition: STObject.cpp:653
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
ripple::STObject::at
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Definition: STObject.h:959
ripple::STObject::setFieldV256
void setFieldV256(SField const &field, STVector256 const &v)
Definition: STObject.cpp:683
ripple::STObject::Transform::operator()
STBase const & operator()(detail::STVar const &e) const
Definition: STObject.h:832
ripple::STObject::getFieldU64
std::uint64_t getFieldU64(SField const &field) const
Definition: STObject.cpp:565
ripple::Slice
An immutable linear range of bytes.
Definition: Slice.h:44
ripple::STObject::peekAtPIndex
const STBase * peekAtPIndex(int offset) const
Definition: STObject.h:918
ripple::STObject::getFieldV256
const STVector256 & getFieldV256(SField const &field) const
Definition: STObject.cpp:617
ripple::STObject::v_
list_type v_
Definition: STObject.h:74
ripple::STObject::OptionalProxy::operator!=
friend bool operator!=(OptionalProxy const &lhs, optional_type const &rhs) noexcept
Definition: STObject.h:588
std::vector::reserve
T reserve(T... args)
ripple::STObject::Proxy::value_type
typename T::value_type value_type
Definition: STObject.h:460
ripple::STObject::OptionalProxy::operator!=
friend bool operator!=(OptionalProxy const &lhs, std::nullopt_t) noexcept
Definition: STObject.h:576
ripple::STObject::getFieldByConstRef
V const & getFieldByConstRef(SField const &field, V const &empty) const
Definition: STObject.h:1071
std::vector< detail::STVar >
std::vector::size
T size(T... args)
ripple::STObject::getFieldU8
unsigned char getFieldU8(SField const &field) const
Definition: STObject.cpp:547
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::STObject::withAllFields
@ withAllFields
Definition: STObject.h:398
ripple::STObject::empty
bool empty() const
Definition: STObject.h:857
ripple::STObject::getSerializer
Serializer getSerializer() const
Definition: STObject.h:884
ripple::STObject::getFieldH128
uint128 getFieldH128(SField const &field) const
Definition: STObject.cpp:571
ripple::STObject::WhichFields
WhichFields
Definition: STObject.h:394
ripple::soeREQUIRED
@ soeREQUIRED
Definition: SOTemplate.h:35
ripple::OptionaledField
Indicate std::optional field semantics.
Definition: SField.h:297
ripple::STObject::OptionalProxy::operator=
OptionalProxy & operator=(OptionalProxy const &)=delete
ripple::STObject::move
STBase * move(std::size_t n, void *buf) override
Definition: STObject.cpp:67
ripple::STObject::setFieldVL
void setFieldVL(SField const &field, Blob const &)
Definition: STObject.cpp:695
ripple::STObject::getFieldVL
Blob getFieldVL(SField const &field) const
Definition: STObject.cpp:595
ripple::STObject::isDefault
bool isDefault() const override
Definition: STObject.cpp:79
ripple::STBitString::setValue
void setValue(base_uint< Bits, Tag > const &v)
Definition: STBitString.h:166
ripple::STObject::OptionalProxy::operator==
friend bool operator==(std::nullopt_t, OptionalProxy const &rhs) noexcept
Definition: STObject.h:546
ripple::STObject::~STObject
virtual ~STObject()=default
ripple::STObject::getFieldH160
uint160 getFieldH160(SField const &field) const
Definition: STObject.cpp:577
ripple::STBitString
Definition: SField.h:47
ripple::STPathSet
Definition: STPathSet.h:175
ripple::STObject::getFullText
std::string getFullText() const override
Definition: STObject.cpp:254
ripple::STObject::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STObject.cpp:304
ripple::STObject::Proxy::assign
void assign(U &&u)
Definition: STObject.h:680
stdexcept
ripple::base_uint< 256 >
ripple::STObject::peekAtIndex
const STBase & peekAtIndex(int offset) const
Definition: STObject.h:906
ripple::STObject::setFieldH160
void setFieldH160(SField const &field, base_uint< 160, Tag > const &v)
Definition: STObject.h:1019
ripple::STObject::OptionalProxy::operator!=
friend bool operator!=(optional_type const &lhs, OptionalProxy const &rhs) noexcept
Definition: STObject.h:594
ripple::STObject::operator=
STObject & operator=(STObject const &)=default
ripple::STObject::FieldErr
Definition: STObject.h:635
ripple::STObject::OptionalProxy::OptionalProxy
OptionalProxy(OptionalProxy const &)=default
ripple::STObject::Proxy::st_
STObject * st_
Definition: STObject.h:462
ripple::STObject::delField
bool delField(SField const &field)
Definition: STObject.cpp:529
ripple::STObject::ValueProxy::value_type
typename T::value_type value_type
Definition: STObject.h:485
ripple::STObject::ValueProxy
Definition: STObject.h:57
ripple::STObject::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STObject.cpp:61
ripple::SOTemplate
Defines the fields and their attributes within a STObject.
Definition: SOTemplate.h:82
ripple::STObject::OptionalProxy
Definition: STObject.h:59
ripple::STObject::setFieldArray
void setFieldArray(SField const &field, STArray const &v)
Definition: STObject.cpp:719
ripple::STObject::iterator
boost::transform_iterator< Transform, STObject::list_type::const_iterator > iterator
Definition: STObject.h:79
ripple::HashPrefix
HashPrefix
Prefix for hashing functions.
Definition: HashPrefix.h:54
ripple::STObject::Proxy::f_
TypedField< T > const * f_
Definition: STObject.h:464
ripple::STObject::setFieldU8
void setFieldU8(SField const &field, unsigned char)
Definition: STObject.cpp:647
std::enable_if_t
ripple::STObject::peekFieldArray
STArray & peekFieldArray(SField const &field)
Definition: STObject.cpp:445
ripple::STObject::OptionalProxy::optional_type
std::optional< typename std::decay< value_type >::type > optional_type
Definition: STObject.h:510
ripple::STObject::operator==
bool operator==(const STObject &o) const
Definition: STObject.cpp:738
ripple::STObject::setFieldAmount
void setFieldAmount(SField const &field, STAmount const &)
Definition: STObject.cpp:707
ripple::STObject::operator!=
bool operator!=(const STObject &o) const
Definition: STObject.h:1037
ripple::STObject::getAccountID
AccountID getAccountID(SField const &field) const
Definition: STObject.cpp:589
ripple::STObject::setFieldH256
void setFieldH256(SField const &field, uint256 const &)
Definition: STObject.cpp:677
ripple::STObject::end
iterator end() const
Definition: STObject.h:851
ripple::soeOPTIONAL
@ soeOPTIONAL
Definition: SOTemplate.h:36
ripple::SOEStyle
SOEStyle
Kind of element in each entry of an SOTemplate.
Definition: SOTemplate.h:33
ripple::throwFieldNotFound
void throwFieldNotFound(SField const &field)
Definition: STObject.h:46
ripple::STArray
Definition: STArray.h:28
ripple::STAmount
Definition: STAmount.h:43
ripple::STObject::clearFlag
bool clearFlag(std::uint32_t)
Definition: STObject.cpp:463
ripple::STObject::getFlags
std::uint32_t getFlags() const
Definition: STObject.cpp:481
ripple::soeINVALID
@ soeINVALID
Definition: SOTemplate.h:34
ripple::STObject::begin
iterator begin() const
Definition: STObject.h:845
std::runtime_error::runtime_error
T runtime_error(T... args)
ripple::SerialIter
Definition: Serializer.h:310
std::uint32_t
ripple::STObject::OptionalProxy::operator!=
friend bool operator!=(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
Definition: STObject.h:600
ripple::STObject::addWithoutSigningFields
void addWithoutSigningFields(Serializer &s) const
Definition: STObject.h:875
ripple::STObject::reserve
void reserve(std::size_t n)
Definition: STObject.h:863
ripple::STObject::getFieldU16
std::uint16_t getFieldU16(SField const &field) const
Definition: STObject.cpp:553
ripple::STObject::setFieldUsingAssignment
void setFieldUsingAssignment(SField const &field, T const &value)
Definition: STObject.h:1117
ripple::STObject::getPField
STBase * getPField(SField const &field, bool createOkay=false)
Definition: STObject.cpp:412
ripple::STObject::setFieldPathSet
void setFieldPathSet(SField const &field, STPathSet const &)
Definition: STObject.cpp:713
std::decay_t
ripple::Serializer
Definition: Serializer.h:39
ripple::STObject::mType
SOTemplate const * mType
Definition: STObject.h:75
ripple::STObject::getFieldIndex
int getFieldIndex(SField const &field) const
Definition: STObject.cpp:357
ripple::STObject::makeFieldPresent
STBase * makeFieldPresent(SField const &field)
Definition: STObject.cpp:492
ripple::STObject::emplace_back
std::size_t emplace_back(Args &&... args)
Definition: STObject.h:893
ripple::STObject::ValueProxy::ValueProxy
ValueProxy(ValueProxy const &)=default
ripple::STObject::add
void add(Serializer &s) const override
Definition: STObject.cpp:85
ripple::STObject
Definition: STObject.h:51
ripple::STObject::Proxy
Definition: STObject.h:55
ripple::STObject::Proxy::find
T const * find() const
Definition: STObject.h:672
std::vector::emplace_back
T emplace_back(T... args)
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::STObject::Proxy::style_
SOEStyle style_
Definition: STObject.h:463
std::remove_reference
ripple::STObject::getIndex
STBase & getIndex(int offset)
Definition: STObject.h:912
ripple::STObject::peekFieldObject
STObject & peekFieldObject(SField const &field)
Definition: STObject.cpp:439
ripple::STObject::getSigningHash
uint256 getSigningHash(HashPrefix prefix) const
Definition: STObject.cpp:348
ripple::STObject::peekAtPField
const STBase * peekAtPField(SField const &field) const
Definition: STObject.cpp:401
std::nullopt_t
ripple::SField
Identifies fields.
Definition: SField.h:109
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:66
ripple::STObject::getField
STBase & getField(SField const &field)
Definition: STObject.cpp:384
ripple::STObject::getSType
SerializedTypeID getSType() const override
Definition: STObject.cpp:73
std::vector::begin
T begin(T... args)
ripple::SField::getName
std::string const & getName() const
Definition: SField.h:172
std
STL namespace.
ripple::STObject::peekField
T & peekField(SField const &field)
Definition: STObject.h:1138
ripple::STObject::isFieldPresent
bool isFieldPresent(SField const &field) const
Definition: STObject.cpp:428
cassert
ripple::detail::STVar::get
STBase & get()
Definition: STVar.h:82
ripple::STObject::Transform
Definition: STObject.h:61
ripple::STObject::OptionalProxy::operator==
friend bool operator==(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
Definition: STObject.h:568
ripple::STObject::OptionalProxy::operator~
optional_type operator~() const
Explicit conversion to std::optional.
Definition: STObject.h:743
ripple::STObject::Proxy::Proxy
Proxy(Proxy const &)=default
ripple::STObject::OptionalProxy::operator==
friend bool operator==(optional_type const &lhs, OptionalProxy const &rhs) noexcept
Definition: STObject.h:562
ripple::STObject::setFieldUsingSetValue
void setFieldUsingSetValue(SField const &field, V value)
Definition: STObject.h:1094
ripple::STObject::setFlag
bool setFlag(std::uint32_t)
Definition: STObject.cpp:451
ripple::STVector256
Definition: STVector256.h:29
ripple::STObject::isFlag
bool isFlag(std::uint32_t) const
Definition: STObject.cpp:475
std::vector::empty
T empty(T... args)
ripple::STObject::OptionalProxy::operator*
value_type operator*() const
Return the contained value.
Definition: STObject.h:729
std::remove_cv
ripple::STObject::Proxy::value
value_type value() const
Definition: STObject.h:659
ripple::STObject::OptionalProxy::operator!=
friend bool operator!=(std::nullopt_t, OptionalProxy const &rhs) noexcept
Definition: STObject.h:582
optional
ripple::STObject::getCount
int getCount() const
Definition: STObject.h:900
std::size_t
ripple::OptionaledField::f
TypedField< T > const * f
Definition: SField.h:299
ripple::STObject::applyTemplateFromSField
void applyTemplateFromSField(SField const &)
Definition: STObject.cpp:170
std::vector::end
T end(T... args)
ripple::STObject::OptionalProxy::optional_value
optional_type optional_value() const
Definition: STObject.h:815
ripple::STObject::operator[]
T::value_type operator[](TypedField< T > const &f) const
Get the value of a field.
Definition: STObject.h:931
ripple::STObject::getFieldU32
std::uint32_t getFieldU32(SField const &field) const
Definition: STObject.cpp:559
ripple::STObject::getFieldByValue
V getFieldByValue(SField const &field) const
ripple::STObject::Transform::Transform
Transform()=default
ripple::STObject::OptionalProxy::value_or
value_type value_or(value_type val) const
Definition: STObject.h:824
ripple::STObject::setFieldU64
void setFieldU64(SField const &field, std::uint64_t)
Definition: STObject.cpp:665
ripple::STObject::getJson
Json::Value getJson(JsonOptions options) const override
Definition: STObject.cpp:725
std::unique_ptr
STL class.
ripple::STObject::getFieldPathSet
STPathSet const & getFieldPathSet(SField const &field) const
Definition: STObject.cpp:610
ripple::STObject::omitSigningFields
@ omitSigningFields
Definition: STObject.h:397
ripple::STObject::set
void set(const SOTemplate &)
Definition: STObject.cpp:100
ripple::STObject::setFieldU32
void setFieldU32(SField const &field, std::uint32_t)
Definition: STObject.cpp:659
ripple::STObject::OptionalProxy::disengage
void disengage()
Definition: STObject.h:802
type_traits
ripple::STObject::getFieldAmount
STAmount const & getFieldAmount(SField const &field) const
Definition: STObject.cpp:603
ripple::STObject::getPIndex
STBase * getPIndex(int offset)
Definition: STObject.h:924
ripple::soeDEFAULT
@ soeDEFAULT
Definition: SOTemplate.h:37
ripple::detail::STVar
Definition: STVar.h:49
ripple::STObject::isFree
bool isFree() const
Definition: STObject.h:869
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::STObject::ValueProxy::operator=
ValueProxy & operator=(ValueProxy const &)=delete
ripple::STObject::getHash
uint256 getHash(HashPrefix prefix) const
Definition: STObject.cpp:339
ripple::STI_NOTPRESENT
@ STI_NOTPRESENT
Definition: SField.h:56
ripple::STObject::getText
std::string getText() const override
Definition: STObject.cpp:285
ripple::STObject::getFieldH256
uint256 getFieldH256(SField const &field) const
Definition: STObject.cpp:583