Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:58:02

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 //  \author   Markus Frank
0011 //  \date     2016-02-02
0012 //  \version  1.0
0013 //
0014 //==========================================================================
0015 #ifndef DD4HEP_PLUGINTESTER_H 
0016 #define DD4HEP_PLUGINTESTER_H 1
0017 
0018 // Framework includes
0019 
0020 // C/C++ include files
0021 #include <typeinfo>
0022 #include <string>
0023 #include <map>
0024 
0025 
0026 /// Namespace for the AIDA detector description toolkit
0027 namespace dd4hep {
0028 
0029   /// Helper class to ease testing of plugins: Effectively a container of object extensions.
0030   class PluginTester  {
0031   public:
0032     /// Definition of the extension type
0033     typedef std::pair<const std::type_info*,std::string> key_type;
0034     /// Mapped extension type
0035     typedef std::map<key_type, void*> Extensions;
0036     /// Extensions destructor type
0037     typedef void (*destruct_t)(void*);
0038 
0039     /// Defintiion of the extension entry
0040     struct Entry {
0041       destruct_t destruct = nullptr;
0042       int id = -1;
0043     };
0044     typedef std::map<const std::type_info*, Entry> ExtensionMap;
0045 
0046     /// The extensions object
0047     Extensions    extensions; //!
0048     /// Pointer to the extension map
0049     ExtensionMap* extensionMap = 0; //!
0050 
0051     /// Function to be passed as dtor if object should NOT be deleted!
0052     static void _noDelete(void*) {}
0053 
0054     /// Templated destructor function
0055     template <typename T> static void _delete(void* ptr) {
0056       delete (T*) (ptr);
0057     }
0058     
0059     /// Add an extension object to the detector element
0060     void* addExtension(void* ptr, const std::string& name, const std::type_info& info, destruct_t dtor);
0061     /// Access an existing extension object from the detector element
0062     void* extension(const std::string& name, const std::type_info& info, bool alert) const;
0063     /// Remove an existing extension object from the instance
0064     void* removeExtension(const std::string& name, const std::type_info& info, bool destroy);
0065 
0066   public:
0067     /// Default constructor
0068     PluginTester();
0069     /// Copy constructor
0070     PluginTester(const PluginTester& copy) = delete;
0071     /// Default destructor
0072     virtual ~PluginTester();
0073     /// Assignment operator
0074     PluginTester& operator=(const PluginTester& copy) = delete;
0075     /// Clear all extensions
0076     void clear(bool destroy=true);
0077     template<typename Q> Q* addExtension(Q* ptr, const std::string& name)  {
0078       return (Q*)addExtension(ptr, name, typeid(Q), _delete<Q>);
0079     }
0080     template<typename Q> Q* extension(const std::string& name, bool alert=true)  {
0081       return (Q*)extension(name, typeid(Q), alert);
0082     }
0083     template<typename Q> Q* removeExtension(const std::string& name, bool destroy=true)  {
0084       return (Q*)removeExtension(name, typeid(Q), destroy);
0085     }
0086   };
0087   
0088 } /* End namespace dd4hep             */
0089 #endif  // DD4HEP_PLUGINTESTER_H