PluginManager.h
Go to the documentation of this file.
1 #ifndef WIRECELL_PLUGINMANAGER
2 #define WIRECELL_PLUGINMANAGER
3 
4 #include "WireCellUtil/Logging.h"
5 
6 #include <map>
7 #include <string>
8 
9 namespace WireCell {
10 
11  class Plugin {
12  public:
13  Plugin(void* lib);
14  ~Plugin();
15 
16  void* raw(const std::string& symbol_name);
17 
18  bool contains(const std::string& symbol_name);
19 
20  template<typename T>
21  bool symbol(const std::string& symbol_name, T& ret) {
22  void* thing = raw(symbol_name);
23  if (!thing) { return false; }
24  ret = reinterpret_cast<T>(thing);
25  return true;
26  }
27  private:
28  void* m_lib;
29  };
30 
31  /** This is meant to be used from a WireCell::Singleton. */
34  PluginManager();
35  ~PluginManager();
36  public:
37  static PluginManager& instance();
38 
39  /// Add a plugin. If libname is not given, try to derive it.
40  Plugin* add(const std::string& plugin_name, const std::string& libname = "");
41 
42  Plugin* get(const std::string& plugin_name);
43 
44  Plugin* find(const std::string& symbol_name);
45  private:
46  std::map<std::string, Plugin*> m_plugins;
47  };
48 
49 }
50 
51 #endif
52 
bool contains(const std::string &symbol_name)
std::string string
Definition: nybbler.cc:12
Coord add(Coord c1, Coord c2)
Definition: restypedef.cpp:23
const std::string instance
Configuration find(Configuration &lst, const std::string &dotpath, const T &val)
Return dictionary in given list if it value at dotpath matches.
std::map< std::string, Plugin * > m_plugins
Definition: PluginManager.h:46
std::shared_ptr< spdlog::logger > logptr_t
Definition: Logging.h:24
Definition: Main.h:22
void * raw(const std::string &symbol_name)
bool symbol(const std::string &symbol_name, T &ret)
Definition: PluginManager.h:21