PluginTypeDeducer.h
Go to the documentation of this file.
1 #ifndef cetlib_PluginTypeDeducer_h
2 #define cetlib_PluginTypeDeducer_h
3 
4 ////////////////////////////////////////////////////////////////////////
5 // PluginTypeDeducer
6 //
7 // An aid to managing multiple plugin types. See
8 // cetlib/BasicPluginFactory.h for background.
9 //
10 // Specialize this class for your own plugin type and make sure it is
11 // seen before being required. A reasonable place would be the in the
12 // header file of the plugin type's base class (assuming there is one),
13 // immediately below the forward declaration of the base class name.
14 //
15 // Define a macro DEFINE_BASIC_PLUGINTYPE_FUNC(base) to produce a
16 // pluginType() function for a plugin library which should be findable
17 // by BasicPluginFactory::pluginType(const std::string & libspec).
18 //
19 // PluginTypeDeducer<> is used rather than a sinple string literal to
20 // allow for the ability for users of the plugin factory to compare the
21 // answer with a known value to verify the type of the plugin found.
22 ////////////////////////////////////////////////////////////////////////
23 
24 #include "cetlib/compiler_macros.h"
25 
26 #include <string>
27 
28 namespace cet {
29  // PluginTypeDeducer.
30  template <typename T>
32 }
33 
34 #define DEFINE_BASIC_PLUGINTYPE_FUNC(base) \
35  EXTERN_C_FUNC_DECLARE_START \
36  std::string pluginType() { return cet::PluginTypeDeducer<base>::value; } \
37  EXTERN_C_FUNC_DECLARE_END
38 
39 namespace cet {
40  template <typename T>
41  struct PluginTypeDeducer {
42  static std::string const value;
43  };
44 
45  template <typename T>
46  std::string const PluginTypeDeducer<T>::value = "Unknown";
47 
48  template <typename T>
49  std::string const& PluginTypeDeducer_v = PluginTypeDeducer<T>::value;
50 }
51 
52 #endif /* cetlib_PluginTypeDeducer_h */
53 
54 // Local Variables:
55 // mode: c++
56 // End:
std::string string
Definition: nybbler.cc:12
static std::string const value
std::string const & PluginTypeDeducer_v