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 
495  template <class T>
496  boost::optional<std::decay_t<typename T::value_type>>
497  operator[](OptionaledField<T> const& of) const;
498 
506  template <class T>
507  ValueProxy<T>
508  operator[](TypedField<T> const& f);
509 
515  template <class T>
516  OptionalProxy<T>
517  operator[](OptionaledField<T> const& of);
518 
522  void
524 
525  void
526  setFieldU8(SField const& field, unsigned char);
527  void
528  setFieldU16(SField const& field, std::uint16_t);
529  void
530  setFieldU32(SField const& field, std::uint32_t);
531  void
532  setFieldU64(SField const& field, std::uint64_t);
533  void
534  setFieldH128(SField const& field, uint128 const&);
535  void
536  setFieldH256(SField const& field, uint256 const&);
537  void
538  setFieldVL(SField const& field, Blob const&);
539  void
540  setFieldVL(SField const& field, Slice const&);
541 
542  void
543  setAccountID(SField const& field, AccountID const&);
544 
545  void
546  setFieldAmount(SField const& field, STAmount const&);
547  void
548  setFieldPathSet(SField const& field, STPathSet const&);
549  void
550  setFieldV256(SField const& field, STVector256 const& v);
551  void
552  setFieldArray(SField const& field, STArray const& v);
553 
554  template <class Tag>
555  void
556  setFieldH160(SField const& field, base_uint<160, Tag> const& v)
557  {
558  STBase* rf = getPField(field, true);
559 
560  if (!rf)
561  throwFieldNotFound(field);
562 
563  if (rf->getSType() == STI_NOTPRESENT)
564  rf = makeFieldPresent(field);
565 
566  using Bits = STBitString<160>;
567  if (auto cf = dynamic_cast<Bits*>(rf))
568  cf->setValue(v);
569  else
570  Throw<std::runtime_error>("Wrong field type");
571  }
572 
573  STObject&
574  peekFieldObject(SField const& field);
575  STArray&
576  peekFieldArray(SField const& field);
577 
578  bool
579  isFieldPresent(SField const& field) const;
580  STBase*
581  makeFieldPresent(SField const& field);
582  void
583  makeFieldAbsent(SField const& field);
584  bool
585  delField(SField const& field);
586  void
587  delField(int index);
588 
589  bool
590  hasMatchingEntry(const STBase&);
591 
592  bool
593  operator==(const STObject& o) const;
594  bool
595  operator!=(const STObject& o) const
596  {
597  return !(*this == o);
598  }
599 
600 private:
601  enum WhichFields : bool {
602  // These values are carefully chosen to do the right thing if passed
603  // to SField::shouldInclude (bool)
606  };
607 
608  void
609  add(Serializer& s, WhichFields whichFields) const;
610 
611  // Sort the entries in an STObject into the order that they will be
612  // serialized. Note: they are not sorted into pointer value order, they
613  // are sorted by SField::fieldCode.
615  getSortedFields(STObject const& objToSort, WhichFields whichFields);
616 
617  // Implementation for getting (most) fields that return by value.
618  //
619  // The remove_cv and remove_reference are necessitated by the STBitString
620  // types. Their value() returns by const ref. We return those types
621  // by value.
622  template <
623  typename T,
624  typename V = typename std::remove_cv<typename std::remove_reference<
625  decltype(std::declval<T>().value())>::type>::type>
626  V
627  getFieldByValue(SField const& field) const
628  {
629  const STBase* rf = peekAtPField(field);
630 
631  if (!rf)
632  throwFieldNotFound(field);
633 
634  SerializedTypeID id = rf->getSType();
635 
636  if (id == STI_NOTPRESENT)
637  return V(); // optional field not present
638 
639  const T* cf = dynamic_cast<const T*>(rf);
640 
641  if (!cf)
642  Throw<std::runtime_error>("Wrong field type");
643 
644  return cf->value();
645  }
646 
647  // Implementations for getting (most) fields that return by const reference.
648  //
649  // If an absent optional field is deserialized we don't have anything
650  // obvious to return. So we insist on having the call provide an
651  // 'empty' value we return in that circumstance.
652  template <typename T, typename V>
653  V const&
654  getFieldByConstRef(SField const& field, V const& empty) const
655  {
656  const STBase* rf = peekAtPField(field);
657 
658  if (!rf)
659  throwFieldNotFound(field);
660 
661  SerializedTypeID id = rf->getSType();
662 
663  if (id == STI_NOTPRESENT)
664  return empty; // optional field not present
665 
666  const T* cf = dynamic_cast<const T*>(rf);
667 
668  if (!cf)
669  Throw<std::runtime_error>("Wrong field type");
670 
671  return *cf;
672  }
673 
674  // Implementation for setting most fields with a setValue() method.
675  template <typename T, typename V>
676  void
678  {
679  static_assert(!std::is_lvalue_reference<V>::value, "");
680 
681  STBase* rf = getPField(field, true);
682 
683  if (!rf)
684  throwFieldNotFound(field);
685 
686  if (rf->getSType() == STI_NOTPRESENT)
687  rf = makeFieldPresent(field);
688 
689  T* cf = dynamic_cast<T*>(rf);
690 
691  if (!cf)
692  Throw<std::runtime_error>("Wrong field type");
693 
694  cf->setValue(std::move(value));
695  }
696 
697  // Implementation for setting fields using assignment
698  template <typename T>
699  void
700  setFieldUsingAssignment(SField const& field, T const& value)
701  {
702  STBase* rf = getPField(field, true);
703 
704  if (!rf)
705  throwFieldNotFound(field);
706 
707  if (rf->getSType() == STI_NOTPRESENT)
708  rf = makeFieldPresent(field);
709 
710  T* cf = dynamic_cast<T*>(rf);
711 
712  if (!cf)
713  Throw<std::runtime_error>("Wrong field type");
714 
715  (*cf) = value;
716  }
717 
718  // Implementation for peeking STObjects and STArrays
719  template <typename T>
720  T&
721  peekField(SField const& field)
722  {
723  STBase* rf = getPField(field, true);
724 
725  if (!rf)
726  throwFieldNotFound(field);
727 
728  if (rf->getSType() == STI_NOTPRESENT)
729  rf = makeFieldPresent(field);
730 
731  T* cf = dynamic_cast<T*>(rf);
732 
733  if (!cf)
734  Throw<std::runtime_error>("Wrong field type");
735 
736  return *cf;
737  }
738 };
739 
740 //------------------------------------------------------------------------------
741 
742 template <class T>
743 STObject::Proxy<T>::Proxy(STObject* st, TypedField<T> const* f) : st_(st), f_(f)
744 {
745  if (st_->mType)
746  {
747  // STObject has associated template
748  if (!st_->peekAtPField(*f_))
749  Throw<STObject::FieldErr>(
750  "Template field error '" + this->f_->getName() + "'");
751  style_ = st_->mType->style(*f_);
752  }
753  else
754  {
755  style_ = soeINVALID;
756  }
757 }
758 
759 template <class T>
760 auto
762 {
763  auto const t = find();
764  if (t)
765  return t->value();
766  if (style_ != soeDEFAULT)
767  Throw<STObject::FieldErr>(
768  "Missing field '" + this->f_->getName() + "'");
769  return value_type{};
770 }
771 
772 template <class T>
773 inline T const*
775 {
776  return dynamic_cast<T const*>(st_->peekAtPField(*f_));
777 }
778 
779 template <class T>
780 template <class U>
781 void
783 {
784  if (style_ == soeDEFAULT && u == value_type{})
785  {
786  st_->makeFieldAbsent(*f_);
787  return;
788  }
789  T* t;
790  if (style_ == soeINVALID)
791  t = dynamic_cast<T*>(st_->getPField(*f_, true));
792  else
793  t = dynamic_cast<T*>(st_->makeFieldPresent(*f_));
794  assert(t);
795  *t = std::forward<U>(u);
796 }
797 
798 //------------------------------------------------------------------------------
799 
800 template <class T>
801 template <class U>
804 {
805  this->assign(std::forward<U>(u));
806  return *this;
807 }
808 
809 template <class T>
811 {
812  return this->value();
813 }
814 
815 template <class T>
817  : Proxy<T>(st, f)
818 {
819 }
820 
821 //------------------------------------------------------------------------------
822 
823 template <class T>
825 {
826  return engaged();
827 }
828 
829 template <class T>
830 auto
832 {
833  return this->value();
834 }
835 
836 template <class T>
838  T>::optional_type() const
839 {
840  return optional_value();
841 }
842 
843 template <class T>
846 {
847  return optional_value();
848 }
849 
850 template <class T>
851 auto
853 {
854  disengage();
855  return *this;
856 }
857 
858 template <class T>
859 auto
861 {
862  if (v)
863  this->assign(std::move(*v));
864  else
865  disengage();
866  return *this;
867 }
868 
869 template <class T>
870 auto
872 {
873  if (v)
874  this->assign(*v);
875  else
876  disengage();
877  return *this;
878 }
879 
880 template <class T>
881 template <class U>
884 {
885  this->assign(std::forward<U>(u));
886  return *this;
887 }
888 
889 template <class T>
891  : Proxy<T>(st, f)
892 {
893 }
894 
895 template <class T>
896 bool
898 {
899  return this->style_ == soeDEFAULT || this->find() != nullptr;
900 }
901 
902 template <class T>
903 void
905 {
906  if (this->style_ == soeREQUIRED || this->style_ == soeDEFAULT)
907  Throw<STObject::FieldErr>(
908  "Template field error '" + this->f_->getName() + "'");
909  if (this->style_ == soeINVALID)
910  this->st_->delField(*this->f_);
911  else
912  this->st_->makeFieldAbsent(*this->f_);
913 }
914 
915 template <class T>
916 auto
918 {
919  if (!engaged())
920  return boost::none;
921  return this->value();
922 }
923 
924 //------------------------------------------------------------------------------
925 
926 template <class T>
927 typename T::value_type
929 {
930  auto const b = peekAtPField(f);
931  if (!b)
932  // This is a free object (no constraints)
933  // with no template
934  Throw<STObject::FieldErr>("Missing field '" + f.getName() + "'");
935  auto const u = dynamic_cast<T const*>(b);
936  if (!u)
937  {
938  assert(mType);
939  assert(b->getSType() == STI_NOTPRESENT);
940  if (mType->style(f) == soeOPTIONAL)
941  Throw<STObject::FieldErr>("Missing field '" + f.getName() + "'");
942  assert(mType->style(f) == soeDEFAULT);
943  // Handle the case where value_type is a
944  // const reference, otherwise we return
945  // the address of a temporary.
946  static std::decay_t<typename T::value_type> const dv{};
947  return dv;
948  }
949  return u->value();
950 }
951 
952 template <class T>
953 boost::optional<std::decay_t<typename T::value_type>>
955 {
956  auto const b = peekAtPField(*of.f);
957  if (!b)
958  return boost::none;
959  auto const u = dynamic_cast<T const*>(b);
960  if (!u)
961  {
962  assert(mType);
963  assert(b->getSType() == STI_NOTPRESENT);
964  if (mType->style(*of.f) == soeOPTIONAL)
965  return boost::none;
966  assert(mType->style(*of.f) == soeDEFAULT);
967  return typename T::value_type{};
968  }
969  return u->value();
970 }
971 
972 template <class T>
973 inline auto
975 {
976  return ValueProxy<T>(this, &f);
977 }
978 
979 template <class T>
980 inline auto
982 {
983  return OptionalProxy<T>(this, of.f);
984 }
985 
986 } // namespace ripple
987 
988 #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:897
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::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:605
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:601
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:782
stdexcept
ripple::base_uint< 256 >
ripple::STObject::setFieldH160
void setFieldH160(SField const &field, base_uint< 160, Tag > const &v)
Definition: STObject.h:556
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:721
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:595
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:700
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:774
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:845
ripple::STObject::Proxy::Proxy
Proxy(Proxy const &)=default
ripple::STObject::getFieldByConstRef
V const & getFieldByConstRef(SField const &field, V const &empty) const
Definition: STObject.h:654
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:677
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:831
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:761
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:917
ripple::STI_OBJECT
@ STI_OBJECT
Definition: SField.h:68
ripple::STObject::operator[]
T::value_type operator[](TypedField< T > const &f) const
Return the value of a field.
Definition: STObject.h:928
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:627
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:604
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:904
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