DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PluginTester.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // \author Markus Frank
11 // \date 2016-02-02
12 // \version 1.0
13 //
14 //==========================================================================
15 #ifndef DD4HEP_PLUGINTESTER_H
16 #define DD4HEP_PLUGINTESTER_H 1
17 
18 // Framework includes
19 
20 // C/C++ include files
21 #include <typeinfo>
22 #include <string>
23 #include <map>
24 
25 
27 namespace DD4hep {
28  class PluginTester {
29  public:
31  typedef std::pair<const std::type_info*,std::string> key_type;
32  typedef std::map<key_type, void*> Extensions;
34  typedef void (*destruct_t)(void*);
36  struct Entry {
38  int id;
39  };
40  typedef std::map<const std::type_info*, Entry> ExtensionMap;
41 
46 
48  static void _noDelete(void*) {}
49 
51  template <typename T> static void _delete(void* ptr) {
52  delete (T*) (ptr);
53  }
54 
56  void* addExtension(void* ptr, const std::string& name, const std::type_info& info, destruct_t dtor);
58  void* extension(const std::string& name, const std::type_info& info, bool alert) const;
60  void* removeExtension(const std::string& name, const std::type_info& info, bool destroy);
61 
62  public:
64  PluginTester();
66  PluginTester(const PluginTester& copy) = delete;
68  virtual ~PluginTester();
70  PluginTester& operator=(const PluginTester& copy) = delete;
72  void clear(bool destroy=true);
73  template<typename Q> Q* addExtension(Q* ptr, const std::string& name) {
74  return (Q*)addExtension(ptr, name, typeid(Q), _delete<Q>);
75  }
76  template<typename Q> Q* extension(const std::string& name, bool alert=true) {
77  return (Q*)extension(name, typeid(Q), alert);
78  }
79  template<typename Q> Q* removeExtension(const std::string& name, bool destroy=true) {
80  return (Q*)removeExtension(name, typeid(Q), destroy);
81  }
82  };
83 
84 } /* End namespace DD4hep */
85 #endif // DD4HEP_PLUGINTESTER_H
Defintiion of the extension entry.
Definition: PluginTester.h:36
Q * extension(const std::string &name, bool alert=true)
Definition: PluginTester.h:76
PluginTester & operator=(const PluginTester &copy)=delete
Assignment operator.
static void _noDelete(void *)
Function to be passed as dtor if object should NOT be deleted!
Definition: PluginTester.h:48
virtual ~PluginTester()
Default destructor.
std::pair< const std::type_info *, std::string > key_type
Definition of the extension type.
Definition: PluginTester.h:31
Q * addExtension(Q *ptr, const std::string &name)
Definition: PluginTester.h:73
int id
Definition: PluginTester.h:38
std::map< key_type, void * > Extensions
Definition: PluginTester.h:32
void * removeExtension(const std::string &name, const std::type_info &info, bool destroy)
Remove an existing extension object from the instance.
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Extensions extensions
The extensions object.
Definition: PluginTester.h:43
static void _delete(void *ptr)
Templated destructor function.
Definition: PluginTester.h:51
std::map< const std::type_info *, Entry > ExtensionMap
Definition: PluginTester.h:40
void * extension(const std::string &name, const std::type_info &info, bool alert) const
Access an existing extension object from the detector element.
destruct_t destruct
Definition: PluginTester.h:37
ExtensionMap * extensionMap
Pointer to the extension map.
Definition: PluginTester.h:45
void * addExtension(void *ptr, const std::string &name, const std::type_info &info, destruct_t dtor)
Add an extension object to the detector element.
Q * removeExtension(const std::string &name, bool destroy=true)
Definition: PluginTester.h:79
PluginTester()
Default constructor.
void clear(bool destroy=true)
Clear all extensions.
void(* destruct_t)(void *)
Extensions destructor type.
Definition: PluginTester.h:34