File indexing completed on 2025-01-18 09:13:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef DD4HEP_EXTENSIONENTRY_H
0022 #define DD4HEP_EXTENSIONENTRY_H
0023
0024
0025 #include <DD4hep/Primitives.h>
0026
0027
0028 #include <typeinfo>
0029
0030
0031 namespace dd4hep {
0032
0033
0034
0035
0036
0037
0038
0039
0040 class ExtensionEntry {
0041 protected:
0042
0043 ExtensionEntry() = default;
0044
0045 ExtensionEntry(const ExtensionEntry& copy) = default;
0046 public:
0047
0048 virtual ~ExtensionEntry() = default;
0049
0050 void invalidCall(const char* tag) const;
0051
0052 virtual void* object() const = 0;
0053
0054 virtual void* copy(void*) const = 0;
0055
0056 virtual void destruct() const = 0;
0057
0058 virtual ExtensionEntry* clone(void* arg) const = 0;
0059
0060 virtual unsigned long long int hash64() const = 0;
0061 };
0062
0063 namespace detail {
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
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
0084 SimpleExtension() = delete;
0085
0086 SimpleExtension(T* p) : ptr(p) { iface = dynamic_cast<Q*>(p); }
0087
0088 SimpleExtension(const SimpleExtension& copy) = default;
0089
0090 virtual ~SimpleExtension() = default;
0091
0092 SimpleExtension& operator=(const SimpleExtension& copy) = default;
0093
0094 virtual void* copy(void*) const override { invalidCall("copy"); return 0; }
0095
0096 virtual void destruct() const override { }
0097
0098 virtual void* object() const override
0099 { return iface ? iface : (iface=dynamic_cast<Q*>(ptr)); }
0100
0101 virtual ExtensionEntry* clone(void*) const override
0102 { invalidCall("clone"); return 0; }
0103
0104 virtual unsigned long long int hash64() const override
0105 { return detail::typeHash64<Q>(); }
0106 };
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
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
0129 DeleteExtension() = delete;
0130
0131 DeleteExtension(T* p) : ptr(p) { iface = dynamic_cast<Q*>(p); }
0132
0133 DeleteExtension(const DeleteExtension& copy) = default;
0134
0135 virtual ~DeleteExtension() = default;
0136
0137 DeleteExtension& operator=(const DeleteExtension& copy) = default;
0138
0139 virtual void* copy(void*) const override { invalidCall("copy"); return 0; }
0140
0141 virtual void destruct() const override { delete ptr; }
0142
0143 virtual void* object() const override
0144 { return iface ? iface : (iface=dynamic_cast<Q*>(ptr)); }
0145
0146 virtual ExtensionEntry* clone(void* arg) const override
0147 { return new DeleteExtension((T*)this->copy(arg)); }
0148
0149 virtual unsigned long long int hash64() const override
0150 { return detail::typeHash64<Q>(); }
0151 };
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
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
0174 CopyDeleteExtension() = delete;
0175
0176 CopyDeleteExtension(T* p) : ptr(p) { iface = dynamic_cast<Q*>(p); }
0177
0178 CopyDeleteExtension(const CopyDeleteExtension& copy) = default;
0179
0180 virtual ~CopyDeleteExtension() = default;
0181
0182 CopyDeleteExtension& operator=(const CopyDeleteExtension& copy) = default;
0183
0184 virtual void* copy(void*) const override { return new T(*ptr); }
0185
0186 virtual void destruct() const override { delete ptr; }
0187
0188 virtual void* object() const override
0189 { return iface ? iface : (iface=dynamic_cast<Q*>(ptr)); }
0190
0191 virtual ExtensionEntry* clone(void* arg) const override
0192 { return new CopyDeleteExtension((T*)this->copy(arg)); }
0193
0194 virtual unsigned long long int hash64() const override
0195 { return detail::typeHash64<Q>(); }
0196 };
0197 }
0198 }
0199 #endif