CatapultServer  v0.5.0.1 (Elephant)
DeltaElementsMixin.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "BaseSetDefaultTraits.h"
24 #include <unordered_set>
25 
26 namespace catapult { namespace deltaset {
27 
29  template<typename TSetDelta>
31  private:
32  // region value accessors
33 
34  template<typename TSet, bool IsMap = utils::traits::is_map_v<TSet>>
35  struct ValueAccessorT {
36  using ValueType = typename TSet::value_type;
37 
38  static const ValueType* GetPointer(const typename TSet::value_type& value) {
39  return &value;
40  }
41  };
42 
43  template<typename TSet>
44  struct ValueAccessorT<TSet, true> { // map specialization
45  using ValueType = typename TSet::value_type::second_type;
46 
47  static const ValueType* GetPointer(const typename TSet::value_type& pair) {
48  return &pair.second;
49  }
50  };
51 
52  // endregion
53 
54  private:
55  // use MemorySetType for detection because it is always stl (memory) container
58  using PointerContainer = std::unordered_set<const ValueType*>;
59 
60  public:
62  explicit DeltaElementsMixin(const TSetDelta& setDelta) : m_setDelta(setDelta)
63  {}
64 
65  public:
68  return CollectAllPointers(m_setDelta.deltas().Added);
69  }
70 
73  return CollectAllPointers(m_setDelta.deltas().Copied);
74  }
75 
78  return CollectAllPointers(m_setDelta.deltas().Removed);
79  }
80 
81  private:
82  template<typename TSource>
83  static PointerContainer CollectAllPointers(const TSource& source) {
84  PointerContainer dest;
85  for (const auto& value : source)
86  dest.insert(ValueAccessor::GetPointer(value));
87 
88  return dest;
89  }
90 
91  private:
92  const TSetDelta& m_setDelta;
93  };
94 }}
catapult::deltaset::DeltaElementsMixin::modifiedElements
PointerContainer modifiedElements() const
Gets pointers to all modified elements.
Definition: DeltaElementsMixin.h:72
catapult::deltaset::DeltaElementsMixin
Mixin that wraps BaseSetDelta and provides a facade on top of BaseSetDelta::deltas().
Definition: DeltaElementsMixin.h:30
catapult::deltaset::DeltaElementsMixin::removedElements
PointerContainer removedElements() const
Gets pointers to all removed elements.
Definition: DeltaElementsMixin.h:77
catapult::deltaset::DeltaElementsMixin::ValueAccessorT< TSet, true >::ValueType
typename TSet::value_type::second_type ValueType
Definition: DeltaElementsMixin.h:45
catapult::deltaset::DeltaElementsMixin::ValueAccessorT::GetPointer
static const ValueType * GetPointer(const typename TSet::value_type &value)
Definition: DeltaElementsMixin.h:38
catapult::deltaset::DeltaElementsMixin::ValueAccessorT
Definition: DeltaElementsMixin.h:35
catapult::deltaset::DeltaElementsMixin::m_setDelta
const TSetDelta & m_setDelta
Definition: DeltaElementsMixin.h:92
catapult::deltaset::DeltaElementsMixin::DeltaElementsMixin
DeltaElementsMixin(const TSetDelta &setDelta)
Creates a mixin around setDelta.
Definition: DeltaElementsMixin.h:62
catapult::deltaset::DeltaElementsMixin::ValueType
typename ValueAccessor::ValueType ValueType
Definition: DeltaElementsMixin.h:57
catapult::deltaset::DeltaElementsMixin::PointerContainer
std::unordered_set< const ValueType * > PointerContainer
Definition: DeltaElementsMixin.h:58
catapult::deltaset::DeltaElementsMixin::ValueAccessorT::ValueType
typename TSet::value_type ValueType
Definition: DeltaElementsMixin.h:36
catapult::deltaset::DeltaElementsMixin::addedElements
PointerContainer addedElements() const
Gets pointers to all added elements.
Definition: DeltaElementsMixin.h:67
BaseSetDefaultTraits.h
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::deltaset::DeltaElementsMixin::ValueAccessorT< TSet, true >::GetPointer
static const ValueType * GetPointer(const typename TSet::value_type &pair)
Definition: DeltaElementsMixin.h:47
catapult::deltaset::DeltaElementsMixin::CollectAllPointers
static PointerContainer CollectAllPointers(const TSource &source)
Definition: DeltaElementsMixin.h:83
StlTraits.h