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 private:
54  // Proxy value for a STBase derived class
55  template <class T>
56  class Proxy
57  {
58  protected:
59  using value_type = typename T::value_type;
60 
63  TypedField<T> const* f_;
64 
65  Proxy(Proxy const&) = default;
66  Proxy(STObject* st, TypedField<T> const* f);
68  value() const;
69  T const*
70  find() const;
71 
72  template <class U>
73  void
74  assign(U&& u);
75  };
76 
77  template <class T>
78  class ValueProxy : private Proxy<T>
79  {
80  private:
81  using value_type = typename T::value_type;
82 
83  public:
84  ValueProxy(ValueProxy const&) = default;
85  ValueProxy&
86  operator=(ValueProxy const&) = delete;
87 
88  template <class U>
90  operator=(U&& u);
91 
92  operator value_type() const;
93 
94  private:
95  friend class STObject;
96 
97  ValueProxy(STObject* st, TypedField<T> const* f);
98  };
99 
100  template <class T>
101  class OptionalProxy : private Proxy<T>
102  {
103  private:
104  using value_type = typename T::value_type;
105 
106  using optional_type =
108 
109  public:
110  OptionalProxy(OptionalProxy const&) = default;
112  operator=(OptionalProxy const&) = delete;
113 
119  explicit operator bool() const noexcept;
120 
127  value_type
128  operator*() const;
129 
130  operator optional_type() const;
131 
134  operator~() const;
135 
136  friend bool
137  operator==(OptionalProxy const& lhs, std::nullopt_t) noexcept
138  {
139  return !lhs.engaged();
140  }
141 
142  friend bool
144  {
145  return rhs == std::nullopt;
146  }
147 
148  friend bool
149  operator==(OptionalProxy const& lhs, optional_type const& rhs) noexcept
150  {
151  if (!lhs.engaged())
152  return !rhs;
153  if (!rhs)
154  return false;
155  return *lhs == *rhs;
156  }
157 
158  friend bool
159  operator==(optional_type const& lhs, OptionalProxy const& rhs) noexcept
160  {
161  return rhs == lhs;
162  }
163 
164  friend bool
165  operator==(OptionalProxy const& lhs, OptionalProxy const& rhs) noexcept
166  {
167  if (lhs.engaged() != rhs.engaged())
168  return false;
169  return !lhs.engaged() || *lhs == *rhs;
170  }
171 
172  friend bool
174  {
175  return !(lhs == std::nullopt);
176  }
177 
178  friend bool
180  {
181  return !(rhs == std::nullopt);
182  }
183 
184  friend bool
185  operator!=(OptionalProxy const& lhs, optional_type const& rhs) noexcept
186  {
187  return !(lhs == rhs);
188  }
189 
190  friend bool
191  operator!=(optional_type const& lhs, OptionalProxy const& rhs) noexcept
192  {
193  return !(lhs == rhs);
194  }
195 
196  friend bool
197  operator!=(OptionalProxy const& lhs, OptionalProxy const& rhs) noexcept
198  {
199  return !(lhs == rhs);
200  }
201 
202  // Emulate std::optional::value_or
203  value_type
204  value_or(value_type val) const
205  {
206  return engaged() ? this->value() : val;
207  }
208 
210  operator=(std::nullopt_t const&);
214  operator=(optional_type const& v);
215 
216  template <class U>
218  operator=(U&& u);
219 
220  private:
221  friend class STObject;
222 
223  OptionalProxy(STObject* st, TypedField<T> const* f);
224 
225  bool
226  engaged() const noexcept;
227 
228  void
229  disengage();
230 
232  optional_value() const;
233  };
234 
235  struct Transform
236  {
237  explicit Transform() = default;
238 
241 
242  STBase const&
243  operator()(detail::STVar const& e) const
244  {
245  return e.get();
246  }
247  };
248 
250 
253 
254 public:
255  using iterator = boost::
256  transform_iterator<Transform, STObject::list_type::const_iterator>;
257 
259  {
261  };
262 
263  STObject(STObject&&);
264  STObject(STObject const&) = default;
265  STObject(const SOTemplate& type, SField const& name);
266  STObject(
267  const SOTemplate& type,
268  SerialIter& sit,
269  SField const& name) noexcept(false);
270  STObject(SerialIter& sit, SField const& name, int depth = 0) noexcept(
271  false);
272  STObject(SerialIter&& sit, SField const& name) noexcept(false)
273  : STObject(sit, name)
274  {
275  }
276  STObject&
277  operator=(STObject const&) = default;
278  STObject&
279  operator=(STObject&& other);
280 
281  explicit STObject(SField const& name);
282 
283  virtual ~STObject() = default;
284 
285  STBase*
286  copy(std::size_t n, void* buf) const override
287  {
288  return emplace(n, buf, *this);
289  }
290 
291  STBase*
292  move(std::size_t n, void* buf) override
293  {
294  return emplace(n, buf, std::move(*this));
295  }
296 
297  iterator
298  begin() const
299  {
300  return iterator(v_.begin());
301  }
302 
303  iterator
304  end() const
305  {
306  return iterator(v_.end());
307  }
308 
309  bool
310  empty() const
311  {
312  return v_.empty();
313  }
314 
315  void
317  {
318  v_.reserve(n);
319  }
320 
321  void
322  applyTemplate(const SOTemplate& type) noexcept(false);
323 
324  void
325  applyTemplateFromSField(SField const&) noexcept(false);
326 
327  bool
328  isFree() const
329  {
330  return mType == nullptr;
331  }
332 
333  void
334  set(const SOTemplate&);
335  bool
336  set(SerialIter& u, int depth = 0);
337 
338  virtual SerializedTypeID
339  getSType() const override
340  {
341  return STI_OBJECT;
342  }
343  virtual bool
344  isEquivalent(const STBase& t) const override;
345  virtual bool
346  isDefault() const override
347  {
348  return v_.empty();
349  }
350 
351  virtual void
352  add(Serializer& s) const override
353  {
354  add(s, withAllFields); // just inner elements
355  }
356 
357  void
359  {
361  }
362 
363  // VFALCO NOTE does this return an expensive copy of an object with a
364  // dynamic buffer?
365  // VFALCO TODO Remove this function and fix the few callers.
366  Serializer
368  {
369  Serializer s;
370  add(s, withAllFields);
371  return s;
372  }
373 
374  virtual std::string
375  getFullText() const override;
376  virtual std::string
377  getText() const override;
378 
379  // TODO(tom): options should be an enum.
380  virtual Json::Value
381  getJson(JsonOptions options) const override;
382 
383  template <class... Args>
385  emplace_back(Args&&... args)
386  {
387  v_.emplace_back(std::forward<Args>(args)...);
388  return v_.size() - 1;
389  }
390 
391  int
392  getCount() const
393  {
394  return v_.size();
395  }
396 
397  bool setFlag(std::uint32_t);
398  bool clearFlag(std::uint32_t);
399  bool isFlag(std::uint32_t) const;
401  getFlags() const;
402 
403  uint256
404  getHash(HashPrefix prefix) const;
405  uint256
406  getSigningHash(HashPrefix prefix) const;
407 
408  const STBase&
409  peekAtIndex(int offset) const
410  {
411  return v_[offset].get();
412  }
413  STBase&
414  getIndex(int offset)
415  {
416  return v_[offset].get();
417  }
418  const STBase*
419  peekAtPIndex(int offset) const
420  {
421  return &v_[offset].get();
422  }
423  STBase*
424  getPIndex(int offset)
425  {
426  return &v_[offset].get();
427  }
428 
429  int
430  getFieldIndex(SField const& field) const;
431  SField const&
432  getFieldSType(int index) const;
433 
434  const STBase&
435  peekAtField(SField const& field) const;
436  STBase&
437  getField(SField const& field);
438  const STBase*
439  peekAtPField(SField const& field) const;
440  STBase*
441  getPField(SField const& field, bool createOkay = false);
442 
443  // these throw if the field type doesn't match, or return default values
444  // if the field is optional but not present
445  unsigned char
446  getFieldU8(SField const& field) const;
448  getFieldU16(SField const& field) const;
450  getFieldU32(SField const& field) const;
452  getFieldU64(SField const& field) const;
453  uint128
454  getFieldH128(SField const& field) const;
455 
456  uint160
457  getFieldH160(SField const& field) const;
458  uint256
459  getFieldH256(SField const& field) const;
460  AccountID
461  getAccountID(SField const& field) const;
462 
463  Blob
464  getFieldVL(SField const& field) const;
465  STAmount const&
466  getFieldAmount(SField const& field) const;
467  STPathSet const&
468  getFieldPathSet(SField const& field) const;
469  const STVector256&
470  getFieldV256(SField const& field) const;
471  const STArray&
472  getFieldArray(SField const& field) const;
473 
481  template <class T>
482  typename T::value_type
483  operator[](TypedField<T> const& f) const;
484 
493  template <class T>
495  operator[](OptionaledField<T> const& of) const;
496 
504  template <class T>
505  ValueProxy<T>
506  operator[](TypedField<T> const& f);
507 
517  template <class T>
518  OptionalProxy<T>
519  operator[](OptionaledField<T> const& of);
520 
528  template <class T>
529  typename T::value_type
530  at(TypedField<T> const& f) const;
531 
540  template <class T>
542  at(OptionaledField<T> const& of) const;
543 
551  template <class T>
552  ValueProxy<T>
553  at(TypedField<T> const& f);
554 
564  template <class T>
565  OptionalProxy<T>
566  at(OptionaledField<T> const& of);
567 
571  void
573 
574  void
575  set(STBase* v);
576 
577  void
578  setFieldU8(SField const& field, unsigned char);
579  void
580  setFieldU16(SField const& field, std::uint16_t);
581  void
582  setFieldU32(SField const& field, std::uint32_t);
583  void
584  setFieldU64(SField const& field, std::uint64_t);
585  void
586  setFieldH128(SField const& field, uint128 const&);
587  void
588  setFieldH256(SField const& field, uint256 const&);
589  void
590  setFieldVL(SField const& field, Blob const&);
591  void
592  setFieldVL(SField const& field, Slice const&);
593 
594  void
595  setAccountID(SField const& field, AccountID const&);
596 
597  void
598  setFieldAmount(SField const& field, STAmount const&);
599  void
600  setFieldPathSet(SField const& field, STPathSet const&);
601  void
602  setFieldV256(SField const& field, STVector256 const& v);
603  void
604  setFieldArray(SField const& field, STArray const& v);
605 
606  template <class Tag>
607  void
608  setFieldH160(SField const& field, base_uint<160, Tag> const& v)
609  {
610  STBase* rf = getPField(field, true);
611 
612  if (!rf)
613  throwFieldNotFound(field);
614 
615  if (rf->getSType() == STI_NOTPRESENT)
616  rf = makeFieldPresent(field);
617 
618  using Bits = STBitString<160>;
619  if (auto cf = dynamic_cast<Bits*>(rf))
620  cf->setValue(v);
621  else
622  Throw<std::runtime_error>("Wrong field type");
623  }
624 
625  STObject&
626  peekFieldObject(SField const& field);
627  STArray&
628  peekFieldArray(SField const& field);
629 
630  bool
631  isFieldPresent(SField const& field) const;
632  STBase*
633  makeFieldPresent(SField const& field);
634  void
635  makeFieldAbsent(SField const& field);
636  bool
637  delField(SField const& field);
638  void
639  delField(int index);
640 
641  bool
642  hasMatchingEntry(const STBase&);
643 
644  bool
645  operator==(const STObject& o) const;
646  bool
647  operator!=(const STObject& o) const
648  {
649  return !(*this == o);
650  }
651 
652 private:
653  enum WhichFields : bool {
654  // These values are carefully chosen to do the right thing if passed
655  // to SField::shouldInclude (bool)
658  };
659 
660  void
661  add(Serializer& s, WhichFields whichFields) const;
662 
663  // Sort the entries in an STObject into the order that they will be
664  // serialized. Note: they are not sorted into pointer value order, they
665  // are sorted by SField::fieldCode.
667  getSortedFields(STObject const& objToSort, WhichFields whichFields);
668 
669  // Implementation for getting (most) fields that return by value.
670  //
671  // The remove_cv and remove_reference are necessitated by the STBitString
672  // types. Their value() returns by const ref. We return those types
673  // by value.
674  template <
675  typename T,
676  typename V = typename std::remove_cv<typename std::remove_reference<
677  decltype(std::declval<T>().value())>::type>::type>
678  V
679  getFieldByValue(SField const& field) const
680  {
681  const STBase* rf = peekAtPField(field);
682 
683  if (!rf)
684  throwFieldNotFound(field);
685 
686  SerializedTypeID id = rf->getSType();
687 
688  if (id == STI_NOTPRESENT)
689  return V(); // optional field not present
690 
691  const T* cf = dynamic_cast<const T*>(rf);
692 
693  if (!cf)
694  Throw<std::runtime_error>("Wrong field type");
695 
696  return cf->value();
697  }
698 
699  // Implementations for getting (most) fields that return by const reference.
700  //
701  // If an absent optional field is deserialized we don't have anything
702  // obvious to return. So we insist on having the call provide an
703  // 'empty' value we return in that circumstance.
704  template <typename T, typename V>
705  V const&
706  getFieldByConstRef(SField const& field, V const& empty) const
707  {
708  const STBase* rf = peekAtPField(field);
709 
710  if (!rf)
711  throwFieldNotFound(field);
712 
713  SerializedTypeID id = rf->getSType();
714 
715  if (id == STI_NOTPRESENT)
716  return empty; // optional field not present
717 
718  const T* cf = dynamic_cast<const T*>(rf);
719 
720  if (!cf)
721  Throw<std::runtime_error>("Wrong field type");
722 
723  return *cf;
724  }
725 
726  // Implementation for setting most fields with a setValue() method.
727  template <typename T, typename V>
728  void
730  {
731  static_assert(!std::is_lvalue_reference<V>::value, "");
732 
733  STBase* rf = getPField(field, true);
734 
735  if (!rf)
736  throwFieldNotFound(field);
737 
738  if (rf->getSType() == STI_NOTPRESENT)
739  rf = makeFieldPresent(field);
740 
741  T* cf = dynamic_cast<T*>(rf);
742 
743  if (!cf)
744  Throw<std::runtime_error>("Wrong field type");
745 
746  cf->setValue(std::move(value));
747  }
748 
749  // Implementation for setting fields using assignment
750  template <typename T>
751  void
752  setFieldUsingAssignment(SField const& field, T const& value)
753  {
754  STBase* rf = getPField(field, true);
755 
756  if (!rf)
757  throwFieldNotFound(field);
758 
759  if (rf->getSType() == STI_NOTPRESENT)
760  rf = makeFieldPresent(field);
761 
762  T* cf = dynamic_cast<T*>(rf);
763 
764  if (!cf)
765  Throw<std::runtime_error>("Wrong field type");
766 
767  (*cf) = value;
768  }
769 
770  // Implementation for peeking STObjects and STArrays
771  template <typename T>
772  T&
773  peekField(SField const& field)
774  {
775  STBase* rf = getPField(field, true);
776 
777  if (!rf)
778  throwFieldNotFound(field);
779 
780  if (rf->getSType() == STI_NOTPRESENT)
781  rf = makeFieldPresent(field);
782 
783  T* cf = dynamic_cast<T*>(rf);
784 
785  if (!cf)
786  Throw<std::runtime_error>("Wrong field type");
787 
788  return *cf;
789  }
790 };
791 
792 //------------------------------------------------------------------------------
793 
794 template <class T>
795 STObject::Proxy<T>::Proxy(STObject* st, TypedField<T> const* f) : st_(st), f_(f)
796 {
797  if (st_->mType)
798  {
799  // STObject has associated template
800  if (!st_->peekAtPField(*f_))
801  Throw<STObject::FieldErr>(
802  "Template field error '" + this->f_->getName() + "'");
803  style_ = st_->mType->style(*f_);
804  }
805  else
806  {
807  style_ = soeINVALID;
808  }
809 }
810 
811 template <class T>
812 auto
814 {
815  auto const t = find();
816  if (t)
817  return t->value();
818  if (style_ != soeDEFAULT)
819  Throw<STObject::FieldErr>(
820  "Missing field '" + this->f_->getName() + "'");
821  return value_type{};
822 }
823 
824 template <class T>
825 inline T const*
827 {
828  return dynamic_cast<T const*>(st_->peekAtPField(*f_));
829 }
830 
831 template <class T>
832 template <class U>
833 void
835 {
836  if (style_ == soeDEFAULT && u == value_type{})
837  {
838  st_->makeFieldAbsent(*f_);
839  return;
840  }
841  T* t;
842  if (style_ == soeINVALID)
843  t = dynamic_cast<T*>(st_->getPField(*f_, true));
844  else
845  t = dynamic_cast<T*>(st_->makeFieldPresent(*f_));
846  assert(t);
847  *t = std::forward<U>(u);
848 }
849 
850 //------------------------------------------------------------------------------
851 
852 template <class T>
853 template <class U>
856 {
857  this->assign(std::forward<U>(u));
858  return *this;
859 }
860 
861 template <class T>
863 {
864  return this->value();
865 }
866 
867 template <class T>
869  : Proxy<T>(st, f)
870 {
871 }
872 
873 //------------------------------------------------------------------------------
874 
875 template <class T>
877 {
878  return engaged();
879 }
880 
881 template <class T>
882 auto
884 {
885  return this->value();
886 }
887 
888 template <class T>
890  T>::optional_type() const
891 {
892  return optional_value();
893 }
894 
895 template <class T>
898 {
899  return optional_value();
900 }
901 
902 template <class T>
903 auto
905 {
906  disengage();
907  return *this;
908 }
909 
910 template <class T>
911 auto
913 {
914  if (v)
915  this->assign(std::move(*v));
916  else
917  disengage();
918  return *this;
919 }
920 
921 template <class T>
922 auto
924 {
925  if (v)
926  this->assign(*v);
927  else
928  disengage();
929  return *this;
930 }
931 
932 template <class T>
933 template <class U>
936 {
937  this->assign(std::forward<U>(u));
938  return *this;
939 }
940 
941 template <class T>
943  : Proxy<T>(st, f)
944 {
945 }
946 
947 template <class T>
948 bool
950 {
951  return this->style_ == soeDEFAULT || this->find() != nullptr;
952 }
953 
954 template <class T>
955 void
957 {
958  if (this->style_ == soeREQUIRED || this->style_ == soeDEFAULT)
959  Throw<STObject::FieldErr>(
960  "Template field error '" + this->f_->getName() + "'");
961  if (this->style_ == soeINVALID)
962  this->st_->delField(*this->f_);
963  else
964  this->st_->makeFieldAbsent(*this->f_);
965 }
966 
967 template <class T>
968 auto
970 {
971  if (!engaged())
972  return std::nullopt;
973  return this->value();
974 }
975 
976 //------------------------------------------------------------------------------
977 
978 template <class T>
979 typename T::value_type
981 {
982  return at(f);
983 }
984 
985 template <class T>
988 {
989  return at(of);
990 }
991 
992 template <class T>
993 inline auto
995 {
996  return at(f);
997 }
998 
999 template <class T>
1000 inline auto
1002 {
1003  return at(of);
1004 }
1005 
1006 template <class T>
1007 typename T::value_type
1009 {
1010  auto const b = peekAtPField(f);
1011  if (!b)
1012  // This is a free object (no constraints)
1013  // with no template
1014  Throw<STObject::FieldErr>("Missing field '" + f.getName() + "'");
1015  auto const u = dynamic_cast<T const*>(b);
1016  if (!u)
1017  {
1018  assert(mType);
1019  assert(b->getSType() == STI_NOTPRESENT);
1020  if (mType->style(f) == soeOPTIONAL)
1021  Throw<STObject::FieldErr>("Missing field '" + f.getName() + "'");
1022  assert(mType->style(f) == soeDEFAULT);
1023  // Handle the case where value_type is a
1024  // const reference, otherwise we return
1025  // the address of a temporary.
1026  static std::decay_t<typename T::value_type> const dv{};
1027  return dv;
1028  }
1029  return u->value();
1030 }
1031 
1032 template <class T>
1035 {
1036  auto const b = peekAtPField(*of.f);
1037  if (!b)
1038  return std::nullopt;
1039  auto const u = dynamic_cast<T const*>(b);
1040  if (!u)
1041  {
1042  assert(mType);
1043  assert(b->getSType() == STI_NOTPRESENT);
1044  if (mType->style(*of.f) == soeOPTIONAL)
1045  return std::nullopt;
1046  assert(mType->style(*of.f) == soeDEFAULT);
1047  return typename T::value_type{};
1048  }
1049  return u->value();
1050 }
1051 
1052 template <class T>
1053 inline auto
1055 {
1056  return ValueProxy<T>(this, &f);
1057 }
1058 
1059 template <class T>
1060 inline auto
1062 {
1063  return OptionalProxy<T>(this, of.f);
1064 }
1065 
1066 } // namespace ripple
1067 
1068 #endif
ripple::STObject::getFieldSType
SField const & getFieldSType(int index) const
Definition: STObject.cpp:368
ripple::STObject::peekAtField
const STBase & peekAtField(SField const &field) const
Definition: STObject.cpp:346
ripple::STObject::OptionalProxy::operator==
friend bool operator==(OptionalProxy const &lhs, optional_type const &rhs) noexcept
Definition: STObject.h:149
ripple::STObject::getIndex
STBase & getIndex(int offset)
Definition: STObject.h:414
ripple::STObject::OptionalProxy::value_type
typename T::value_type value_type
Definition: STObject.h:104
ripple::STObject::getSortedFields
static std::vector< STBase const * > getSortedFields(STObject const &objToSort, WhichFields whichFields)
Definition: STObject.cpp:779
ripple::STObject::setAccountID
void setAccountID(SField const &field, AccountID const &)
Definition: STObject.cpp:662
ripple::STBase::STBase
STBase()
Definition: STBase.cpp:27
ripple::STObject::OptionalProxy::engaged
bool engaged() const noexcept
Definition: STObject.h:949
ripple::STObject::getFieldArray
const STArray & getFieldArray(SField const &field) const
Definition: STObject.cpp:597
ripple::STBase::getSType
virtual SerializedTypeID getSType() const
Definition: STBase.cpp:57
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:487
std::string
STL class.
ripple::STObject::hasMatchingEntry
bool hasMatchingEntry(const STBase &)
Definition: STObject.cpp:216
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:644
ripple::STObject::setFieldU16
void setFieldU16(SField const &field, std::uint16_t)
Definition: STObject.cpp:626
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:1008
ripple::STObject::setFieldV256
void setFieldV256(SField const &field, STVector256 const &v)
Definition: STObject.cpp:656
ripple::STObject::getFieldU64
std::uint64_t getFieldU64(SField const &field) const
Definition: STObject.cpp:538
ripple::Slice
An immutable linear range of bytes.
Definition: Slice.h:44
ripple::STObject::getFieldV256
const STVector256 & getFieldV256(SField const &field) const
Definition: STObject.cpp:590
ripple::STObject::v_
list_type v_
Definition: STObject.h:251
ripple::STObject::OptionalProxy::operator!=
friend bool operator!=(OptionalProxy const &lhs, optional_type const &rhs) noexcept
Definition: STObject.h:185
std::vector::reserve
T reserve(T... args)
ripple::STObject::Proxy::value_type
typename T::value_type value_type
Definition: STObject.h:59
ripple::STObject::OptionalProxy::operator!=
friend bool operator!=(OptionalProxy const &lhs, std::nullopt_t) noexcept
Definition: STObject.h:173
std::vector< detail::STVar >
std::vector::size
T size(T... args)
ripple::STObject::getFieldU8
unsigned char getFieldU8(SField const &field) const
Definition: STObject.cpp:520
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::STObject::withAllFields
@ withAllFields
Definition: STObject.h:657
ripple::STObject::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STObject.h:286
ripple::STObject::empty
bool empty() const
Definition: STObject.h:310
ripple::STObject::getSerializer
Serializer getSerializer() const
Definition: STObject.h:367
ripple::STObject::getFieldH128
uint128 getFieldH128(SField const &field) const
Definition: STObject.cpp:544
ripple::STObject::WhichFields
WhichFields
Definition: STObject.h:653
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::setFieldVL
void setFieldVL(SField const &field, Blob const &)
Definition: STObject.cpp:668
ripple::STObject::getFieldVL
Blob getFieldVL(SField const &field) const
Definition: STObject.cpp:568
ripple::STBitString::setValue
void setValue(base_uint< Bits, Tag > const &v)
Definition: STBitString.h:91
ripple::STObject::OptionalProxy::operator==
friend bool operator==(std::nullopt_t, OptionalProxy const &rhs) noexcept
Definition: STObject.h:143
ripple::STObject::~STObject
virtual ~STObject()=default
ripple::STObject::peekAtPIndex
const STBase * peekAtPIndex(int offset) const
Definition: STObject.h:419
ripple::STObject::getFieldH160
uint160 getFieldH160(SField const &field) const
Definition: STObject.cpp:550
ripple::STBitString
Definition: SField.h:47
ripple::STObject::peekAtIndex
const STBase & peekAtIndex(int offset) const
Definition: STObject.h:409
ripple::STPathSet
Definition: STPathSet.h:309
ripple::STObject::getFullText
virtual std::string getFullText() const override
Definition: STObject.cpp:227
ripple::STObject::isEquivalent
virtual bool isEquivalent(const STBase &t) const override
Definition: STObject.cpp:277
ripple::STBase::emplace
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:149
ripple::STObject::Proxy::assign
void assign(U &&u)
Definition: STObject.h:834
stdexcept
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:74
ripple::STObject::setFieldH160
void setFieldH160(SField const &field, base_uint< 160, Tag > const &v)
Definition: STObject.h:608
ripple::STObject::OptionalProxy::operator!=
friend bool operator!=(optional_type const &lhs, OptionalProxy const &rhs) noexcept
Definition: STObject.h:191
ripple::STObject::getSType
virtual SerializedTypeID getSType() const override
Definition: STObject.h:339
ripple::STObject::FieldErr
Definition: STObject.h:258
ripple::STObject::OptionalProxy::OptionalProxy
OptionalProxy(OptionalProxy const &)=default
ripple::STObject::Proxy::st_
STObject * st_
Definition: STObject.h:61
ripple::STObject::delField
bool delField(SField const &field)
Definition: STObject.cpp:502
ripple::STObject::peekField
T & peekField(SField const &field)
Definition: STObject.h:773
ripple::STObject::ValueProxy::value_type
typename T::value_type value_type
Definition: STObject.h:81
ripple::STObject::ValueProxy
Definition: STObject.h:78
ripple::SOTemplate
Defines the fields and their attributes within a STObject.
Definition: SOTemplate.h:82
ripple::STObject::OptionalProxy
Definition: STObject.h:101
ripple::STObject::begin
iterator begin() const
Definition: STObject.h:298
ripple::STObject::setFieldArray
void setFieldArray(SField const &field, STArray const &v)
Definition: STObject.cpp:692
ripple::STObject::iterator
boost::transform_iterator< Transform, STObject::list_type::const_iterator > iterator
Definition: STObject.h:256
ripple::STObject::applyTemplate
void applyTemplate(const SOTemplate &type) noexcept(false)
Definition: STObject.cpp:89
ripple::HashPrefix
HashPrefix
Prefix for hashing functions.
Definition: HashPrefix.h:54
ripple::STObject::Proxy::f_
TypedField< T > const * f_
Definition: STObject.h:63
ripple::STObject::setFieldU8
void setFieldU8(SField const &field, unsigned char)
Definition: STObject.cpp:620
std::enable_if_t
ripple::STObject::peekFieldArray
STArray & peekFieldArray(SField const &field)
Definition: STObject.cpp:418
ripple::STObject::OptionalProxy::optional_type
std::optional< typename std::decay< value_type >::type > optional_type
Definition: STObject.h:107
ripple::STObject::setFieldAmount
void setFieldAmount(SField const &field, STAmount const &)
Definition: STObject.cpp:680
ripple::STObject::operator!=
bool operator!=(const STObject &o) const
Definition: STObject.h:647
ripple::STObject::getAccountID
AccountID getAccountID(SField const &field) const
Definition: STObject.cpp:562
ripple::STObject::setFieldH256
void setFieldH256(SField const &field, uint256 const &)
Definition: STObject.cpp:650
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::STObject::OptionalProxy::operator==
friend bool operator==(OptionalProxy const &lhs, std::nullopt_t) noexcept
Definition: STObject.h:137
ripple::STAmount
Definition: STAmount.h:43
ripple::STObject::clearFlag
bool clearFlag(std::uint32_t)
Definition: STObject.cpp:436
ripple::STObject::isDefault
virtual bool isDefault() const override
Definition: STObject.h:346
ripple::STObject::getFlags
std::uint32_t getFlags() const
Definition: STObject.cpp:454
ripple::soeINVALID
@ soeINVALID
Definition: SOTemplate.h:34
std::runtime_error
STL class.
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:197
ripple::STObject::addWithoutSigningFields
void addWithoutSigningFields(Serializer &s) const
Definition: STObject.h:358
ripple::STObject::reserve
void reserve(std::size_t n)
Definition: STObject.h:316
ripple::STObject::getFieldU16
std::uint16_t getFieldU16(SField const &field) const
Definition: STObject.cpp:526
ripple::STObject::setFieldUsingAssignment
void setFieldUsingAssignment(SField const &field, T const &value)
Definition: STObject.h:752
ripple::STObject::end
iterator end() const
Definition: STObject.h:304
ripple::STObject::getPField
STBase * getPField(SField const &field, bool createOkay=false)
Definition: STObject.cpp:385
ripple::STObject::setFieldPathSet
void setFieldPathSet(SField const &field, STPathSet const &)
Definition: STObject.cpp:686
std::decay_t
ripple::Serializer
Definition: Serializer.h:39
ripple::STObject::mType
SOTemplate const * mType
Definition: STObject.h:252
ripple::STObject::getFieldIndex
int getFieldIndex(SField const &field) const
Definition: STObject.cpp:330
ripple::STObject::makeFieldPresent
STBase * makeFieldPresent(SField const &field)
Definition: STObject.cpp:465
ripple::STObject::emplace_back
std::size_t emplace_back(Args &&... args)
Definition: STObject.h:385
ripple::STObject::ValueProxy::ValueProxy
ValueProxy(ValueProxy const &)=default
ripple::STObject
Definition: STObject.h:51
ripple::STObject::Proxy
Definition: STObject.h:56
ripple::STObject::applyTemplateFromSField
void applyTemplateFromSField(SField const &) noexcept(false)
Definition: STObject.cpp:143
ripple::STObject::move
STBase * move(std::size_t n, void *buf) override
Definition: STObject.h:292
ripple::STObject::Proxy::find
T const * find() const
Definition: STObject.h:826
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:62
std::remove_reference
ripple::STObject::peekFieldObject
STObject & peekFieldObject(SField const &field)
Definition: STObject.cpp:412
ripple::STObject::getSigningHash
uint256 getSigningHash(HashPrefix prefix) const
Definition: STObject.cpp:321
ripple::STObject::peekAtPField
const STBase * peekAtPField(SField const &field) const
Definition: STObject.cpp:374
ripple::STObject::add
virtual void add(Serializer &s) const override
Definition: STObject.h:352
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:62
ripple::STObject::getField
STBase & getField(SField const &field)
Definition: STObject.cpp:357
std::vector::begin
T begin(T... args)
ripple::SField::getName
std::string const & getName() const
Definition: SField.h:172
std
STL namespace.
ripple::STObject::isFieldPresent
bool isFieldPresent(SField const &field) const
Definition: STObject.cpp:401
ripple::STObject::getPIndex
STBase * getPIndex(int offset)
Definition: STObject.h:424
cassert
ripple::detail::STVar::get
STBase & get()
Definition: STVar.h:82
ripple::STObject::Transform
Definition: STObject.h:235
ripple::STObject::OptionalProxy::operator==
friend bool operator==(OptionalProxy const &lhs, OptionalProxy const &rhs) noexcept
Definition: STObject.h:165
ripple::STObject::OptionalProxy::operator~
optional_type operator~() const
Explicit conversion to std::optional.
Definition: STObject.h:897
ripple::STObject::Proxy::Proxy
Proxy(Proxy const &)=default
ripple::STObject::getFieldByConstRef
V const & getFieldByConstRef(SField const &field, V const &empty) const
Definition: STObject.h:706
ripple::STObject::OptionalProxy::operator==
friend bool operator==(optional_type const &lhs, OptionalProxy const &rhs) noexcept
Definition: STObject.h:159
ripple::STObject::setFieldUsingSetValue
void setFieldUsingSetValue(SField const &field, V value)
Definition: STObject.h:729
ripple::STObject::setFlag
bool setFlag(std::uint32_t)
Definition: STObject.cpp:424
ripple::STVector256
Definition: STVector256.h:29
ripple::STObject::isFlag
bool isFlag(std::uint32_t) const
Definition: STObject.cpp:448
std::vector::empty
T empty(T... args)
ripple::STObject::OptionalProxy::operator*
value_type operator*() const
Return the contained value.
Definition: STObject.h:883
std::remove_cv
ripple::STObject::Proxy::value
value_type value() const
Definition: STObject.h:813
ripple::STObject::OptionalProxy::operator!=
friend bool operator!=(std::nullopt_t, OptionalProxy const &rhs) noexcept
Definition: STObject.h:179
optional
ripple::STObject::getCount
int getCount() const
Definition: STObject.h:392
std::size_t
ripple::OptionaledField::f
TypedField< T > const * f
Definition: SField.h:299
std::vector::end
T end(T... args)
ripple::STObject::OptionalProxy::optional_value
optional_type optional_value() const
Definition: STObject.h:969
ripple::STI_OBJECT
@ STI_OBJECT
Definition: SField.h:68
ripple::STObject::operator[]
T::value_type operator[](TypedField< T > const &f) const
Get the value of a field.
Definition: STObject.h:980
ripple::STObject::getFieldU32
std::uint32_t getFieldU32(SField const &field) const
Definition: STObject.cpp:532
ripple::STObject::OptionalProxy::STObject
friend class STObject
Definition: STObject.h:221
ripple::STObject::getFieldByValue
V getFieldByValue(SField const &field) const
Definition: STObject.h:679
ripple::STObject::setFieldU64
void setFieldU64(SField const &field, std::uint64_t)
Definition: STObject.cpp:638
ripple::STObject::getJson
virtual Json::Value getJson(JsonOptions options) const override
Definition: STObject.cpp:698
ripple::STObject::Transform::operator()
STBase const & operator()(detail::STVar const &e) const
Definition: STObject.h:243
std::unique_ptr
STL class.
ripple::STObject::getFieldPathSet
STPathSet const & getFieldPathSet(SField const &field) const
Definition: STObject.cpp:583
ripple::STObject::omitSigningFields
@ omitSigningFields
Definition: STObject.h:656
ripple::STObject::set
void set(const SOTemplate &)
Definition: STObject.cpp:73
ripple::STObject::setFieldU32
void setFieldU32(SField const &field, std::uint32_t)
Definition: STObject.cpp:632
ripple::STObject::OptionalProxy::disengage
void disengage()
Definition: STObject.h:956
type_traits
ripple::STObject::getFieldAmount
STAmount const & getFieldAmount(SField const &field) const
Definition: STObject.cpp:576
ripple::soeDEFAULT
@ soeDEFAULT
Definition: SOTemplate.h:37
ripple::detail::STVar
Definition: STVar.h:49
ripple::STObject::isFree
bool isFree() const
Definition: STObject.h:328
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:312
ripple::STI_NOTPRESENT
@ STI_NOTPRESENT
Definition: SField.h:56
ripple::STObject::getText
virtual std::string getText() const override
Definition: STObject.cpp:258
ripple::STObject::getFieldH256
uint256 getFieldH256(SField const &field) const
Definition: STObject.cpp:556
ripple::STObject::OptionalProxy::value_or
value_type value_or(value_type val) const
Definition: STObject.h:204