CatapultServer  v0.5.0.1 (Elephant)
ReadThroughMemoryDataSource.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "MemoryDataSource.h"
23 
24 namespace catapult { namespace tree {
25 
27  template<typename TBackingDataSource>
29  public:
32  const TBackingDataSource& backingDataSource,
34  : m_backingDataSource(backingDataSource)
35  , m_memoryDataSource(verbosity)
36  {}
37 
38  public:
40  size_t size() const {
41  return m_memoryDataSource.size();
42  }
43 
44  public:
46  std::unique_ptr<const TreeNode> get(const Hash256& hash) const {
47  auto pNode = m_memoryDataSource.get(hash);
48  return pNode ? std::move(pNode) : m_backingDataSource.get(hash);
49  }
50 
54  }
55 
56  public:
58  void set(const LeafTreeNode& node) {
59  m_memoryDataSource.set(node);
60  }
61 
63  void set(const BranchTreeNode& node) {
64  m_memoryDataSource.set(node);
65  }
66 
68  void clear() {
70  }
71 
72  private:
73  const TBackingDataSource& m_backingDataSource;
75  };
76 }}
catapult::tree::ReadThroughMemoryDataSource::set
void set(const LeafTreeNode &node)
Saves a leaf tree node.
Definition: ReadThroughMemoryDataSource.h:58
catapult::tree::ReadThroughMemoryDataSource::m_memoryDataSource
MemoryDataSource m_memoryDataSource
Definition: ReadThroughMemoryDataSource.h:74
catapult::tree::ReadThroughMemoryDataSource
A patricia tree memory data source that reads through but does not write through.
Definition: ReadThroughMemoryDataSource.h:28
catapult::tree::MemoryDataSource::clear
void clear()
Clears all nodes.
Definition: MemoryDataSource.cpp:64
catapult::tree::MemoryDataSource::set
void set(const LeafTreeNode &node)
Saves a leaf tree node.
Definition: MemoryDataSource.cpp:44
catapult::tree::ReadThroughMemoryDataSource::forEach
void forEach(const consumer< const TreeNode & > &consumer) const
Gets all nodes in memory and passes them to consumer.
Definition: ReadThroughMemoryDataSource.h:52
catapult::tree::ReadThroughMemoryDataSource::set
void set(const BranchTreeNode &node)
Saves a branch tree node.
Definition: ReadThroughMemoryDataSource.h:63
catapult::tree::MemoryDataSource::get
std::unique_ptr< const TreeNode > get(const Hash256 &hash) const
Gets the tree node associated with hash.
Definition: MemoryDataSource.cpp:34
catapult::tree::ReadThroughMemoryDataSource::size
size_t size() const
Gets the number of saved nodes in the in memory cache.
Definition: ReadThroughMemoryDataSource.h:40
catapult::tree::ReadThroughMemoryDataSource::get
std::unique_ptr< const TreeNode > get(const Hash256 &hash) const
Gets the tree node associated with hash.
Definition: ReadThroughMemoryDataSource.h:46
catapult::tree::MemoryDataSource::forEach
void forEach(const consumer< const TreeNode & > &consumer) const
Gets all nodes and passes them to consumer.
Definition: MemoryDataSource.cpp:39
catapult::tree::ReadThroughMemoryDataSource::m_backingDataSource
const TBackingDataSource & m_backingDataSource
Definition: ReadThroughMemoryDataSource.h:73
catapult::tree::LeafTreeNode
Represents a leaf tree node.
Definition: TreeNode.h:34
catapult::tree::MemoryDataSource::size
size_t size() const
Gets the number of saved nodes.
Definition: MemoryDataSource.cpp:30
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::tree::DataSourceVerbosity
DataSourceVerbosity
Data source verbosity.
Definition: DataSourceVerbosity.h:26
catapult::utils::ByteArray< Hash256_Size, Hash256_tag >
catapult::tree::ReadThroughMemoryDataSource::clear
void clear()
Clears all cached memory nodes.
Definition: ReadThroughMemoryDataSource.h:68
catapult::tree::MemoryDataSource
A patricia tree memory data source.
Definition: MemoryDataSource.h:31
catapult::consumer
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
catapult::tree::BranchTreeNode
Represents a branch tree node.
Definition: TreeNode.h:60
MemoryDataSource.h
catapult::tree::ReadThroughMemoryDataSource::ReadThroughMemoryDataSource
ReadThroughMemoryDataSource(const TBackingDataSource &backingDataSource, DataSourceVerbosity verbosity=DataSourceVerbosity::Off)
Creates a data source around backingDataSource with specified verbosity.
Definition: ReadThroughMemoryDataSource.h:31
catapult::tree::DataSourceVerbosity::Off
No messages.