CatapultServer  v0.5.0.1 (Elephant)
ExternalCacheStorageBuilder.h
Go to the documentation of this file.
1 
21 #pragma once
23 #include "catapult/exceptions.h"
24 
25 namespace catapult { namespace mongo {
26 
29  public:
31  template<typename TStorage>
32  void add(std::unique_ptr<TStorage>&& pStorage) {
33  auto id = pStorage->id();
34  m_storages.resize(std::max(m_storages.size(), id + 1));
35  if (m_storages[id])
36  CATAPULT_THROW_INVALID_ARGUMENT_1("storage has already been registered with id", id);
37 
38  m_storages[id] = std::move(pStorage);
39  }
40 
42  std::unique_ptr<ExternalCacheStorage> build() {
43  std::vector<std::unique_ptr<ExternalCacheStorage>> storages;
44  for (auto& pStorage : m_storages) {
45  if (!!pStorage)
46  storages.push_back(std::move(pStorage));
47  }
48 
49  CATAPULT_LOG(debug) << "creating ExternalCacheStorage with " << storages.size() << " storages";
50  return std::make_unique<AggregateExternalCacheStorage>(std::move(storages));
51  }
52 
53  private:
54  std::vector<std::unique_ptr<ExternalCacheStorage>> m_storages;
55  };
56 }}
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::mongo::ExternalCacheStorageBuilder::build
std::unique_ptr< ExternalCacheStorage > build()
Builds an aggregate external cache storage.
Definition: ExternalCacheStorageBuilder.h:42
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
AggregateExternalCacheStorage.h
catapult::mongo::ExternalCacheStorageBuilder::m_storages
std::vector< std::unique_ptr< ExternalCacheStorage > > m_storages
Definition: ExternalCacheStorageBuilder.h:54
catapult::mongo::ExternalCacheStorageBuilder
Builder for creating an aggregate external cache storage around external cache storages.
Definition: ExternalCacheStorageBuilder.h:28
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::mongo::ExternalCacheStorageBuilder::add
void add(std::unique_ptr< TStorage > &&pStorage)
Adds pStorage to the builder.
Definition: ExternalCacheStorageBuilder.h:32