CatapultServer  v0.5.0.1 (Elephant)
BaseSetCommitPolicy.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "DeltaElements.h"
23 #include "catapult/exceptions.h"
24 
25 namespace catapult { namespace deltaset {
26 
28  template<typename TKeyTraits, typename TStorageSet, typename TMemorySet>
29  void UpdateSet(TStorageSet& elements, const DeltaElements<TMemorySet>& deltas) {
30  if (!deltas.Added.empty())
31  elements.insert(deltas.Added.cbegin(), deltas.Added.cend());
32 
33  for (const auto& element : deltas.Copied) {
34  auto iter = elements.find(TKeyTraits::ToKey(element));
35  if (elements.cend() == iter)
36  CATAPULT_THROW_INVALID_ARGUMENT("element not found, cannot update");
37 
38  iter = elements.erase(iter);
39  elements.insert(iter, element);
40  }
41 
42  for (const auto& element : deltas.Removed)
43  elements.erase(TKeyTraits::ToKey(element));
44  }
45 
47  template<typename TSetTraits>
50  static void Update(typename TSetTraits::SetType& elements, const DeltaElements<typename TSetTraits::MemorySetType>& deltas) {
51  UpdateSet<typename TSetTraits::KeyTraits>(elements, deltas);
52  }
53  };
54 }}
catapult::deltaset::BaseSetCommitPolicy::Update
static void Update(typename TSetTraits::SetType &elements, const DeltaElements< typename TSetTraits::MemorySetType > &deltas)
Applies all changes in deltas to elements.
Definition: BaseSetCommitPolicy.h:50
exceptions.h
catapult::deltaset::DeltaElements::Removed
const TSet & Removed
Removed elements.
Definition: DeltaElements.h:47
catapult::deltaset::DeltaElements::Added
const TSet & Added
Added elements.
Definition: DeltaElements.h:44
catapult::deltaset::UpdateSet
void UpdateSet(TStorageSet &elements, const DeltaElements< TMemorySet > &deltas)
Applies all changes in deltas to elements.
Definition: BaseSetCommitPolicy.h:29
catapult::deltaset::DeltaElements
Slim wrapper around changed elements.
Definition: DeltaElements.h:27
catapult::deltaset::BaseSetCommitPolicy
Default policy for committing changes to a base set.
Definition: BaseSetCommitPolicy.h:48
catapult::deltaset::DeltaElements::Copied
const TSet & Copied
Copied elements.
Definition: DeltaElements.h:50
DeltaElements.h
CATAPULT_THROW_INVALID_ARGUMENT
#define CATAPULT_THROW_INVALID_ARGUMENT(MESSAGE)
Macro used to throw a catapult invalid argument.
Definition: exceptions.h:179
catapult
Definition: AddressExtractionExtension.cpp:28