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 
5 
6 #ifndef __GCCXML__
7 template <typename T>
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 
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> {
138 #ifndef __GCCXML__
141 #endif
142 
144 };
145 
149 template <typename I1, typename I2>
150 struct GAUDI_API implements2: virtual public extend_interfaces2<I1,I2> {
155 #ifndef __GCCXML__
158 #endif
159 
161 };
162 
166 template <typename I1, typename I2, typename I3>
167 struct GAUDI_API implements3: virtual public extend_interfaces3<I1,I2,I3> {
172 #ifndef __GCCXML__
175 #endif
176 
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> {
189 #ifndef __GCCXML__
192 #endif
193 
195 };
196 
197 // Undefine helper macros
198 #undef _refcounting_implementation_
199 #undef _helper_common_implementation_
200 
201 #endif /* GAUDIKERNEL_IMPLEMENTS_H_ */
Base class to be used to extend an interface.
extend_interfaces_base::ext_iids interfaces
MPL set of all the implemented interfaces.
Definition: implements.h:157
Base class to be used to extend an interface.
mpl::fold< typename IAuditor::iid::iids::type, typename IProperty::iid::iids::type, mpl::insert< mpl::_1, mpl::_2 > >::type ext_iids
MPL set of interfaces extended by this one.
Helper class for the cast used in the MPL for_each algorithm in the implementation of queryInterface...
Definition: implements.h:11
const T * instance
Value of this.
Definition: implements.h:17
Base class used to implement the interfaces.
Definition: implements.h:167
Base class used to implement the interfaces.
Definition: implements.h:150
Base class to be used to extend an interface.
extend_interfaces4< I1, I2, I3, I4 > extend_interfaces_base
Typedef to the base of this class.
Definition: implements.h:188
std::vector< std::string > & v
vector to be filled.
Definition: implements.h:35
AppendInterfaceName(std::vector< std::string > &_v)
Definition: implements.h:36
void *& ptr
Pointer to be filled.
Definition: implements.h:15
interfaceMatch(const T *_instance, const InterfaceID &_tid, void *&_ptr)
Definition: implements.h:18
extend_interfaces1< I1 > extend_interfaces_base
Typedef to the base of this class.
Definition: implements.h:137
Base class used to implement the interfaces.
Definition: implements.h:133
Interface ID class.
Definition: IInterface.h:55
#define _helper_common_implementation_(N)
Definition: implements.h:63
implements3 base_class
Typedef to this class.
Definition: implements.h:169
#define GAUDI_LOCAL
Definition: Kernel.h:100
extend_interfaces_base::ext_iids interfaces
MPL set of all the implemented interfaces.
Definition: implements.h:174
IInterface::iid::iids::type ext_iids
MPL set of interfaces extended by this one.
implements1 base_class
Typedef to this class.
Definition: implements.h:135
mpl::fold< typename IAppMgrUI::iid::iids::type, typename mpl::fold< typename IEventProcessor::iid::iids::type, typename mpl::fold< typename IService::iid::iids::type, typename IStateful::iid::iids::type, mpl::insert< mpl::_1, mpl::_2 > >::type, mpl::insert< mpl::_1, mpl::_2 > >::type, mpl::insert< mpl::_1, mpl::_2 > >::type ext_iids
MPL set of interfaces extended by this one.
const InterfaceID & target
InterfaceID for the requested interface.
Definition: implements.h:13
extend_interfaces_base::ext_iids interfaces
MPL set of all the implemented interfaces.
Definition: implements.h:140
extend_interfaces_base::ext_iids interfaces
MPL set of all the implemented interfaces.
Definition: implements.h:191
implements2 base_class
Typedef to this class.
Definition: implements.h:152
Base class to be used to extend an interface.
extend_interfaces3< I1, I2, I3 > extend_interfaces_base
Typedef to the base of this class.
Definition: implements.h:171
#define GAUDI_API
Definition: Kernel.h:108
Base class used to implement the interfaces.
Definition: implements.h:184
implements4 base_class
Typedef to this class.
Definition: implements.h:186
Helper class for the cast used in the MPL for_each algorithm in the implementation of query_interface...
Definition: implements.h:33
mpl::fold< typename IService::iid::iids::type, typename mpl::fold< typename IProperty::iid::iids::type, typename IStateful::iid::iids::type, mpl::insert< mpl::_1, mpl::_2 > >::type, mpl::insert< mpl::_1, mpl::_2 > >::type ext_iids
MPL set of interfaces extended by this one.
extend_interfaces2< I1, I2 > extend_interfaces_base
Typedef to the base of this class.
Definition: implements.h:154