Bayeux  3.4.1
Core Foundation library for SuperNEMO
manager-inl.h
Go to the documentation of this file.
1 // -*- mode: c++ ; -*-
2 /* manager-inl.h
3  *
4  */
5 
6 #ifndef GEOMTOOLS_DETAIL_MANAGER_INL_H_
7 #define GEOMTOOLS_DETAIL_MANAGER_INL_H_ 1
8 
9 #include <datatools/exception.h>
10 
11 namespace geomtools {
12 
13  template<class T>
14  bool manager::is_plugin_a (const std::string & a_plugin_name) const
15  {
16  plugins_dict_type::const_iterator found = _plugins_.find(a_plugin_name);
17  DT_THROW_IF (found == _plugins_.end (),
18  std::logic_error,
19  "No plugin named '" << a_plugin_name << "' !");
20  const plugin_entry& entry = found->second;
21  if (! entry.is_initialized ()) {
23  "Triggering initialization of the plugin named '"
24  << a_plugin_name
25  << "'...");
26  manager * mutable_this = const_cast<manager *>(this);
27  plugin_entry& mutable_entry = const_cast<plugin_entry &>(entry);
28  mutable_this->_initialize_plugin(mutable_entry);
29  }
30  const std::type_info& ti = typeid(T);
31  const base_plugin& cur = found->second.get();
32  const std::type_info& tf = typeid(cur);
33  return (ti == tf);
34  }
35 
36  template<class T>
37  T& manager::grab_plugin (const std::string & a_plugin_name)
38  {
39  plugins_dict_type::iterator found = _plugins_.find(a_plugin_name);
40  DT_THROW_IF (found == _plugins_.end (),
41  std::logic_error,
42  "No plugin named '" << a_plugin_name << "' !");
43  plugin_entry& entry = found->second;
44  if (! entry.is_initialized ()) {
45  this->_initialize_plugin(entry);
46  }
47  const std::type_info& ti = typeid(T);
48  const base_plugin& cur = found->second.get();
49  const std::type_info& tf = typeid(cur);
50  DT_THROW_IF (ti != tf,
51  std::logic_error,
52  "Requested plugin type '"
53  << ti.name() << "' does not match the type '"
54  << tf.name()
55  << "' of the plugin named '" << a_plugin_name
56  << "' !");
57  return dynamic_cast<T&>(found->second.grab());
58  }
59 
60  template<class T>
61  const T& manager::get_plugin (const std::string & a_plugin_name) const
62  {
63  manager* sm = const_cast<manager*>(this);
64  return const_cast<T&>(sm->grab_plugin<T>(a_plugin_name));
65  }
66 
67  template <class PluginClass>
68  void manager::register_plugin_type(const std::string& id) {
69  _plugins_factory_register_.registration(id, boost::factory<PluginClass*>());
70  }
71 
72 
73 } // end of namespace geomtools
74 
75 #endif // GEOMTOOLS_DETAIL_MANAGER_INL_H_
datatools::logger::priority _logging
Logging priority threshold.
Definition: manager.h:433
Internal record plugin handling.
Definition: manager.h:149
T & grab_plugin(const std::string &a_plugin_name)
Definition: manager-inl.h:37
const T & get_plugin(const std::string &a_plugin_name) const
Definition: manager-inl.h:61
The geometry manager's plugin base class.
Definition: manager.h:81
void _initialize_plugin(plugin_entry &entry)
Utility macros for exception handling.
void register_plugin_type(const std::string &plugin_id)
Register a plugin type.
Definition: manager-inl.h:68
#define DT_LOG_NOTICE(Priority, Message)
Definition: logger_macros.h:118
bool is_plugin_a(const std::string &a_plugin_name) const
Definition: manager-inl.h:14
#define DT_THROW_IF(Condition, ExceptionType, Message)
Definition: exception.h:76
Geometry manager for virtual geometry modelling. Main geometry manager for the modelisation of variou...
Definition: manager.h:70
Top-level namespace of the Bayeux/geomtools module library.
Definition: electromagnetic_field_manager.h:39