CatapultServer  v0.5.0.1 (Elephant)
PluginRegistry.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "catapult/exceptions.h"
23 #include <memory>
24 #include <vector>
25 
26 namespace catapult { namespace model {
27 
29  template<typename TPlugin, typename TPluginKey>
31  public:
33  size_t size() const {
34  return m_plugins.size();
35  }
36 
38  const TPlugin* findPlugin(TPluginKey type) const {
39  auto iter = std::find_if(m_plugins.cbegin(), m_plugins.cend(), [type](const auto& pPlugin) {
40  return pPlugin->type() == type;
41  });
42 
43  return m_plugins.cend() == iter ? nullptr : iter->get();
44  }
45 
46  public:
48  void registerPlugin(std::unique_ptr<const TPlugin>&& pPlugin) {
49  if (findPlugin(pPlugin->type()))
50  CATAPULT_THROW_INVALID_ARGUMENT_1("plugin has already been registered with type", pPlugin->type());
51 
52  m_plugins.push_back(std::move(pPlugin));
53  }
54 
55  private:
56  std::vector<std::unique_ptr<const TPlugin>> m_plugins;
57  };
58 }}
exceptions.h
catapult::model::PluginRegistry::findPlugin
const TPlugin * findPlugin(TPluginKey type) const
Finds the plugin corresponding to type or nullptr if none is registered.
Definition: PluginRegistry.h:38
catapult::model::PluginRegistry::size
size_t size() const
Gets the number of registered plugins.
Definition: PluginRegistry.h:33
catapult::model::PluginRegistry
A registry of plugins.
Definition: PluginRegistry.h:30
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
catapult::model::PluginRegistry::m_plugins
std::vector< std::unique_ptr< const TPlugin > > m_plugins
Definition: PluginRegistry.h:56
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::model::PluginRegistry::registerPlugin
void registerPlugin(std::unique_ptr< const TPlugin > &&pPlugin)
Registers pPlugin with the registry.
Definition: PluginRegistry.h:48