DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
PluginTester.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
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 
30  class PluginTester {
31  public:
33  typedef std::pair<const std::type_info*,std::string> key_type;
35  typedef std::map<key_type, void*> Extensions;
37  typedef void (*destruct_t)(void*);
38 
40  struct Entry {
41  destruct_t destruct = nullptr;
42  int id = -1;
43  };
44  typedef std::map<const std::type_info*, Entry> ExtensionMap;
45 
50 
52  static void _noDelete(void*) {}
53 
55  template <typename T> static void _delete(void* ptr) {
56  delete (T*) (ptr);
57  }
58 
60  void* addExtension(void* ptr, const std::string& name, const std::type_info& info, destruct_t dtor);
62  void* extension(const std::string& name, const std::type_info& info, bool alert) const;
64  void* removeExtension(const std::string& name, const std::type_info& info, bool destroy);
65 
66  public:
68  PluginTester();
70  PluginTester(const PluginTester& copy) = delete;
72  virtual ~PluginTester();
76  void clear(bool destroy=true);
77  template<typename Q> Q* addExtension(Q* ptr, const std::string& name) {
78  return (Q*)addExtension(ptr, name, typeid(Q), _delete<Q>);
79  }
80  template<typename Q> Q* extension(const std::string& name, bool alert=true) {
81  return (Q*)extension(name, typeid(Q), alert);
82  }
83  template<typename Q> Q* removeExtension(const std::string& name, bool destroy=true) {
84  return (Q*)removeExtension(name, typeid(Q), destroy);
85  }
86  };
87 
88 } /* End namespace dd4hep */
89 #endif // DD4HEP_PLUGINTESTER_H
dd4hep::PluginTester::clear
void clear(bool destroy=true)
Clear all extensions.
Definition: PluginTester.cpp:48
dd4hep::PluginTester::key_type
std::pair< const std::type_info *, std::string > key_type
Definition of the extension type.
Definition: PluginTester.h:33
dd4hep::PluginTester::PluginTester
PluginTester()
Default constructor.
Definition: PluginTester.cpp:36
dd4hep::PluginTester::~PluginTester
virtual ~PluginTester()
Default destructor.
Definition: PluginTester.cpp:42
dd4hep::info
std::size_t info(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:65
dd4hep::PluginTester::removeExtension
void * removeExtension(const std::string &name, const std::type_info &info, bool destroy)
Remove an existing extension object from the instance.
Definition: PluginTester.cpp:82
dd4hep::PluginTester::extensionMap
ExtensionMap * extensionMap
Pointer to the extension map.
Definition: PluginTester.h:49
dd4hep::PluginTester::extension
Q * extension(const std::string &name, bool alert=true)
Definition: PluginTester.h:80
dd4hep::PluginTester::PluginTester
PluginTester(const PluginTester &copy)=delete
Copy constructor.
dd4hep::PluginTester::ExtensionMap
std::map< const std::type_info *, Entry > ExtensionMap
Definition: PluginTester.h:44
dd4hep::PluginTester::Extensions
std::map< key_type, void * > Extensions
Mapped extension type.
Definition: PluginTester.h:35
dd4hep::PluginTester::extension
void * extension(const std::string &name, const std::type_info &info, bool alert) const
Access an existing extension object from the detector element.
Definition: PluginTester.cpp:103
dd4hep::PluginTester::addExtension
void * addExtension(void *ptr, const std::string &name, const std::type_info &info, destruct_t dtor)
Add an extension object to the detector element.
Definition: PluginTester.cpp:64
dd4hep::PluginTester::destruct_t
void(* destruct_t)(void *)
Extensions destructor type.
Definition: PluginTester.h:37
dd4hep::PluginTester::removeExtension
Q * removeExtension(const std::string &name, bool destroy=true)
Definition: PluginTester.h:83
dd4hep::PluginTester::_delete
static void _delete(void *ptr)
Templated destructor function.
Definition: PluginTester.h:55
dd4hep::PluginTester::_noDelete
static void _noDelete(void *)
Function to be passed as dtor if object should NOT be deleted!
Definition: PluginTester.h:52
dd4hep::PluginTester
Helper class to ease testing of plugins: Effectively a container of object extensions.
Definition: PluginTester.h:30
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::PluginTester::Entry
Defintiion of the extension entry.
Definition: PluginTester.h:40
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::PluginTester::addExtension
Q * addExtension(Q *ptr, const std::string &name)
Definition: PluginTester.h:77
dd4hep::PluginTester::Entry::destruct
destruct_t destruct
Definition: PluginTester.h:41
dd4hep::PluginTester::operator=
PluginTester & operator=(const PluginTester &copy)=delete
Assignment operator.
dd4hep::PluginTester::extensions
Extensions extensions
The extensions object.
Definition: PluginTester.h:47