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 <boost/optional.hpp>
36 #include <cassert>
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 =
107  boost::optional<typename std::decay<value_type>::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, boost::none_t) noexcept
138  {
139  return !lhs.engaged();
140  }
141 
142  friend bool
143  operator==(boost::none_t, OptionalProxy const& rhs) noexcept
144  {
145  return rhs == boost::none;
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
173  operator!=(OptionalProxy const& lhs, boost::none_t) noexcept
174  {
175  return !(lhs == boost::none);
176  }
177 
178  friend bool
179  operator!=(boost::none_t, OptionalProxy const& rhs) noexcept
180  {
181  return !(rhs == boost::none);
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 boost::optional::value_or
203  value_type
204  value_or(value_type val) const
205  {
206  return engaged() ? this->value() : val;
207  }
208 
210  operator=(boost::none_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>
494  boost::optional<std::decay_t<typename T::value_type>>
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>
541  boost::optional<std::decay_t<typename T::value_type>>
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  setFieldU8(SField const& field, unsigned char);
576  void
577  setFieldU16(SField const& field, std::uint16_t);
578  void
579  setFieldU32(SField const& field, std::uint32_t);
580  void
581  setFieldU64(SField const& field, std::uint64_t);
582  void
583  setFieldH128(SField const& field, uint128 const&);
584  void
585  setFieldH256(SField const& field, uint256 const&);
586  void
587  setFieldVL(SField const& field, Blob const&);
588  void
589  setFieldVL(SField const& field, Slice const&);
590 
591  void
592  setAccountID(SField const& field, AccountID const&);
593 
594  void
595  setFieldAmount(SField const& field, STAmount const&);
596  void
597  setFieldPathSet(SField const& field, STPathSet const&);
598  void
599  setFieldV256(SField const& field, STVector256 const& v);
600  void
601  setFieldArray(SField const& field, STArray const& v);
602 
603  template <class Tag>
604  void
605  setFieldH160(SField const& field, base_uint<160, Tag> const& v)
606  {
607  STBase* rf = getPField(field, true);
608 
609  if (!rf)
610  throwFieldNotFound(field);
611 
612  if (rf->getSType() == STI_NOTPRESENT)
613  rf = makeFieldPresent(field);
614 
615  using Bits = STBitString<160>;
616  if (auto cf = dynamic_cast<Bits*>(rf))
617  cf->setValue(v);
618  else
619  Throw<std::runtime_error>("Wrong field type");
620  }
621 
622  STObject&
623  peekFieldObject(SField const& field);
624  STArray&
625  peekFieldArray(SField const& field);
626 
627  bool
628  isFieldPresent(SField const& field) const;
629  STBase*
630  makeFieldPresent(SField const& field);
631  void
632  makeFieldAbsent(SField const& field);
633  bool
634  delField(SField const& field);
635  void
636  delField(int index);
637 
638  bool
639  hasMatchingEntry(const STBase&);
640 
641  bool
642  operator==(const STObject& o) const;
643  bool
644  operator!=(const STObject& o) const
645  {
646  return !(*this == o);
647  }
648 
649 private:
650  enum WhichFields : bool {
651  // These values are carefully chosen to do the right thing if passed
652  // to SField::shouldInclude (bool)
655  };
656 
657  void
658  add(Serializer& s, WhichFields whichFields) const;
659 
660  // Sort the entries in an STObject into the order that they will be
661  // serialized. Note: they are not sorted into pointer value order, they
662  // are sorted by SField::fieldCode.
664  getSortedFields(STObject const& objToSort, WhichFields whichFields);
665 
666  // Implementation for getting (most) fields that return by value.
667  //
668  // The remove_cv and remove_reference are necessitated by the STBitString
669  // types. Their value() returns by const ref. We return those types
670  // by value.
671  template <
672  typename T,
673  typename V = typename std::remove_cv<typename std::remove_reference<
674  decltype(std::declval<T>().value())>::type>::type>
675  V
676  getFieldByValue(SField const& field) const
677  {
678  const STBase* rf = peekAtPField(field);
679 
680  if (!rf)
681  throwFieldNotFound(field);
682 
683  SerializedTypeID id = rf->getSType();
684 
685  if (id == STI_NOTPRESENT)
686  return V(); // optional field not present
687 
688  const T* cf = dynamic_cast<const T*>(rf);
689 
690  if (!cf)
691  Throw<std::runtime_error>("Wrong field type");
692 
693  return cf->value();
694  }
695 
696  // Implementations for getting (most) fields that return by const reference.
697  //
698  // If an absent optional field is deserialized we don't have anything
699  // obvious to return. So we insist on having the call provide an
700  // 'empty' value we return in that circumstance.
701  template <typename T, typename V>
702  V const&
703  getFieldByConstRef(SField const& field, V const& empty) const
704  {
705  const STBase* rf = peekAtPField(field);
706 
707  if (!rf)
708  throwFieldNotFound(field);
709 
710  SerializedTypeID id = rf->getSType();
711 
712  if (id == STI_NOTPRESENT)
713  return empty; // optional field not present
714 
715  const T* cf = dynamic_cast<const T*>(rf);
716 
717  if (!cf)
718  Throw<std::runtime_error>("Wrong field type");
719 
720  return *cf;
721  }
722 
723  // Implementation for setting most fields with a setValue() method.
724  template <typename T, typename V>
725  void
727  {
728  static_assert(!std::is_lvalue_reference<V>::value, "");
729 
730  STBase* rf = getPField(field, true);
731 
732  if (!rf)
733  throwFieldNotFound(field);
734 
735  if (rf->getSType() == STI_NOTPRESENT)
736  rf = makeFieldPresent(field);
737 
738  T* cf = dynamic_cast<T*>(rf);
739 
740  if (!cf)
741  Throw<std::runtime_error>("Wrong field type");
742 
743  cf->setValue(std::move(value));
744  }
745 
746  // Implementation for setting fields using assignment
747  template <typename T>
748  void
749  setFieldUsingAssignment(SField const& field, T const& value)
750  {
751  STBase* rf = getPField(field, true);
752 
753  if (!rf)
754  throwFieldNotFound(field);
755 
756  if (rf->getSType() == STI_NOTPRESENT)
757  rf = makeFieldPresent(field);
758 
759  T* cf = dynamic_cast<T*>(rf);
760 
761  if (!cf)
762  Throw<std::runtime_error>("Wrong field type");
763 
764  (*cf) = value;
765  }
766 
767  // Implementation for peeking STObjects and STArrays
768  template <typename T>
769  T&
770  peekField(SField const& field)
771  {
772  STBase* rf = getPField(field, true);
773 
774  if (!rf)
775  throwFieldNotFound(field);
776 
777  if (rf->getSType() == STI_NOTPRESENT)
778  rf = makeFieldPresent(field);
779 
780  T* cf = dynamic_cast<T*>(rf);
781 
782  if (!cf)
783  Throw<std::runtime_error>("Wrong field type");
784 
785  return *cf;
786  }
787 };
788 
789 //------------------------------------------------------------------------------
790 
791 template <class T>
792 STObject::Proxy<T>::Proxy(STObject* st, TypedField<T> const* f) : st_(st), f_(f)
793 {
794  if (st_->mType)
795  {
796  // STObject has associated template
797  if (!st_->peekAtPField(*f_))
798  Throw<STObject::FieldErr>(
799  "Template field error '" + this->f_->getName() + "'");
800  style_ = st_->mType->style(*f_);
801  }
802  else
803  {
804  style_ = soeINVALID;
805  }
806 }
807 
808 template <class T>
809 auto
811 {
812  auto const t = find();
813  if (t)
814  return t->value();
815  if (style_ != soeDEFAULT)
816  Throw<STObject::FieldErr>(
817  "Missing field '" + this->f_->getName() + "'");
818  return value_type{};
819 }
820 
821 template <class T>
822 inline T const*
824 {
825  return dynamic_cast<T const*>(st_->peekAtPField(*f_));
826 }
827 
828 template <class T>
829 template <class U>
830 void
832 {
833  if (style_ == soeDEFAULT && u == value_type{})
834  {
835  st_->makeFieldAbsent(*f_);
836  return;
837  }
838  T* t;
839  if (style_ == soeINVALID)
840  t = dynamic_cast<T*>(st_->getPField(*f_, true));
841  else
842  t = dynamic_cast<T*>(st_->makeFieldPresent(*f_));
843  assert(t);
844  *t = std::forward<U>(u);
845 }
846 
847 //------------------------------------------------------------------------------
848 
849 template <class T>
850 template <class U>
853 {
854  this->assign(std::forward<U>(u));
855  return *this;
856 }
857 
858 template <class T>
860 {
861  return this->value();
862 }
863 
864 template <class T>
866  : Proxy<T>(st, f)
867 {
868 }
869 
870 //------------------------------------------------------------------------------
871 
872 template <class T>
874 {
875  return engaged();
876 }
877 
878 template <class T>
879 auto
881 {
882  return this->value();
883 }
884 
885 template <class T>
887  T>::optional_type() const
888 {
889  return optional_value();
890 }
891 
892 template <class T>
895 {
896  return optional_value();
897 }
898 
899 template <class T>
900 auto
902 {
903  disengage();
904  return *this;
905 }
906 
907 template <class T>
908 auto
910 {
911  if (v)
912  this->assign(std::move(*v));
913  else
914  disengage();
915  return *this;
916 }
917 
918 template <class T>
919 auto
921 {
922  if (v)
923  this->assign(*v);
924  else
925  disengage();
926  return *this;
927 }
928 
929 template <class T>
930 template <class U>
933 {
934  this->assign(std::forward<U>(u));
935  return *this;
936 }
937 
938 template <class T>
940  : Proxy<T>(st, f)
941 {
942 }
943 
944 template <class T>
945 bool
947 {
948  return this->style_ == soeDEFAULT || this->find() != nullptr;
949 }
950 
951 template <class T>
952 void
954 {
955  if (this->style_ == soeREQUIRED || this->style_ == soeDEFAULT)
956  Throw<STObject::FieldErr>(
957  "Template field error '" + this->f_->getName() + "'");
958  if (this->style_ == soeINVALID)
959  this->st_->delField(*this->f_);
960  else
961  this->st_->makeFieldAbsent(*this->f_);
962 }
963 
964 template <class T>
965 auto
967 {
968  if (!engaged())
969  return boost::none;
970  return this->value();
971 }
972 
973 //------------------------------------------------------------------------------
974 
975 template <class T>
976 typename T::value_type
978 {
979  return at(f);
980 }
981 
982 template <class T>
983 boost::optional<std::decay_t<typename T::value_type>>
985 {
986  return at(of);
987 }
988 
989 template <class T>
990 inline auto
992 {
993  return at(f);
994 }
995 
996 template <class T>
997 inline auto
999 {
1000  return at(of);
1001 }
1002 
1003 template <class T>
1004 typename T::value_type
1006 {
1007  auto const b = peekAtPField(f);
1008  if (!b)
1009  // This is a free object (no constraints)
1010  // with no template
1011  Throw<STObject::FieldErr>("Missing field '" + f.getName() + "'");
1012  auto const u = dynamic_cast<T const*>(b);
1013  if (!u)
1014  {
1015  assert(mType);
1016  assert(b->getSType() == STI_NOTPRESENT);
1017  if (mType->style(f) == soeOPTIONAL)
1018  Throw<STObject::FieldErr>("Missing field '" + f.getName() + "'");
1019  assert(mType->style(f) == soeDEFAULT);
1020  // Handle the case where value_type is a
1021  // const reference, otherwise we return
1022  // the address of a temporary.
1023  static std::decay_t<typename T::value_type> const dv{};
1024  return dv;
1025  }
1026  return u->value();
1027 }
1028 
1029 template <class T>
1030 boost::optional<std::decay_t<typename T::value_type>>
1032 {
1033  auto const b = peekAtPField(*of.f);
1034  if (!b)
1035  return boost::none;
1036  auto const u = dynamic_cast<T const*>(b);
1037  if (!u)
1038  {
1039  assert(mType);
1040  assert(b->getSType() == STI_NOTPRESENT);
1041  if (mType->style(*of.f) == soeOPTIONAL)
1042  return boost::none;
1043  assert(mType->style(*of.f) == soeDEFAULT);
1044  return typename T::value_type{};
1045  }
1046  return u->value();
1047 }
1048 
1049 template <class T>
1050 inline auto
1052 {
1053  return ValueProxy<T>(this, &f);
1054 }
1055 
1056 template <class T>
1057 inline auto
1059 {
1060  return OptionalProxy<T>(this, of.f);
1061 }
1062 
1063 } // namespace ripple
1064 
1065 #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:946
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:135
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:1005
ripple::STObject::OptionalProxy::operator!=
friend bool operator!=(OptionalProxy const &lhs, boost::none_t) noexcept
Definition: STObject.h:173
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
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:654
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:650
ripple::soeREQUIRED
@ soeREQUIRED
Definition: SOTemplate.h:34
ripple::OptionaledField
Indicate boost::optional field semantics.
Definition: SField.h:297
ripple::STObject::OptionalProxy::operator=
OptionalProxy & operator=(OptionalProxy const &)=delete
boost
Definition: IPAddress.h:117
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::STObject::OptionalProxy::operator==
friend bool operator==(boost::none_t, OptionalProxy const &rhs) noexcept
Definition: STObject.h:143
ripple::STBitString::setValue
void setValue(base_uint< Bits, Tag > const &v)
Definition: STBitString.h:91
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:831
stdexcept
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:73
ripple::STObject::setFieldH160
void setFieldH160(SField const &field, base_uint< 160, Tag > const &v)
Definition: STObject.h:605
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:770
ripple::STObject::ValueProxy::value_type
typename T::value_type value_type
Definition: STObject.h:81
ripple::STObject::ValueProxy
Definition: STObject.h:78
ripple::STObject::OptionalProxy::operator==
friend bool operator==(OptionalProxy const &lhs, boost::none_t) noexcept
Definition: STObject.h:137
ripple::SOTemplate
Defines the fields and their attributes within a STObject.
Definition: SOTemplate.h:81
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::setFieldAmount
void setFieldAmount(SField const &field, STAmount const &)
Definition: STObject.cpp:680
ripple::STObject::operator!=
bool operator!=(const STObject &o) const
Definition: STObject.h:644
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:35
ripple::SOEStyle
SOEStyle
Kind of element in each entry of an SOTemplate.
Definition: SOTemplate.h:32
ripple::throwFieldNotFound
void throwFieldNotFound(SField const &field)
Definition: STObject.h:46
ripple::STArray
Definition: STArray.h:28
ripple::STAmount
Definition: STAmount.h:42
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:33
std::runtime_error
STL class.
ripple::SerialIter
Definition: Serializer.h:308
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::OptionalProxy::optional_type
boost::optional< typename std::decay< value_type >::type > optional_type
Definition: STObject.h:107
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:749
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:823
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
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
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 boost::optional.
Definition: STObject.h:894
ripple::STObject::Proxy::Proxy
Proxy(Proxy const &)=default
ripple::STObject::getFieldByConstRef
V const & getFieldByConstRef(SField const &field, V const &empty) const
Definition: STObject.h:703
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:726
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:880
ripple::STObject::OptionalProxy::operator!=
friend bool operator!=(boost::none_t, OptionalProxy const &rhs) noexcept
Definition: STObject.h:179
std::remove_cv
ripple::STObject::Proxy::value
value_type value() const
Definition: STObject.h:810
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:966
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:977
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:676
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:653
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:953
type_traits
ripple::STObject::getFieldAmount
STAmount const & getFieldAmount(SField const &field) const
Definition: STObject.cpp:576
ripple::soeDEFAULT
@ soeDEFAULT
Definition: SOTemplate.h:36
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