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  static char const*
265  {
266  return "STObject";
267  }
268 
269  STObject(STObject&&);
270  STObject(STObject const&) = default;
271  STObject(const SOTemplate& type, SField const& name);
272  STObject(
273  const SOTemplate& type,
274  SerialIter& sit,
275  SField const& name) noexcept(false);
276  STObject(SerialIter& sit, SField const& name, int depth = 0) noexcept(
277  false);
278  STObject(SerialIter&& sit, SField const& name) noexcept(false)
279  : STObject(sit, name)
280  {
281  }
282  STObject&
283  operator=(STObject const&) = default;
284  STObject&
285  operator=(STObject&& other);
286 
287  explicit STObject(SField const& name);
288 
289  virtual ~STObject() = default;
290 
291  STBase*
292  copy(std::size_t n, void* buf) const override
293  {
294  return emplace(n, buf, *this);
295  }
296 
297  STBase*
298  move(std::size_t n, void* buf) override
299  {
300  return emplace(n, buf, std::move(*this));
301  }
302 
303  iterator
304  begin() const
305  {
306  return iterator(v_.begin());
307  }
308 
309  iterator
310  end() const
311  {
312  return iterator(v_.end());
313  }
314 
315  bool
316  empty() const
317  {
318  return v_.empty();
319  }
320 
321  void
323  {
324  v_.reserve(n);
325  }
326 
327  void
328  applyTemplate(const SOTemplate& type) noexcept(false);
329 
330  void
331  applyTemplateFromSField(SField const&) noexcept(false);
332 
333  bool
334  isFree() const
335  {
336  return mType == nullptr;
337  }
338 
339  void
340  set(const SOTemplate&);
341  bool
342  set(SerialIter& u, int depth = 0);
343 
344  virtual SerializedTypeID
345  getSType() const override
346  {
347  return STI_OBJECT;
348  }
349  virtual bool
350  isEquivalent(const STBase& t) const override;
351  virtual bool
352  isDefault() const override
353  {
354  return v_.empty();
355  }
356 
357  virtual void
358  add(Serializer& s) const override
359  {
360  add(s, withAllFields); // just inner elements
361  }
362 
363  void
365  {
367  }
368 
369  // VFALCO NOTE does this return an expensive copy of an object with a
370  // dynamic buffer?
371  // VFALCO TODO Remove this function and fix the few callers.
372  Serializer
374  {
375  Serializer s;
376  add(s, withAllFields);
377  return s;
378  }
379 
380  virtual std::string
381  getFullText() const override;
382  virtual std::string
383  getText() const override;
384 
385  // TODO(tom): options should be an enum.
386  virtual Json::Value
387  getJson(JsonOptions options) const override;
388 
389  template <class... Args>
391  emplace_back(Args&&... args)
392  {
393  v_.emplace_back(std::forward<Args>(args)...);
394  return v_.size() - 1;
395  }
396 
397  int
398  getCount() const
399  {
400  return v_.size();
401  }
402 
403  bool setFlag(std::uint32_t);
404  bool clearFlag(std::uint32_t);
405  bool isFlag(std::uint32_t) const;
407  getFlags() const;
408 
409  uint256
410  getHash(HashPrefix prefix) const;
411  uint256
412  getSigningHash(HashPrefix prefix) const;
413 
414  const STBase&
415  peekAtIndex(int offset) const
416  {
417  return v_[offset].get();
418  }
419  STBase&
420  getIndex(int offset)
421  {
422  return v_[offset].get();
423  }
424  const STBase*
425  peekAtPIndex(int offset) const
426  {
427  return &v_[offset].get();
428  }
429  STBase*
430  getPIndex(int offset)
431  {
432  return &v_[offset].get();
433  }
434 
435  int
436  getFieldIndex(SField const& field) const;
437  SField const&
438  getFieldSType(int index) const;
439 
440  const STBase&
441  peekAtField(SField const& field) const;
442  STBase&
443  getField(SField const& field);
444  const STBase*
445  peekAtPField(SField const& field) const;
446  STBase*
447  getPField(SField const& field, bool createOkay = false);
448 
449  // these throw if the field type doesn't match, or return default values
450  // if the field is optional but not present
451  unsigned char
452  getFieldU8(SField const& field) const;
454  getFieldU16(SField const& field) const;
456  getFieldU32(SField const& field) const;
458  getFieldU64(SField const& field) const;
459  uint128
460  getFieldH128(SField const& field) const;
461 
462  uint160
463  getFieldH160(SField const& field) const;
464  uint256
465  getFieldH256(SField const& field) const;
466  AccountID
467  getAccountID(SField const& field) const;
468 
469  Blob
470  getFieldVL(SField const& field) const;
471  STAmount const&
472  getFieldAmount(SField const& field) const;
473  STPathSet const&
474  getFieldPathSet(SField const& field) const;
475  const STVector256&
476  getFieldV256(SField const& field) const;
477  const STArray&
478  getFieldArray(SField const& field) const;
479 
487  template <class T>
488  typename T::value_type
489  operator[](TypedField<T> const& f) const;
490 
499  template <class T>
500  boost::optional<std::decay_t<typename T::value_type>>
501  operator[](OptionaledField<T> const& of) const;
502 
510  template <class T>
511  ValueProxy<T>
512  operator[](TypedField<T> const& f);
513 
523  template <class T>
524  OptionalProxy<T>
525  operator[](OptionaledField<T> const& of);
526 
534  template <class T>
535  typename T::value_type
536  at(TypedField<T> const& f) const;
537 
546  template <class T>
547  boost::optional<std::decay_t<typename T::value_type>>
548  at(OptionaledField<T> const& of) const;
549 
557  template <class T>
558  ValueProxy<T>
559  at(TypedField<T> const& f);
560 
570  template <class T>
571  OptionalProxy<T>
572  at(OptionaledField<T> const& of);
573 
577  void
579 
580  void
581  setFieldU8(SField const& field, unsigned char);
582  void
583  setFieldU16(SField const& field, std::uint16_t);
584  void
585  setFieldU32(SField const& field, std::uint32_t);
586  void
587  setFieldU64(SField const& field, std::uint64_t);
588  void
589  setFieldH128(SField const& field, uint128 const&);
590  void
591  setFieldH256(SField const& field, uint256 const&);
592  void
593  setFieldVL(SField const& field, Blob const&);
594  void
595  setFieldVL(SField const& field, Slice const&);
596 
597  void
598  setAccountID(SField const& field, AccountID const&);
599 
600  void
601  setFieldAmount(SField const& field, STAmount const&);
602  void
603  setFieldPathSet(SField const& field, STPathSet const&);
604  void
605  setFieldV256(SField const& field, STVector256 const& v);
606  void
607  setFieldArray(SField const& field, STArray const& v);
608 
609  template <class Tag>
610  void
611  setFieldH160(SField const& field, base_uint<160, Tag> const& v)
612  {
613  STBase* rf = getPField(field, true);
614 
615  if (!rf)
616  throwFieldNotFound(field);
617 
618  if (rf->getSType() == STI_NOTPRESENT)
619  rf = makeFieldPresent(field);
620 
621  using Bits = STBitString<160>;
622  if (auto cf = dynamic_cast<Bits*>(rf))
623  cf->setValue(v);
624  else
625  Throw<std::runtime_error>("Wrong field type");
626  }
627 
628  STObject&
629  peekFieldObject(SField const& field);
630  STArray&
631  peekFieldArray(SField const& field);
632 
633  bool
634  isFieldPresent(SField const& field) const;
635  STBase*
636  makeFieldPresent(SField const& field);
637  void
638  makeFieldAbsent(SField const& field);
639  bool
640  delField(SField const& field);
641  void
642  delField(int index);
643 
644  bool
645  hasMatchingEntry(const STBase&);
646 
647  bool
648  operator==(const STObject& o) const;
649  bool
650  operator!=(const STObject& o) const
651  {
652  return !(*this == o);
653  }
654 
655 private:
656  enum WhichFields : bool {
657  // These values are carefully chosen to do the right thing if passed
658  // to SField::shouldInclude (bool)
661  };
662 
663  void
664  add(Serializer& s, WhichFields whichFields) const;
665 
666  // Sort the entries in an STObject into the order that they will be
667  // serialized. Note: they are not sorted into pointer value order, they
668  // are sorted by SField::fieldCode.
670  getSortedFields(STObject const& objToSort, WhichFields whichFields);
671 
672  // Implementation for getting (most) fields that return by value.
673  //
674  // The remove_cv and remove_reference are necessitated by the STBitString
675  // types. Their value() returns by const ref. We return those types
676  // by value.
677  template <
678  typename T,
679  typename V = typename std::remove_cv<typename std::remove_reference<
680  decltype(std::declval<T>().value())>::type>::type>
681  V
682  getFieldByValue(SField const& field) const
683  {
684  const STBase* rf = peekAtPField(field);
685 
686  if (!rf)
687  throwFieldNotFound(field);
688 
689  SerializedTypeID id = rf->getSType();
690 
691  if (id == STI_NOTPRESENT)
692  return V(); // optional field not present
693 
694  const T* cf = dynamic_cast<const T*>(rf);
695 
696  if (!cf)
697  Throw<std::runtime_error>("Wrong field type");
698 
699  return cf->value();
700  }
701 
702  // Implementations for getting (most) fields that return by const reference.
703  //
704  // If an absent optional field is deserialized we don't have anything
705  // obvious to return. So we insist on having the call provide an
706  // 'empty' value we return in that circumstance.
707  template <typename T, typename V>
708  V const&
709  getFieldByConstRef(SField const& field, V const& empty) const
710  {
711  const STBase* rf = peekAtPField(field);
712 
713  if (!rf)
714  throwFieldNotFound(field);
715 
716  SerializedTypeID id = rf->getSType();
717 
718  if (id == STI_NOTPRESENT)
719  return empty; // optional field not present
720 
721  const T* cf = dynamic_cast<const T*>(rf);
722 
723  if (!cf)
724  Throw<std::runtime_error>("Wrong field type");
725 
726  return *cf;
727  }
728 
729  // Implementation for setting most fields with a setValue() method.
730  template <typename T, typename V>
731  void
733  {
734  static_assert(!std::is_lvalue_reference<V>::value, "");
735 
736  STBase* rf = getPField(field, true);
737 
738  if (!rf)
739  throwFieldNotFound(field);
740 
741  if (rf->getSType() == STI_NOTPRESENT)
742  rf = makeFieldPresent(field);
743 
744  T* cf = dynamic_cast<T*>(rf);
745 
746  if (!cf)
747  Throw<std::runtime_error>("Wrong field type");
748 
749  cf->setValue(std::move(value));
750  }
751 
752  // Implementation for setting fields using assignment
753  template <typename T>
754  void
755  setFieldUsingAssignment(SField const& field, T const& value)
756  {
757  STBase* rf = getPField(field, true);
758 
759  if (!rf)
760  throwFieldNotFound(field);
761 
762  if (rf->getSType() == STI_NOTPRESENT)
763  rf = makeFieldPresent(field);
764 
765  T* cf = dynamic_cast<T*>(rf);
766 
767  if (!cf)
768  Throw<std::runtime_error>("Wrong field type");
769 
770  (*cf) = value;
771  }
772 
773  // Implementation for peeking STObjects and STArrays
774  template <typename T>
775  T&
776  peekField(SField const& field)
777  {
778  STBase* rf = getPField(field, true);
779 
780  if (!rf)
781  throwFieldNotFound(field);
782 
783  if (rf->getSType() == STI_NOTPRESENT)
784  rf = makeFieldPresent(field);
785 
786  T* cf = dynamic_cast<T*>(rf);
787 
788  if (!cf)
789  Throw<std::runtime_error>("Wrong field type");
790 
791  return *cf;
792  }
793 };
794 
795 //------------------------------------------------------------------------------
796 
797 template <class T>
798 STObject::Proxy<T>::Proxy(STObject* st, TypedField<T> const* f) : st_(st), f_(f)
799 {
800  if (st_->mType)
801  {
802  // STObject has associated template
803  if (!st_->peekAtPField(*f_))
804  Throw<STObject::FieldErr>(
805  "Template field error '" + this->f_->getName() + "'");
806  style_ = st_->mType->style(*f_);
807  }
808  else
809  {
810  style_ = soeINVALID;
811  }
812 }
813 
814 template <class T>
815 auto
817 {
818  auto const t = find();
819  if (t)
820  return t->value();
821  if (style_ != soeDEFAULT)
822  Throw<STObject::FieldErr>(
823  "Missing field '" + this->f_->getName() + "'");
824  return value_type{};
825 }
826 
827 template <class T>
828 inline T const*
830 {
831  return dynamic_cast<T const*>(st_->peekAtPField(*f_));
832 }
833 
834 template <class T>
835 template <class U>
836 void
838 {
839  if (style_ == soeDEFAULT && u == value_type{})
840  {
841  st_->makeFieldAbsent(*f_);
842  return;
843  }
844  T* t;
845  if (style_ == soeINVALID)
846  t = dynamic_cast<T*>(st_->getPField(*f_, true));
847  else
848  t = dynamic_cast<T*>(st_->makeFieldPresent(*f_));
849  assert(t);
850  *t = std::forward<U>(u);
851 }
852 
853 //------------------------------------------------------------------------------
854 
855 template <class T>
856 template <class U>
859 {
860  this->assign(std::forward<U>(u));
861  return *this;
862 }
863 
864 template <class T>
866 {
867  return this->value();
868 }
869 
870 template <class T>
872  : Proxy<T>(st, f)
873 {
874 }
875 
876 //------------------------------------------------------------------------------
877 
878 template <class T>
880 {
881  return engaged();
882 }
883 
884 template <class T>
885 auto
887 {
888  return this->value();
889 }
890 
891 template <class T>
893  T>::optional_type() const
894 {
895  return optional_value();
896 }
897 
898 template <class T>
901 {
902  return optional_value();
903 }
904 
905 template <class T>
906 auto
908 {
909  disengage();
910  return *this;
911 }
912 
913 template <class T>
914 auto
916 {
917  if (v)
918  this->assign(std::move(*v));
919  else
920  disengage();
921  return *this;
922 }
923 
924 template <class T>
925 auto
927 {
928  if (v)
929  this->assign(*v);
930  else
931  disengage();
932  return *this;
933 }
934 
935 template <class T>
936 template <class U>
939 {
940  this->assign(std::forward<U>(u));
941  return *this;
942 }
943 
944 template <class T>
946  : Proxy<T>(st, f)
947 {
948 }
949 
950 template <class T>
951 bool
953 {
954  return this->style_ == soeDEFAULT || this->find() != nullptr;
955 }
956 
957 template <class T>
958 void
960 {
961  if (this->style_ == soeREQUIRED || this->style_ == soeDEFAULT)
962  Throw<STObject::FieldErr>(
963  "Template field error '" + this->f_->getName() + "'");
964  if (this->style_ == soeINVALID)
965  this->st_->delField(*this->f_);
966  else
967  this->st_->makeFieldAbsent(*this->f_);
968 }
969 
970 template <class T>
971 auto
973 {
974  if (!engaged())
975  return boost::none;
976  return this->value();
977 }
978 
979 //------------------------------------------------------------------------------
980 
981 template <class T>
982 typename T::value_type
984 {
985  return at(f);
986 }
987 
988 template <class T>
989 boost::optional<std::decay_t<typename T::value_type>>
991 {
992  return at(of);
993 }
994 
995 template <class T>
996 inline auto
998 {
999  return at(f);
1000 }
1001 
1002 template <class T>
1003 inline auto
1005 {
1006  return at(of);
1007 }
1008 
1009 template <class T>
1010 typename T::value_type
1012 {
1013  auto const b = peekAtPField(f);
1014  if (!b)
1015  // This is a free object (no constraints)
1016  // with no template
1017  Throw<STObject::FieldErr>("Missing field '" + f.getName() + "'");
1018  auto const u = dynamic_cast<T const*>(b);
1019  if (!u)
1020  {
1021  assert(mType);
1022  assert(b->getSType() == STI_NOTPRESENT);
1023  if (mType->style(f) == soeOPTIONAL)
1024  Throw<STObject::FieldErr>("Missing field '" + f.getName() + "'");
1025  assert(mType->style(f) == soeDEFAULT);
1026  // Handle the case where value_type is a
1027  // const reference, otherwise we return
1028  // the address of a temporary.
1029  static std::decay_t<typename T::value_type> const dv{};
1030  return dv;
1031  }
1032  return u->value();
1033 }
1034 
1035 template <class T>
1036 boost::optional<std::decay_t<typename T::value_type>>
1038 {
1039  auto const b = peekAtPField(*of.f);
1040  if (!b)
1041  return boost::none;
1042  auto const u = dynamic_cast<T const*>(b);
1043  if (!u)
1044  {
1045  assert(mType);
1046  assert(b->getSType() == STI_NOTPRESENT);
1047  if (mType->style(*of.f) == soeOPTIONAL)
1048  return boost::none;
1049  assert(mType->style(*of.f) == soeDEFAULT);
1050  return typename T::value_type{};
1051  }
1052  return u->value();
1053 }
1054 
1055 template <class T>
1056 inline auto
1058 {
1059  return ValueProxy<T>(this, &f);
1060 }
1061 
1062 template <class T>
1063 inline auto
1065 {
1066  return OptionalProxy<T>(this, of.f);
1067 }
1068 
1069 } // namespace ripple
1070 
1071 #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:420
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:952
ripple::STObject::getFieldArray
const STArray & getFieldArray(SField const &field) const
Definition: STObject.cpp:597
ripple::STBase::getSType
virtual SerializedTypeID getSType() const
Definition: STBase.cpp:67
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:110
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:1011
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:660
ripple::STObject::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STObject.h:292
ripple::STObject::empty
bool empty() const
Definition: STObject.h:316
ripple::STObject::getSerializer
Serializer getSerializer() const
Definition: STObject.h:373
ripple::STObject::getFieldH128
uint128 getFieldH128(SField const &field) const
Definition: STObject.cpp:544
ripple::STObject::WhichFields
WhichFields
Definition: STObject.h:656
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:101
ripple::STObject::~STObject
virtual ~STObject()=default
ripple::STObject::peekAtPIndex
const STBase * peekAtPIndex(int offset) const
Definition: STObject.h:425
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:415
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:837
stdexcept
ripple::base_uint< 256 >
ripple::STObject::setFieldH160
void setFieldH160(SField const &field, base_uint< 160, Tag > const &v)
Definition: STObject.h:611
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:345
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:776
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:304
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:650
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:352
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:364
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:322
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:755
ripple::STObject::end
iterator end() const
Definition: STObject.h:310
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
ripple::STObject::getCountedObjectName
static char const * getCountedObjectName()
Definition: STObject.h:264
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:391
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:298
ripple::STObject::Proxy::find
T const * find() const
Definition: STObject.h:829
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:358
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:430
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:900
ripple::STObject::Proxy::Proxy
Proxy(Proxy const &)=default
ripple::STObject::getFieldByConstRef
V const & getFieldByConstRef(SField const &field, V const &empty) const
Definition: STObject.h:709
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:732
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:886
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:816
ripple::STObject::getCount
int getCount() const
Definition: STObject.h:398
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:972
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:983
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:682
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:659
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:959
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:334
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