Gaudi Framework, version v23r2

Home   Generated: Thu Jun 28 2012

implements.h

Go to the documentation of this file.
00001 #ifndef GAUDIKERNEL_IMPLEMENTS_H
00002 #define GAUDIKERNEL_IMPLEMENTS_H
00003 
00004 #include "GaudiKernel/IInterface.h"
00005 
00006 #ifndef __GCCXML__
00007 
00008 
00009 
00010 template <typename T>
00011 struct GAUDI_LOCAL interfaceMatch {
00013   const InterfaceID &target;
00015   void *&ptr;
00017   const T *instance;
00018   interfaceMatch(const T *_instance, const InterfaceID &_tid, void * &_ptr):
00019     target(_tid),
00020     ptr(_ptr),
00021     instance(_instance){}
00022 
00023   template <typename IID>
00024   inline void operator() (IID) {
00025     if ((!ptr) && target.versionMatch(IID::interfaceID())) {
00026       ptr = const_cast<void*>(reinterpret_cast<const void*>(static_cast<const typename IID::iface_type*>(instance)));
00027     }
00028   }
00029 };
00030 
00033 struct GAUDI_LOCAL AppendInterfaceName {
00035   std::vector<std::string> &v;
00036   AppendInterfaceName(std::vector<std::string> &_v): v(_v) {}
00037 
00038   template <typename IID>
00039   inline void operator() (IID) { v.push_back(IID::name()); }
00040 };
00041 
00042 #endif
00043 
00044 #define _refcounting_implementation_ \
00045 public: \
00046  \
00047   virtual unsigned long addRef() { return ++m_refCount; } \
00048  \
00049   virtual unsigned long release() { \
00050     /* Avoid to decrement 0 */ \
00051     const unsigned long count = (m_refCount) ? --m_refCount : m_refCount; \
00052     if(count == 0) delete this; \
00053     return count; \
00054   } \
00055  \
00056   virtual unsigned long refCount() const { return m_refCount; } \
00057 protected: \
00058  \
00059   unsigned long m_refCount; \
00060 private:
00061 
00062 #ifndef __GCCXML__
00063 #define _helper_common_implementation_(N) \
00064   public: \
00065  \
00066   virtual void *i_cast(const InterfaceID &tid) const { \
00067     void *ptr = 0; \
00068     interfaceMatch<implements##N> matcher(this,tid,ptr); \
00069     mpl::for_each<interfaces>(matcher); \
00070     return ptr; \
00071   } \
00072  \
00073   virtual StatusCode queryInterface(const InterfaceID &ti, void** pp){ \
00074     if (!pp) return StatusCode::FAILURE; \
00075     *pp = 0; \
00076     interfaceMatch<implements##N> matcher(this,ti,*pp); \
00077     mpl::for_each<interfaces>(matcher); \
00078     if (!*pp) { /* cast failed */ \
00079       return StatusCode::FAILURE; \
00080     } \
00081     this->addRef(); \
00082     return StatusCode::SUCCESS; \
00083   } \
00084  \
00085   virtual std::vector<std::string> getInterfaceNames() const { \
00086     std::vector<std::string> v; /* temporary storage */ \
00087     AppendInterfaceName appender(v); \
00088     mpl::for_each<interfaces>(appender); \
00089     return v; \
00090   } \
00091  \
00092   implements##N():m_refCount(0) {} \
00093  \
00094   virtual ~implements##N() {} \
00095   _refcounting_implementation_
00096 #else
00097 #define _helper_common_implementation_(N) \
00098   public: \
00099  \
00100   virtual void *i_cast(const InterfaceID &tid) const { \
00101     return 0; \
00102   } \
00103  \
00104   virtual StatusCode queryInterface(const InterfaceID &ti, void** pp){ \
00105     if (!pp) return StatusCode::FAILURE; \
00106     *pp = 0; \
00107     return StatusCode::SUCCESS; \
00108   } \
00109  \
00110   virtual std::vector<std::string> getInterfaceNames() const { \
00111     std::vector<std::string> v; /* temporary storage */ \
00112     return v; \
00113   } \
00114  \
00115   implements##N():m_refCount(0) {} \
00116  \
00117   virtual ~implements##N() {} \
00118   _refcounting_implementation_
00119 #endif
00120 
00124 template <typename I1>
00125 struct GAUDI_API implements1: virtual public extend_interfaces1<I1> {
00127   typedef implements1 base_class;
00129   typedef extend_interfaces1<I1> extend_interfaces_base;
00130 #ifndef __GCCXML__
00131 
00132   typedef typename extend_interfaces_base::ext_iids interfaces;
00133 #endif
00134 
00135   _helper_common_implementation_(1)
00136 };
00137 
00141 template <typename I1, typename I2>
00142 struct GAUDI_API implements2: virtual public extend_interfaces2<I1,I2> {
00144   typedef implements2 base_class;
00146   typedef extend_interfaces2<I1,I2> extend_interfaces_base;
00147 #ifndef __GCCXML__
00148 
00149   typedef typename extend_interfaces_base::ext_iids interfaces;
00150 #endif
00151 
00152   _helper_common_implementation_(2)
00153 };
00154 
00158 template <typename I1, typename I2, typename I3>
00159 struct GAUDI_API implements3: virtual public extend_interfaces3<I1,I2,I3> {
00161   typedef implements3 base_class;
00163   typedef extend_interfaces3<I1,I2,I3> extend_interfaces_base;
00164 #ifndef __GCCXML__
00165 
00166   typedef typename extend_interfaces_base::ext_iids interfaces;
00167 #endif
00168 
00169   _helper_common_implementation_(3)
00170 };
00171 
00175 template <typename I1, typename I2, typename I3, typename I4>
00176 struct GAUDI_API implements4: virtual public extend_interfaces4<I1,I2,I3,I4> {
00178   typedef implements4 base_class;
00180   typedef extend_interfaces4<I1,I2,I3,I4> extend_interfaces_base;
00181 #ifndef __GCCXML__
00182 
00183   typedef typename extend_interfaces_base::ext_iids interfaces;
00184 #endif
00185 
00186   _helper_common_implementation_(4)
00187 };
00188 
00189 // Undefine helper macros
00190 #undef _refcounting_implementation_
00191 #undef _helper_common_implementation_
00192 
00193 #endif /* GAUDIKERNEL_IMPLEMENTS_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 23:27:20 for Gaudi Framework, version v23r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004