CatapultServer  v0.5.0.1 (Elephant)
BasicTransactionsCache.h
Go to the documentation of this file.
1 
21 #pragma once
24 #include <memory>
25 
26 namespace catapult { namespace cache {
27 
29  template<typename TTransactionInfo>
31  public:
32  virtual ~BasicTransactionsCacheModifier() noexcept(false) {}
33 
34  public:
36  virtual size_t size() const = 0;
37 
40  virtual bool add(const TTransactionInfo& transactionInfo) = 0;
41 
43  virtual TTransactionInfo remove(const Hash256& hash) = 0;
44  };
45 
49  template<typename TTransactionInfo, typename TTransactionsCacheModifier>
51  public:
53  explicit BasicTransactionsCacheModifierProxy(std::unique_ptr<TTransactionsCacheModifier>&& pModifier)
54  : m_pModifier(std::move(pModifier))
55  {}
56 
57  public:
59  size_t size() const {
60  return m_pModifier->size();
61  }
62 
65  bool add(const TTransactionInfo& transactionInfo) {
66  return m_pModifier->add(transactionInfo);
67  }
68 
70  TTransactionInfo remove(const Hash256& hash) {
71  return m_pModifier->remove(hash);
72  }
73 
74  protected:
76  TTransactionsCacheModifier& modifier() {
77  return *m_pModifier;
78  }
79 
81  const TTransactionsCacheModifier& modifier() const {
82  return *m_pModifier;
83  }
84 
85  private:
86  std::unique_ptr<TTransactionsCacheModifier> m_pModifier;
87  };
88 
90  template<typename TTransactionsCacheModifierProxy>
92  public:
93  virtual ~BasicTransactionsCache() = default;
94 
95  public:
97  virtual TTransactionsCacheModifierProxy modifier() = 0;
98  };
99 }}
catapult::cache::BasicTransactionsCacheModifierProxy::BasicTransactionsCacheModifierProxy
BasicTransactionsCacheModifierProxy(std::unique_ptr< TTransactionsCacheModifier > &&pModifier)
Creates a transactions cache modifier around pModifier.
Definition: BasicTransactionsCache.h:53
catapult::cache::BasicTransactionsCache::modifier
virtual TTransactionsCacheModifierProxy modifier()=0
Gets a write only view of the cache.
catapult::cache::BasicTransactionsCacheModifierProxy::size
size_t size() const
Returns the number of transactions in the cache.
Definition: BasicTransactionsCache.h:59
catapult::cache::BasicTransactionsCacheModifier::size
virtual size_t size() const =0
Returns the number of transactions in the cache.
catapult::cache::BasicTransactionsCacheModifierProxy::add
bool add(const TTransactionInfo &transactionInfo)
Definition: BasicTransactionsCache.h:65
catapult::cache::BasicTransactionsCacheModifierProxy::remove
TTransactionInfo remove(const Hash256 &hash)
Removes the transaction identified by hash from the cache.
Definition: BasicTransactionsCache.h:70
catapult::cache::BasicTransactionsCacheModifier::remove
virtual TTransactionInfo remove(const Hash256 &hash)=0
Removes the transaction identified by hash from the cache.
catapult::cache::BasicTransactionsCacheModifierProxy::modifier
TTransactionsCacheModifier & modifier()
Gets the modifier.
Definition: BasicTransactionsCache.h:76
catapult::cache::BasicTransactionsCacheModifierProxy
Definition: BasicTransactionsCache.h:50
EntityInfo.h
catapult::utils::MoveOnly
A class that can be moved but not copied.
Definition: NonCopyable.h:43
catapult::cache::BasicTransactionsCacheModifier
An interface for modifying a transactions cache.
Definition: BasicTransactionsCache.h:30
catapult::cache::BasicTransactionsCacheModifier::~BasicTransactionsCacheModifier
virtual ~BasicTransactionsCacheModifier() noexcept(false)
Definition: BasicTransactionsCache.h:32
catapult::cache::BasicTransactionsCache::~BasicTransactionsCache
virtual ~BasicTransactionsCache()=default
ContainerTypes.h
catapult::cache::BasicTransactionsCacheModifierProxy::m_pModifier
std::unique_ptr< TTransactionsCacheModifier > m_pModifier
Definition: BasicTransactionsCache.h:86
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::cache::BasicTransactionsCacheModifierProxy::modifier
const TTransactionsCacheModifier & modifier() const
Gets the (const) modifier.
Definition: BasicTransactionsCache.h:81
catapult::cache::BasicTransactionsCache
An interface for caching transactions.
Definition: BasicTransactionsCache.h:91
catapult::cache::BasicTransactionsCacheModifier::add
virtual bool add(const TTransactionInfo &transactionInfo)=0
catapult::utils::ByteArray
Base class for wrappers of byte array types, to provide some type-safety.
Definition: ByteArray.h:29
catapult::utils::NonCopyable
A class that can neither be copied nor moved.
Definition: NonCopyable.h:26