1 #ifndef _GAUDI_PLUGIN_SERVICE_DETAILS_H_
2 #define _GAUDI_PLUGIN_SERVICE_DETAILS_H_
23 #if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
28 # define GAUDIPS_HASCLASSVISIBILITY
31 #if defined(GAUDIPS_HASCLASSVISIBILITY)
32 # define GAUDIPS_IMPORT __attribute__((visibility("default")))
33 # define GAUDIPS_EXPORT __attribute__((visibility("default")))
34 # define GAUDIPS_LOCAL __attribute__((visibility("hidden")))
36 # define GAUDIPS_IMPORT
37 # define GAUDIPS_EXPORT
38 # define GAUDIPS_LOCAL
41 #ifdef GaudiPluginService_EXPORTS
42 #define GAUDIPS_API GAUDIPS_EXPORT
44 #define GAUDIPS_API GAUDIPS_IMPORT
47 namespace Gaudi {
namespace PluginService {
57 #if !defined(__REFLEX__) || defined(ATLAS)
58 template <
typename S,
typename... Args>
59 static typename S::ReturnType
create(Args&&...
args) {
60 return new T(std::forward<Args>(
args)...);
84 union {
void* src; F dst; } p2p;
92 std::string
demangle(
const std::type_info&
id);
101 typedef std::string KeyType;
104 typedef std::map<KeyType, std::string> Properties;
107 FactoryInfo(
const std::string& lib,
void* p=0,
108 const std::string& t=
"",
109 const std::string& rt=
"",
110 const std::string& cn=
"",
111 const Properties& props=Properties()):
112 library(lib), ptr(p),
type(t), rtype(rt), className(cn), properties(props) {}
118 std::string className;
119 Properties properties;
121 FactoryInfo& addProperty(
const KeyType& k,
const std::string& v) {
128 typedef std::map<KeyType, FactoryInfo> FactoryMap;
131 static Registry& instance();
134 template <
typename F,
typename T,
typename I>
135 inline FactoryInfo&
add(
const I&
id,
typename F::FuncType ptr){
136 union {
typename F::FuncType src;
void* dst; } p2p;
138 std::ostringstream o; o << id;
139 return add(o.str(), p2p.dst,
140 typeid(
typename F::FuncType).name(),
141 typeid(
typename F::ReturnType).name(),
146 void*
get(
const std::string& id,
const std::string&
type)
const;
149 const FactoryInfo& getInfo(
const std::string&
id)
const;
153 addProperty(
const std::string&
id,
154 const std::string& k,
155 const std::string& v);
158 std::set<KeyType> loadedFactories()
const;
161 inline const FactoryMap&
factories()
const {
162 if (!m_initialized)
const_cast<Registry*
>(
this)->
initialize();
174 Registry(
const Registry&): m_initialized(
false) {}
178 add(
const std::string&
id,
void *factory,
179 const std::string&
type,
const std::string& rtype,
180 const std::string& className,
181 const Properties& props = Properties());
197 FactoryMap m_factories;
199 #if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
200 mutable std::recursive_mutex m_mutex;
208 enum Level {
Debug=0, Info=1, Warning=2, Error=3 };
211 inline Level level()
const {
return m_level; }
213 inline void info(
const std::string&
msg) { report(Info, msg); }
214 inline void debug(
const std::string&
msg) { report(
Debug, msg); }
215 inline void warning(
const std::string&
msg) { report(Warning, msg); }
216 inline void error(
const std::string&
msg) { report(Error, msg); }
218 virtual void report(
Level lvl,
const std::string&
msg);
236 #define _INTERNAL_FACTORY_REGISTER_CNAME(name, serial) \
237 _register_ ## _ ## serial
239 #define _INTERNAL_DECLARE_FACTORY_WITH_CREATOR(type, typecreator, \
240 id, factory, serial) \
242 class _INTERNAL_FACTORY_REGISTER_CNAME(type, serial) { \
244 typedef factory s_t; \
245 typedef typecreator f_t; \
246 static s_t::FuncType creator() { return &f_t::create<s_t>; } \
247 _INTERNAL_FACTORY_REGISTER_CNAME(type, serial) () { \
248 using ::Gaudi::PluginService::Details::Registry; \
249 Registry::instance().add<s_t, type>(id, creator()); \
251 } _INTERNAL_FACTORY_REGISTER_CNAME(s_ ## type, serial); \
254 #define _INTERNAL_DECLARE_FACTORY(type, id, factory, serial) \
255 _INTERNAL_DECLARE_FACTORY_WITH_CREATOR(type, \
256 ::Gaudi::PluginService::Details::Factory<type>, \
259 #endif //_GAUDI_PLUGIN_SERVICE_DETAILS_H_
GAUDIPS_API Logger & logger()
Return the current logger instance.
GAUDIPS_API void * getCreator(const std::string &id, const std::string &type)
Function used to load a specific factory function.
static S::ReturnType create(Args &&...args)
GAUDIPS_API int Debug()
Backward compatibility with Reflex.
GAUDIPS_API std::string demangle(const std::type_info &id)
Return a canonical name for type_info object (implementation borrowed from GaudiKernel/System).
GAUDIPS_API void SetDebug(int debugLevel)
Backward compatibility with Reflex.
GAUDIPS_API void setLogger(Logger *logger)
Set the logger instance to use.
Helper functions to set/get the application return code.