Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 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   implements##N(const implements##N &/*other*/):m_refCount(0) {} \
00095  \
00096   implements##N& operator=(const implements##N &/*other*/) { return *this; } \
00097  \
00098   virtual ~implements##N() {} \
00099   _refcounting_implementation_
00100 #else
00101 #define _helper_common_implementation_(N) \
00102   public: \
00103  \
00104   virtual void *i_cast(const InterfaceID &tid) const { \
00105     return 0; \
00106   } \
00107  \
00108   virtual StatusCode queryInterface(const InterfaceID &ti, void** pp){ \
00109     if (!pp) return StatusCode::FAILURE; \
00110     *pp = 0; \
00111     return StatusCode::SUCCESS; \
00112   } \
00113  \
00114   virtual std::vector<std::string> getInterfaceNames() const { \
00115     std::vector<std::string> v; /* temporary storage */ \
00116     return v; \
00117   } \
00118  \
00119   implements##N():m_refCount(0) {} \
00120  \
00121   implements##N(const implements##N &/*other*/):m_refCount(0) {} \
00122  \
00123   implements##N& operator=(const implements##N &/*other*/) { return *this; } \
00124  \
00125   virtual ~implements##N() {} \
00126   _refcounting_implementation_
00127 #endif
00128 
00132 template <typename I1>
00133 struct GAUDI_API implements1: virtual public extend_interfaces1<I1> {
00135   typedef implements1 base_class;
00137   typedef extend_interfaces1<I1> extend_interfaces_base;
00138 #ifndef __GCCXML__
00139 
00140   typedef typename extend_interfaces_base::ext_iids interfaces;
00141 #endif
00142 
00143   _helper_common_implementation_(1)
00144 };
00145 
00149 template <typename I1, typename I2>
00150 struct GAUDI_API implements2: virtual public extend_interfaces2<I1,I2> {
00152   typedef implements2 base_class;
00154   typedef extend_interfaces2<I1,I2> extend_interfaces_base;
00155 #ifndef __GCCXML__
00156 
00157   typedef typename extend_interfaces_base::ext_iids interfaces;
00158 #endif
00159 
00160   _helper_common_implementation_(2)
00161 };
00162 
00166 template <typename I1, typename I2, typename I3>
00167 struct GAUDI_API implements3: virtual public extend_interfaces3<I1,I2,I3> {
00169   typedef implements3 base_class;
00171   typedef extend_interfaces3<I1,I2,I3> extend_interfaces_base;
00172 #ifndef __GCCXML__
00173 
00174   typedef typename extend_interfaces_base::ext_iids interfaces;
00175 #endif
00176 
00177   _helper_common_implementation_(3)
00178 };
00179 
00183 template <typename I1, typename I2, typename I3, typename I4>
00184 struct GAUDI_API implements4: virtual public extend_interfaces4<I1,I2,I3,I4> {
00186   typedef implements4 base_class;
00188   typedef extend_interfaces4<I1,I2,I3,I4> extend_interfaces_base;
00189 #ifndef __GCCXML__
00190 
00191   typedef typename extend_interfaces_base::ext_iids interfaces;
00192 #endif
00193 
00194   _helper_common_implementation_(4)
00195 };
00196 
00197 // Undefine helper macros
00198 #undef _refcounting_implementation_
00199 #undef _helper_common_implementation_
00200 
00201 #endif /* GAUDIKERNEL_IMPLEMENTS_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Sep 17 2012 13:49:30 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004