| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# 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__
    00009 template <typename THIS>
    00010 struct GAUDI_LOCAL check_cast {
    00012   const std::type_info &target;
    00014   void *&ptr;
    00016   const THIS *instance;
    00017   check_cast(const THIS *_instance, const std::type_info &_tid, void * &_ptr):
    00018     target(_tid),
    00019     ptr(_ptr),
    00020     instance(_instance){}
    00021
    00022   template <typename IID>
    00023   inline void operator() (IID) {
    00024     if ((!ptr) && (typeid(typename IID::iids::type) == target)) {
    00025       ptr = const_cast<void*>(reinterpret_cast<const void*>(static_cast<const typename IID::iface_type*>(instance)));
    00026     }
    00027   }
    00028
    00029 };
    00030
    00033 template <typename THIS>
    00034 struct GAUDI_LOCAL interfaceMatch {
    00036   const InterfaceID &target;
    00038   void *&ptr;
    00040   THIS *instance;
    00041   interfaceMatch(THIS *_instance, const InterfaceID &_tid, void * &_ptr):
    00042     target(_tid),
    00043     ptr(_ptr),
    00044     instance(_instance){}
    00045
    00046   template <typename IID>
    00047   inline void operator() (IID) {
    00048     if ((!ptr) && target.versionMatch(IID::interfaceID())) {
    00049       ptr = reinterpret_cast<void*>(static_cast<typename IID::iface_type*>(instance));
    00050     }
    00051   }
    00052 };
    00053
    00056 struct GAUDI_LOCAL AppendInterfaceName {
    00058   std::vector<std::string> &v;
    00059   AppendInterfaceName(std::vector<std::string> &_v): v(_v) {}
    00060
    00061   template <typename IID>
    00062   inline void operator() (IID) { v.push_back(IID::name()); }
    00063 };
    00064
    00065 #endif
    00066
    00067 #define _refcounting_implementation_ \
    00068 public: \
    00069  \
    00070   virtual unsigned long addRef() { return ++m_refCount; } \
    00071  \
    00072   virtual unsigned long release() { \
    00073     /* Avoid to decrement 0 */ \
    00074     const unsigned long count = (m_refCount) ? --m_refCount : m_refCount; \
    00075     if(count == 0) delete this; \
    00076     return count; \
    00077   } \
    00078  \
    00079   virtual unsigned long refCount() const { return m_refCount; } \
    00080 protected: \
    00081  \
    00082   unsigned long m_refCount; \
    00083 private:
    00084
    00085 #ifndef __GCCXML__
    00086 #define _helper_common_implementation_(N) \
    00087   public: \
    00088  \
    00089   virtual void *i_cast(const std::type_info &tid) const { \
    00090     void *ptr = 0; \
    00091     check_cast<implements##N> caster(this,tid,ptr); \
    00092     mpl::for_each<interfaces>(caster); \
    00093     return ptr; \
    00094   } \
    00095  \
    00096   virtual StatusCode queryInterface(const InterfaceID &ti, void** pp){ \
    00097     if (!pp) return StatusCode::FAILURE; \
    00098     *pp = 0; \
    00099     interfaceMatch<implements##N> matcher(this,ti,*pp); \
    00100     mpl::for_each<interfaces>(matcher); \
    00101     if (!*pp) { /* cast failed */ \
    00102       return StatusCode::FAILURE; \
    00103     } \
    00104     this->addRef(); \
    00105     return StatusCode::SUCCESS; \
    00106   } \
    00107  \
    00108   virtual std::vector<std::string> getInterfaceNames() const { \
    00109     std::vector<std::string> v; /* temporary storage */ \
    00110     AppendInterfaceName appender(v); \
    00111     mpl::for_each<interfaces>(appender); \
    00112     return v; \
    00113   } \
    00114  \
    00115   implements##N():m_refCount(0) {} \
    00116  \
    00117   virtual ~implements##N() {} \
    00118   _refcounting_implementation_
    00119 #else
    00120 #define _helper_common_implementation_(N) \
    00121   public: \
    00122  \
    00123   virtual void *i_cast(const std::type_info &tid) const { \
    00124     return 0; \
    00125   } \
    00126  \
    00127   virtual StatusCode queryInterface(const InterfaceID &ti, void** pp){ \
    00128     if (!pp) return StatusCode::FAILURE; \
    00129     *pp = 0; \
    00130     return StatusCode::SUCCESS; \
    00131   } \
    00132  \
    00133   virtual std::vector<std::string> getInterfaceNames() const { \
    00134     std::vector<std::string> v; /* temporary storage */ \
    00135     return v; \
    00136   } \
    00137  \
    00138   implements##N():m_refCount(0) {} \
    00139  \
    00140   virtual ~implements##N() {} \
    00141   _refcounting_implementation_
    00142 #endif
    00143
    00147 template <typename I1>
    00148 struct GAUDI_API implements1: virtual public extend_interfaces1<I1> {
    00150   typedef implements1 base_class;
    00152   typedef extend_interfaces1<I1> extend_interfaces_base;
    00153 #ifndef __GCCXML__
    00155   typedef typename extend_interfaces_base::ext_iids interfaces;
    00156 #endif
    00157
    00158   _helper_common_implementation_(1)
    00159 };
    00160
    00164 template <typename I1, typename I2>
    00165 struct GAUDI_API implements2: virtual public extend_interfaces2<I1,I2> {
    00167   typedef implements2 base_class;
    00169   typedef extend_interfaces2<I1,I2> extend_interfaces_base;
    00170 #ifndef __GCCXML__
    00172   typedef typename extend_interfaces_base::ext_iids interfaces;
    00173 #endif
    00174
    00175   _helper_common_implementation_(2)
    00176 };
    00177
    00181 template <typename I1, typename I2, typename I3>
    00182 struct GAUDI_API implements3: virtual public extend_interfaces3<I1,I2,I3> {
    00184   typedef implements3 base_class;
    00186   typedef extend_interfaces3<I1,I2,I3> extend_interfaces_base;
    00187 #ifndef __GCCXML__
    00189   typedef typename extend_interfaces_base::ext_iids interfaces;
    00190 #endif
    00191
    00192   _helper_common_implementation_(3)
    00193 };
    00194
    00198 template <typename I1, typename I2, typename I3, typename I4>
    00199 struct GAUDI_API implements4: virtual public extend_interfaces4<I1,I2,I3,I4> {
    00201   typedef implements4 base_class;
    00203   typedef extend_interfaces4<I1,I2,I3,I4> extend_interfaces_base;
    00204 #ifndef __GCCXML__
    00206   typedef typename extend_interfaces_base::ext_iids interfaces;
    00207 #endif
    00208
    00209   _helper_common_implementation_(4)
    00210 };
    00211
    00212 // Undefine helper macros
    00213 #undef _refcounting_implementation_
    00214 #undef _helper_common_implementation_
    00215
    00216 #endif /* GAUDIKERNEL_IMPLEMENTS_H_ */