CatapultServer  v0.5.0.1 (Elephant)
CatapultCacheBuilder.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "CatapultCache.h"
23 #include "SubCachePluginAdapter.h"
24 #include "catapult/exceptions.h"
25 
26 namespace catapult { namespace cache {
27 
30  public:
32  template<typename TStorageTraits, typename TCache>
33  void add(std::unique_ptr<TCache>&& pSubCache) {
34  add(std::make_unique<SubCachePluginAdapter<TCache, TStorageTraits>>(std::move(pSubCache)));
35  }
36 
38  void add(std::unique_ptr<SubCachePlugin>&& pSubCachePlugin) {
39  auto id = pSubCachePlugin->id();
40  m_subCaches.resize(std::max(m_subCaches.size(), id + 1));
41  if (m_subCaches[id])
42  CATAPULT_THROW_INVALID_ARGUMENT_1("sub cache has already been registered with id", id);
43 
44  m_subCaches[id] = std::move(pSubCachePlugin);
45  }
46 
47  public:
50  CATAPULT_LOG(debug) << "creating CatapultCache with " << m_subCaches.size() << " sub caches";
51  return CatapultCache(std::move(m_subCaches));
52  }
53 
54  private:
55  std::vector<std::unique_ptr<SubCachePlugin>> m_subCaches;
56  };
57 }}
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
exceptions.h
Parser.debug
def debug(*args)
Definition: Parser.py:46
catapult::cache::CatapultCacheBuilder
Builder for creating a catapult cache around sub caches.
Definition: CatapultCacheBuilder.h:29
SubCachePluginAdapter.h
catapult::cache::CatapultCache
Central cache holding all sub caches.
Definition: CatapultCache.h:40
CATAPULT_THROW_INVALID_ARGUMENT_1
#define CATAPULT_THROW_INVALID_ARGUMENT_1(MESSAGE, PARAM1)
Macro used to throw a catapult invalid argument with a single parameter.
Definition: exceptions.h:183
CatapultCache.h
catapult::cache::CatapultCacheBuilder::add
void add(std::unique_ptr< SubCachePlugin > &&pSubCachePlugin)
Adds pSubCachePlugin to the builder.
Definition: CatapultCacheBuilder.h:38
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::cache::CatapultCacheBuilder::m_subCaches
std::vector< std::unique_ptr< SubCachePlugin > > m_subCaches
Definition: CatapultCacheBuilder.h:55
catapult::cache::CatapultCacheBuilder::add
void add(std::unique_ptr< TCache > &&pSubCache)
Adds pSubCache to the builder with the specified storage traits.
Definition: CatapultCacheBuilder.h:33
catapult::cache::CatapultCacheBuilder::build
CatapultCache build()
Builds a catapult cache.
Definition: CatapultCacheBuilder.h:49
catapult::cache::SubCachePluginAdapter
A SubCachePlugin implementation that wraps a SynchronizedCache.
Definition: SubCachePluginAdapter.h:32