CatapultServer  v0.5.0.1 (Elephant)
BaseSetFindIterator.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include <utility>
23 
24 namespace catapult { namespace deltaset {
25 
26  namespace detail {
29  template<typename TFindTraits, typename TSetTraits, typename TStorageIterator, typename TFindResult>
31  public:
34  {}
35 
37  explicit BaseSetSingleIteratorWrapper(TStorageIterator&& storageIter)
38  : m_isSet(true)
39  , m_storageIter(std::move(storageIter))
40  {}
41 
42  public:
44  TFindResult get() const {
45  return m_isSet ? TFindTraits::ToResult(TSetTraits::ToValue(*m_storageIter)) : nullptr;
46  }
47 
48  private:
49  bool m_isSet;
50  TStorageIterator m_storageIter;
51  };
52 
55  template<typename TFindTraits, typename TSetTraits, typename TStorageIterator, typename TMemoryIterator, typename TFindResult>
57  public:
60  {}
61 
63  explicit BaseSetDualIteratorWrapper(TStorageIterator&& storageIter)
65  , m_storageIter(std::move(storageIter))
66  {}
67 
69  explicit BaseSetDualIteratorWrapper(TMemoryIterator&& memoryIter)
71  , m_memoryIter(std::move(memoryIter))
72  {}
73 
74  public:
76  TFindResult get() const {
77  switch (m_iteratorType) {
79  return TFindTraits::ToResult(TSetTraits::ToValue(*m_storageIter));
81  return TFindTraits::ToResult(TSetTraits::ToValue(*m_memoryIter));
82  default:
83  return nullptr;
84  }
85  }
86 
87  private:
88  enum class IteratorType { Unset, Storage, Memory };
89 
90  private:
92  TStorageIterator m_storageIter;
93  TMemoryIterator m_memoryIter;
94  };
95 
97  template<typename TFindTraits, typename TSetTraits, typename TStorageIterator, typename TMemoryIterator, typename TFindResult>
98  using BaseSetConditionalIteratorWrapper = std::conditional_t<
99  std::is_same_v<TStorageIterator, TMemoryIterator>,
102  >;
103  }
104 
106  template<typename TFindTraits, typename TSetTraits>
108  TFindTraits,
109  TSetTraits,
110  typename TSetTraits::SetType::const_iterator,
111  typename TFindTraits::ConstResultType
112  >;
113 
115  template<typename TFindTraits, typename TSetTraits>
117  TFindTraits,
118  TSetTraits,
119  typename TSetTraits::MemorySetType::iterator,
120  typename TFindTraits::ResultType
121  >;
122 
124  template<typename TFindTraits, typename TSetTraits>
126  TFindTraits,
127  TSetTraits,
128  typename TSetTraits::SetType::const_iterator,
129  typename TSetTraits::MemorySetType::const_iterator,
130  typename TFindTraits::ConstResultType
131  >;
132 }}
catapult::deltaset::detail::BaseSetDualIteratorWrapper::IteratorType
IteratorType
Definition: BaseSetFindIterator.h:88
catapult::deltaset::detail::BaseSetDualIteratorWrapper::BaseSetDualIteratorWrapper
BaseSetDualIteratorWrapper(TStorageIterator &&storageIter)
Creates an iterator around a storage iterator (storageIter).
Definition: BaseSetFindIterator.h:63
catapult::deltaset::detail::BaseSetSingleIteratorWrapper::get
TFindResult get() const
Gets the underlying value.
Definition: BaseSetFindIterator.h:44
catapult::deltaset::detail::BaseSetDualIteratorWrapper
Definition: BaseSetFindIterator.h:56
catapult::deltaset::ConditionalContainerMode::Storage
Delegate to storage.
catapult::deltaset::detail::BaseSetDualIteratorWrapper::IteratorType::Unset
catapult::deltaset::detail::BaseSetSingleIteratorWrapper::BaseSetSingleIteratorWrapper
BaseSetSingleIteratorWrapper()
Creates an unset iterator.
Definition: BaseSetFindIterator.h:33
catapult::deltaset::detail::BaseSetDualIteratorWrapper::m_storageIter
TStorageIterator m_storageIter
Definition: BaseSetFindIterator.h:92
catapult::deltaset::detail::BaseSetDualIteratorWrapper::IteratorType::Memory
catapult::deltaset::detail::BaseSetSingleIteratorWrapper::m_storageIter
TStorageIterator m_storageIter
Definition: BaseSetFindIterator.h:50
catapult::deltaset::detail::BaseSetSingleIteratorWrapper::m_isSet
bool m_isSet
Definition: BaseSetFindIterator.h:49
catapult::deltaset::detail::BaseSetSingleIteratorWrapper
Definition: BaseSetFindIterator.h:30
catapult::deltaset::BaseSetDeltaFindConstIterator
detail::BaseSetConditionalIteratorWrapper< TFindTraits, TSetTraits, typename TSetTraits::SetType::const_iterator, typename TSetTraits::MemorySetType::const_iterator, typename TFindTraits::ConstResultType > BaseSetDeltaFindConstIterator
Iterator that returns a find (const) result from a base set delta.
Definition: BaseSetFindIterator.h:131
catapult::deltaset::detail::BaseSetConditionalIteratorWrapper
std::conditional_t< std::is_same_v< TStorageIterator, TMemoryIterator >, BaseSetSingleIteratorWrapper< TFindTraits, TSetTraits, TStorageIterator, TFindResult >, BaseSetDualIteratorWrapper< TFindTraits, TSetTraits, TStorageIterator, TMemoryIterator, TFindResult > > BaseSetConditionalIteratorWrapper
Iterator that represents a find result from a base set that supports either one or two types of conta...
Definition: BaseSetFindIterator.h:102
catapult::deltaset::detail::BaseSetDualIteratorWrapper::IteratorType::Storage
catapult::deltaset::detail::BaseSetDualIteratorWrapper::m_iteratorType
IteratorType m_iteratorType
Definition: BaseSetFindIterator.h:91
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::deltaset::detail::BaseSetDualIteratorWrapper::BaseSetDualIteratorWrapper
BaseSetDualIteratorWrapper()
Creates an unset iterator.
Definition: BaseSetFindIterator.h:59
catapult::deltaset::detail::BaseSetSingleIteratorWrapper::BaseSetSingleIteratorWrapper
BaseSetSingleIteratorWrapper(TStorageIterator &&storageIter)
Creates an iterator around a storage iterator (storageIter).
Definition: BaseSetFindIterator.h:37
catapult::deltaset::ConditionalContainerMode::Memory
Delegate to memory.
catapult::deltaset::detail::BaseSetDualIteratorWrapper::m_memoryIter
TMemoryIterator m_memoryIter
Definition: BaseSetFindIterator.h:93
catapult::deltaset::detail::BaseSetDualIteratorWrapper::get
TFindResult get() const
Gets the underlying value.
Definition: BaseSetFindIterator.h:76
catapult::deltaset::detail::BaseSetDualIteratorWrapper::BaseSetDualIteratorWrapper
BaseSetDualIteratorWrapper(TMemoryIterator &&memoryIter)
Creates an iterator around a memory iterator (memoryIter).
Definition: BaseSetFindIterator.h:69