| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
implements.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_IMPLEMENTS_H
2 #define GAUDIKERNEL_IMPLEMENTS_H
3
4 #include "GaudiKernel/IInterface.h"
5
6 #ifndef __GCCXML__
7
8
9
10 template <typename T>
11 struct GAUDI_LOCAL interfaceMatch {
13 const InterfaceID &target;
15 void *&ptr;
17 const T *instance;
18 interfaceMatch(const T *_instance, const InterfaceID &_tid, void * &_ptr):
19 target(_tid),
20 ptr(_ptr),
21 instance(_instance){}
22
23 template <typename IID>
24 inline void operator() (IID) {
25 if ((!ptr) && target.versionMatch(IID::interfaceID())) {
26 ptr = const_cast<void*>(reinterpret_cast<const void*>(static_cast<const typename IID::iface_type*>(instance)));
27 }
28 }
29 };
30
33 struct GAUDI_LOCAL AppendInterfaceName {
35 std::vector<std::string> &v;
36 AppendInterfaceName(std::vector<std::string> &_v): v(_v) {}
37
38 template <typename IID>
39 inline void operator() (IID) { v.push_back(IID::name()); }
40 };
41
42 #endif
43
44 #define _refcounting_implementation_ \
45 public: \
46 \
47 virtual unsigned long addRef() { return ++m_refCount; } \
48 \
49 virtual unsigned long release() { \
50 /* Avoid to decrement 0 */ \
51 const unsigned long count = (m_refCount) ? --m_refCount : m_refCount; \
52 if(count == 0) delete this; \
53 return count; \
54 } \
55 \
56 virtual unsigned long refCount() const { return m_refCount; } \
57 protected: \
58 \
59 unsigned long m_refCount; \
60 private:
61
62 #ifndef __GCCXML__
63 #define _helper_common_implementation_(N) \
64 public: \
65 \
66 virtual void *i_cast(const InterfaceID &tid) const { \
67 void *ptr = 0; \
68 interfaceMatch<implements##N> matcher(this,tid,ptr); \
69 mpl::for_each<interfaces>(matcher); \
70 return ptr; \
71 } \
72 \
73 virtual StatusCode queryInterface(const InterfaceID &ti, void** pp){ \
74 if (!pp) return StatusCode::FAILURE; \
75 *pp = 0; \
76 interfaceMatch<implements##N> matcher(this,ti,*pp); \
77 mpl::for_each<interfaces>(matcher); \
78 if (!*pp) { /* cast failed */ \
79 return StatusCode::FAILURE; \
80 } \
81 this->addRef(); \
82 return StatusCode::SUCCESS; \
83 } \
84 \
85 virtual std::vector<std::string> getInterfaceNames() const { \
86 std::vector<std::string> v; /* temporary storage */ \
87 AppendInterfaceName appender(v); \
88 mpl::for_each<interfaces>(appender); \
89 return v; \
90 } \
91 \
92 implements##N():m_refCount(0) {} \
93 \
94 implements##N(const implements##N &/*other*/):m_refCount(0) {} \
95 \
96 implements##N& operator=(const implements##N &/*other*/) { return *this; } \
97 \
98 virtual ~implements##N() {} \
99 _refcounting_implementation_
100 #else
101 #define _helper_common_implementation_(N) \
102 public: \
103 \
104 virtual void *i_cast(const InterfaceID &tid) const { \
105 return 0; \
106 } \
107 \
108 virtual StatusCode queryInterface(const InterfaceID &ti, void** pp){ \
109 if (!pp) return StatusCode::FAILURE; \
110 *pp = 0; \
111 return StatusCode::SUCCESS; \
112 } \
113 \
114 virtual std::vector<std::string> getInterfaceNames() const { \
115 std::vector<std::string> v; /* temporary storage */ \
116 return v; \
117 } \
118 \
119 implements##N():m_refCount(0) {} \
120 \
121 implements##N(const implements##N &/*other*/):m_refCount(0) {} \
122 \
123 implements##N& operator=(const implements##N &/*other*/) { return *this; } \
124 \
125 virtual ~implements##N() {} \
126 _refcounting_implementation_
127 #endif
128
132 template <typename I1>
133 struct GAUDI_API implements1: virtual public extend_interfaces1<I1> {
135 typedef implements1 base_class;
137 typedef extend_interfaces1<I1> extend_interfaces_base;
138 #ifndef __GCCXML__
139
140 typedef typename extend_interfaces_base::ext_iids interfaces;
141 #endif
142
143 _helper_common_implementation_(1)
144 };
145
149 template <typename I1, typename I2>
150 struct GAUDI_API implements2: virtual public extend_interfaces2<I1,I2> {
152 typedef implements2 base_class;
154 typedef extend_interfaces2<I1,I2> extend_interfaces_base;
155 #ifndef __GCCXML__
156
157 typedef typename extend_interfaces_base::ext_iids interfaces;
158 #endif
159
160 _helper_common_implementation_(2)
161 };
162
166 template <typename I1, typename I2, typename I3>
167 struct GAUDI_API implements3: virtual public extend_interfaces3<I1,I2,I3> {
169 typedef implements3 base_class;
171 typedef extend_interfaces3<I1,I2,I3> extend_interfaces_base;
172 #ifndef __GCCXML__
173
174 typedef typename extend_interfaces_base::ext_iids interfaces;
175 #endif
176
177 _helper_common_implementation_(3)
178 };
179
183 template <typename I1, typename I2, typename I3, typename I4>
184 struct GAUDI_API implements4: virtual public extend_interfaces4<I1,I2,I3,I4> {
186 typedef implements4 base_class;
188 typedef extend_interfaces4<I1,I2,I3,I4> extend_interfaces_base;
189 #ifndef __GCCXML__
190
191 typedef typename extend_interfaces_base::ext_iids interfaces;
192 #endif
193
194 _helper_common_implementation_(4)
195 };
196
197 // Undefine helper macros
198 #undef _refcounting_implementation_
199 #undef _helper_common_implementation_
200
201 #endif /* GAUDIKERNEL_IMPLEMENTS_H_ */