Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:33

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     : M.Frank
0011 //
0012 //==========================================================================
0013 //
0014 // NOTE:
0015 //
0016 // This is an internal include file. It should only be included to 
0017 // instantiate code. Otherwise the BasicGrammar include file should be
0018 // sufficient for all practical purposes.
0019 //
0020 //==========================================================================
0021 #ifndef DD4HEP_EXTENSIONENTRY_H
0022 #define DD4HEP_EXTENSIONENTRY_H
0023 
0024 // Framework include files
0025 #include <DD4hep/Primitives.h>
0026 
0027 // C/C++ include files
0028 #include <typeinfo>
0029 
0030 /// Namespace for the AIDA detector description toolkit
0031 namespace dd4hep {
0032 
0033   /// Definition of the extension entry interface class
0034   /** Base class for the object extension mechanism.
0035    *
0036    *   \author  M.Frank
0037    *   \date    13.08.2013
0038    *   \ingroup DD4HEP
0039    */
0040   class ExtensionEntry {
0041   protected:
0042     /// Default constructor
0043     ExtensionEntry() = default;
0044     /// Copy constructor
0045     ExtensionEntry(const ExtensionEntry& copy) = default;
0046   public:
0047     /// Default destructor
0048     virtual ~ExtensionEntry() = default;
0049     /// Callback on invalid call invokation
0050     void invalidCall(const char* tag)  const;
0051     /// Virtual object accessor
0052     virtual void* object() const    = 0;
0053     /// Virtual object copy operator
0054     virtual void* copy(void*) const = 0;
0055     /// Virtual object destructor
0056     virtual void  destruct() const  = 0;
0057     /// Virtual entry clone function
0058     virtual ExtensionEntry* clone(void* arg)  const = 0;
0059     /// Hash value
0060     virtual unsigned long long int hash64()  const = 0;
0061   };
0062 
0063   namespace detail  {
0064 
0065     /// Implementation class for the object extension mechanism.
0066     /**  This implementation class supports the object extension mechanism
0067      *   for dd4hep. 
0068      *
0069      *   Note:
0070      *   The double-template implementation is necessary to support extensions
0071      *   using a virtual inheritance relationship between the interface and the
0072      *   concrete implementation of the extension object.
0073      *
0074      *   \author  M.Frank
0075      *   \date    13.08.2013
0076      *   \ingroup DD4HEP
0077      */
0078     template <typename Q,typename T> class SimpleExtension : public ExtensionEntry  {
0079     protected:
0080       T* ptr = 0;
0081       mutable Q* iface = 0;  //!
0082     public:
0083       /// Default constructor
0084       SimpleExtension() = delete;
0085       /// Initializing constructor
0086       SimpleExtension(T* p) : ptr(p) { iface = dynamic_cast<Q*>(p); }
0087       /// Copy constructor
0088       SimpleExtension(const SimpleExtension& copy) = default;
0089       /// Default destructor
0090       virtual ~SimpleExtension() = default;
0091       /// Assignment operator
0092       SimpleExtension& operator=(const SimpleExtension& copy) = default;
0093       /// Virtual object copy operator
0094       virtual void* copy(void*) const override { invalidCall("copy"); return 0;   }
0095       /// Virtual object destructor. Function may still be called without side-effects.
0096       virtual void  destruct()  const override {                                  }
0097       /// Virtual object accessor
0098       virtual void* object()    const override
0099       { return iface ? iface : (iface=dynamic_cast<Q*>(ptr));                     }
0100       /// Virtual entry clone function
0101       virtual ExtensionEntry* clone(void*)  const  override
0102       { invalidCall("clone"); return 0;                                           }
0103       /// Hash value
0104       virtual unsigned long long int hash64()  const override
0105       {  return detail::typeHash64<Q>();                                       }
0106     };
0107       
0108     /// Implementation class for the object extension mechanism.
0109     /**  This implementation class supports the object extension mechanism
0110      *   for dd4hep. It is ensured, that on the object destruction or
0111      *   on request the reference to the user object may be destructed.
0112      *
0113      *   Note: User object must be taken from the heap using "new".
0114      *   Note:
0115      *   The double-template implementation is necessary to support extensions
0116      *   using a virtual inheritance relationship between the interface and the
0117      *   concrete implementation of the extension object.
0118      *
0119      *   \author  M.Frank
0120      *   \date    13.08.2013
0121      *   \ingroup DD4HEP
0122      */
0123     template <typename Q,typename T> class DeleteExtension : public ExtensionEntry  {
0124     protected:
0125       T* ptr = 0;
0126       mutable Q* iface = 0;  //!
0127     public:
0128       /// Default constructor
0129       DeleteExtension() = delete;
0130       /// Initializing constructor
0131       DeleteExtension(T* p) : ptr(p)  { iface = dynamic_cast<Q*>(p); }
0132       /// Copy constructor
0133       DeleteExtension(const DeleteExtension& copy) = default;
0134       /// Default destructor
0135       virtual ~DeleteExtension() = default;
0136       /// Assignment operator
0137       DeleteExtension& operator=(const DeleteExtension& copy) = default;
0138       /// Virtual object copy operator
0139       virtual void* copy(void*)  const override  { invalidCall("copy"); return 0; }
0140       /// Virtual object destructor
0141       virtual void  destruct()   const override  { delete ptr;                    }
0142       /// Virtual object accessor
0143       virtual void* object()     const override
0144       { return iface ? iface : (iface=dynamic_cast<Q*>(ptr));                     }
0145       /// Virtual entry clone function
0146       virtual ExtensionEntry* clone(void* arg)  const  override
0147       {  return new DeleteExtension((T*)this->copy(arg));                         }
0148       /// Hash value
0149       virtual unsigned long long int hash64()  const override
0150       {  return detail::typeHash64<Q>();                                       }
0151     };
0152 
0153     /// Implementation class for the object extension mechanism.
0154     /**  This implementation class supports the object extension mechanism
0155      *   for dd4hep. It is ensured, that on the object destruction or
0156      *   on request the reference to the user object may be destructed.
0157      *
0158      *   Note: User object must be taken from the heap using "new".
0159      *   Note:
0160      *   The double-template implementation is necessary to support extensions
0161      *   using a virtual inheritance relationship between the interface and the
0162      *   concrete implementation of the extension object.
0163      *
0164      *   \author  M.Frank
0165      *   \date    13.08.2013
0166      *   \ingroup DD4HEP
0167      */
0168     template <typename Q,typename T> class CopyDeleteExtension : public ExtensionEntry  {
0169     protected:
0170       T* ptr = 0;
0171       mutable Q* iface = 0;  //!
0172     public:
0173       /// Default constructor
0174       CopyDeleteExtension() = delete;
0175       /// Initializing constructor
0176       CopyDeleteExtension(T* p) : ptr(p)  { iface = dynamic_cast<Q*>(p);          }
0177       /// Copy constructor
0178       CopyDeleteExtension(const CopyDeleteExtension& copy) = default;
0179       /// Default destructor
0180       virtual ~CopyDeleteExtension() = default;
0181       /// Assignment operator
0182       CopyDeleteExtension& operator=(const CopyDeleteExtension& copy) = default;
0183       /// Virtual object copy operator
0184       virtual void* copy(void*)  const override  { return new T(*ptr);            }
0185       /// Virtual object destructor
0186       virtual void  destruct()   const override  { delete ptr;                    }
0187       /// Virtual object accessor
0188       virtual void* object()     const override
0189       { return iface ? iface : (iface=dynamic_cast<Q*>(ptr));                     }
0190       /// Virtual entry clone function
0191       virtual ExtensionEntry* clone(void* arg)  const  override
0192       {  return new CopyDeleteExtension((T*)this->copy(arg));                     }
0193       /// Hash value
0194       virtual unsigned long long int hash64()  const override
0195       {  return detail::typeHash64<Q>();                                       }
0196     };
0197   }     // End namespace detail
0198 }       // End namespace dd4hep
0199 #endif // DD4HEP_EXTENSIONENTRY_H