Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 08:35:03

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