DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ExtensionEntry.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 : M.Frank
11 //
12 //==========================================================================
13 //
14 // NOTE:
15 //
16 // This is an internal include file. It should only be included to
17 // instantiate code. Otherwise the BasicGrammar include file should be
18 // sufficient for all practical purposes.
19 //
20 //==========================================================================
21 #ifndef DD4HEP_EXTENSIONENTRY_H
22 #define DD4HEP_EXTENSIONENTRY_H
23 
24 // Framework include files
25 #include <DD4hep/Primitives.h>
26 
27 // C/C++ include files
28 #include <typeinfo>
29 
31 namespace dd4hep {
32 
34 
41  protected:
43  ExtensionEntry() = default;
45  ExtensionEntry(const ExtensionEntry& copy) = default;
46  public:
48  virtual ~ExtensionEntry() = default;
50  void invalidCall(const char* tag) const;
52  virtual void* object() const = 0;
54  virtual void* copy(void*) const = 0;
56  virtual void destruct() const = 0;
58  virtual ExtensionEntry* clone(void* arg) const = 0;
60  virtual unsigned long long int hash64() const = 0;
61  };
62 
63  namespace detail {
64 
66 
78  template <typename Q,typename T> class SimpleExtension : public ExtensionEntry {
79  protected:
80  T* ptr = 0;
81  mutable Q* iface = 0;
82  public:
84  SimpleExtension() = delete;
86  SimpleExtension(T* p) : ptr(p) { iface = dynamic_cast<Q*>(p); }
90  virtual ~SimpleExtension() = default;
94  virtual void* copy(void*) const override { invalidCall("copy"); return 0; }
96  virtual void destruct() const override { }
98  virtual void* object() const override
99  { return iface ? iface : (iface=dynamic_cast<Q*>(ptr)); }
101  virtual ExtensionEntry* clone(void*) const override
102  { invalidCall("clone"); return 0; }
104  virtual unsigned long long int hash64() const override
105  { return detail::typeHash64<Q>(); }
106  };
107 
109 
123  template <typename Q,typename T> class DeleteExtension : public ExtensionEntry {
124  protected:
125  T* ptr = 0;
126  mutable Q* iface = 0;
127  public:
129  DeleteExtension() = delete;
131  DeleteExtension(T* p) : ptr(p) { iface = dynamic_cast<Q*>(p); }
135  virtual ~DeleteExtension() = default;
139  virtual void* copy(void*) const override { invalidCall("copy"); return 0; }
141  virtual void destruct() const override { delete ptr; }
143  virtual void* object() const override
144  { return iface ? iface : (iface=dynamic_cast<Q*>(ptr)); }
146  virtual ExtensionEntry* clone(void* arg) const override
147  { return new DeleteExtension((T*)this->copy(arg)); }
149  virtual unsigned long long int hash64() const override
150  { return detail::typeHash64<Q>(); }
151  };
152 
154 
168  template <typename Q,typename T> class CopyDeleteExtension : public ExtensionEntry {
169  protected:
170  T* ptr = 0;
171  mutable Q* iface = 0;
172  public:
176  CopyDeleteExtension(T* p) : ptr(p) { iface = dynamic_cast<Q*>(p); }
180  virtual ~CopyDeleteExtension() = default;
184  virtual void* copy(void*) const override { return new T(*ptr); }
186  virtual void destruct() const override { delete ptr; }
188  virtual void* object() const override
189  { return iface ? iface : (iface=dynamic_cast<Q*>(ptr)); }
191  virtual ExtensionEntry* clone(void* arg) const override
192  { return new CopyDeleteExtension((T*)this->copy(arg)); }
194  virtual unsigned long long int hash64() const override
195  { return detail::typeHash64<Q>(); }
196  };
197  } // End namespace detail
198 } // End namespace dd4hep
199 #endif // DD4HEP_EXTENSIONENTRY_H
dd4hep::ExtensionEntry
Definition of the extension entry interface class.
Definition: ExtensionEntry.h:40
dd4hep::detail::DeleteExtension::clone
virtual ExtensionEntry * clone(void *arg) const override
Virtual entry clone function.
Definition: ExtensionEntry.h:146
dd4hep::detail::SimpleExtension::object
virtual void * object() const override
Virtual object accessor.
Definition: ExtensionEntry.h:98
dd4hep::detail::CopyDeleteExtension::object
virtual void * object() const override
Virtual object accessor.
Definition: ExtensionEntry.h:188
dd4hep::detail::SimpleExtension::~SimpleExtension
virtual ~SimpleExtension()=default
Default destructor.
dd4hep::ExtensionEntry::destruct
virtual void destruct() const =0
Virtual object destructor.
dd4hep::detail::CopyDeleteExtension::CopyDeleteExtension
CopyDeleteExtension(const CopyDeleteExtension &copy)=default
Copy constructor.
dd4hep::detail::DeleteExtension::DeleteExtension
DeleteExtension(const DeleteExtension &copy)=default
Copy constructor.
dd4hep::detail::SimpleExtension::SimpleExtension
SimpleExtension(const SimpleExtension &copy)=default
Copy constructor.
dd4hep::detail::SimpleExtension::copy
virtual void * copy(void *) const override
Virtual object copy operator.
Definition: ExtensionEntry.h:94
dd4hep::detail::CopyDeleteExtension
Implementation class for the object extension mechanism.
Definition: ExtensionEntry.h:168
dd4hep::detail::SimpleExtension::hash64
virtual unsigned long long int hash64() const override
Hash value.
Definition: ExtensionEntry.h:104
dd4hep::ExtensionEntry::clone
virtual ExtensionEntry * clone(void *arg) const =0
Virtual entry clone function.
dd4hep::detail::SimpleExtension
Implementation class for the object extension mechanism.
Definition: ExtensionEntry.h:78
dd4hep::detail::SimpleExtension::destruct
virtual void destruct() const override
Virtual object destructor. Function may still be called without side-effects.
Definition: ExtensionEntry.h:96
dd4hep::detail::SimpleExtension::ptr
T * ptr
Definition: ExtensionEntry.h:80
dd4hep::ExtensionEntry::~ExtensionEntry
virtual ~ExtensionEntry()=default
Default destructor.
dd4hep::ExtensionEntry::invalidCall
void invalidCall(const char *tag) const
Callback on invalid call invokation.
Definition: ExtensionEntry.cpp:19
dd4hep::detail::CopyDeleteExtension::clone
virtual ExtensionEntry * clone(void *arg) const override
Virtual entry clone function.
Definition: ExtensionEntry.h:191
dd4hep::detail::CopyDeleteExtension::hash64
virtual unsigned long long int hash64() const override
Hash value.
Definition: ExtensionEntry.h:194
dd4hep::detail::DeleteExtension::DeleteExtension
DeleteExtension(T *p)
Initializing constructor.
Definition: ExtensionEntry.h:131
dd4hep::detail::CopyDeleteExtension::iface
Q * iface
Definition: ExtensionEntry.h:171
dd4hep::detail::DeleteExtension
Implementation class for the object extension mechanism.
Definition: ExtensionEntry.h:123
dd4hep::ExtensionEntry::object
virtual void * object() const =0
Virtual object accessor.
dd4hep::detail::CopyDeleteExtension::~CopyDeleteExtension
virtual ~CopyDeleteExtension()=default
Default destructor.
dd4hep::detail::SimpleExtension::iface
Q * iface
Definition: ExtensionEntry.h:81
dd4hep::ExtensionEntry::ExtensionEntry
ExtensionEntry(const ExtensionEntry &copy)=default
Copy constructor.
dd4hep::detail::CopyDeleteExtension::operator=
CopyDeleteExtension & operator=(const CopyDeleteExtension &copy)=default
Assignment operator.
dd4hep::ExtensionEntry::copy
virtual void * copy(void *) const =0
Virtual object copy operator.
dd4hep::detail::DeleteExtension::operator=
DeleteExtension & operator=(const DeleteExtension &copy)=default
Assignment operator.
dd4hep::detail::SimpleExtension::operator=
SimpleExtension & operator=(const SimpleExtension &copy)=default
Assignment operator.
dd4hep::detail::CopyDeleteExtension::destruct
virtual void destruct() const override
Virtual object destructor.
Definition: ExtensionEntry.h:186
dd4hep::detail::DeleteExtension::~DeleteExtension
virtual ~DeleteExtension()=default
Default destructor.
Primitives.h
dd4hep::ExtensionEntry::ExtensionEntry
ExtensionEntry()=default
Default constructor.
dd4hep::detail::SimpleExtension::SimpleExtension
SimpleExtension(T *p)
Initializing constructor.
Definition: ExtensionEntry.h:86
dd4hep::detail::DeleteExtension::object
virtual void * object() const override
Virtual object accessor.
Definition: ExtensionEntry.h:143
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::detail::DeleteExtension::iface
Q * iface
Definition: ExtensionEntry.h:126
dd4hep::detail::CopyDeleteExtension::CopyDeleteExtension
CopyDeleteExtension()=delete
Default constructor.
dd4hep::detail::DeleteExtension::hash64
virtual unsigned long long int hash64() const override
Hash value.
Definition: ExtensionEntry.h:149
dd4hep::detail::CopyDeleteExtension::CopyDeleteExtension
CopyDeleteExtension(T *p)
Initializing constructor.
Definition: ExtensionEntry.h:176
dd4hep::detail::DeleteExtension::ptr
T * ptr
Definition: ExtensionEntry.h:125
dd4hep::detail::CopyDeleteExtension::copy
virtual void * copy(void *) const override
Virtual object copy operator.
Definition: ExtensionEntry.h:184
dd4hep::detail::SimpleExtension::clone
virtual ExtensionEntry * clone(void *) const override
Virtual entry clone function.
Definition: ExtensionEntry.h:101
dd4hep::detail::CopyDeleteExtension::ptr
T * ptr
Definition: ExtensionEntry.h:170
dd4hep::detail::SimpleExtension::SimpleExtension
SimpleExtension()=delete
Default constructor.
dd4hep::detail::DeleteExtension::copy
virtual void * copy(void *) const override
Virtual object copy operator.
Definition: ExtensionEntry.h:139
dd4hep::detail::DeleteExtension::DeleteExtension
DeleteExtension()=delete
Default constructor.
dd4hep::detail::DeleteExtension::destruct
virtual void destruct() const override
Virtual object destructor.
Definition: ExtensionEntry.h:141
dd4hep::ExtensionEntry::hash64
virtual unsigned long long int hash64() const =0
Hash value.