![]() |
![]() |
00001 #ifndef DataFormats_Common_FwdPtr_h 00002 #define DataFormats_Common_FwdPtr_h 00003 // -*- C++ -*- 00004 // 00005 // Package: Common 00006 // Class : FwdPtr 00007 // 00016 // 00017 // Original Author: Salvatore Rappoccio 00018 // Created: Fri Feb 5 14:58:49 CST 2010 00019 // 00020 00021 // system include files 00022 #include "boost/type_traits/is_base_of.hpp" 00023 #include "boost/utility/enable_if.hpp" 00024 00025 // user include files 00026 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h" 00027 #include "DataFormats/Common/interface/RefCore.h" 00028 #include "DataFormats/Common/interface/Ptr.h" 00029 #include "DataFormats/Common/interface/traits.h" 00030 #include "DataFormats/Common/interface/GetProduct.h" 00031 #include "DataFormats/Common/interface/EDProduct.h" 00032 #include "DataFormats/Common/interface/EDProductGetter.h" 00033 #include "DataFormats/Common/interface/Handle.h" 00034 #include "DataFormats/Common/interface/OrphanHandle.h" 00035 #include "DataFormats/Common/interface/TestHandle.h" 00036 00037 #include "FWCore/Utilities/interface/EDMException.h" 00038 00039 // forward declarations 00040 namespace edm { 00041 template <typename T> 00042 class FwdPtr { 00043 friend class FwdPtrVectorBase; 00044 public: 00045 00046 typedef unsigned long key_type; 00047 typedef T value_type; 00048 00049 // General purpose constructor from two Ptrs. 00050 template <typename C> 00051 FwdPtr( Ptr<C> f, Ptr<C> b): 00052 ptr_(f), backPtr_(b) 00053 {} 00054 00055 FwdPtr(): 00056 ptr_(), backPtr_() 00057 {} 00058 00059 FwdPtr(FwdPtr<T> const& iOther): 00060 ptr_(iOther.ptr_), backPtr_(iOther.backPtr_) 00061 {} 00062 00063 /* template<typename U> */ 00064 /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<T, U>::value>::type * t = 0): */ 00065 /* ptr_(iOther.ptr_, t), backPtr_(iOther.backPtr_,t) */ 00066 /* { */ 00067 /* } */ 00068 00069 /* template<typename U> */ 00070 /* explicit */ 00071 /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<U, T>::value>::type * t = 0): */ 00072 /* ptr_(iOther.ptr_,t), backPtr_(iOther.backPtr_,t){} */ 00073 00074 00076 ~FwdPtr() {} 00077 00079 T const& 00080 operator*() const { return ptr_.isNonnull() ? ptr_.operator*() : backPtr_.operator*();} 00081 00083 T const* 00084 operator->() const{ return ptr_.isNonnull() ? ptr_.operator->() : backPtr_.operator->();} 00085 00087 T const* get() const { return ptr_.isNonnull() ? ptr_.get() : backPtr_.get();} 00088 00089 00091 bool isNull() const {return !isNonnull(); } 00092 00094 //bool isNonnull() const {return id().isValid(); } 00095 bool isNonnull() const {return ptr_.isNonnull() || backPtr_.isNonnull(); } 00097 bool operator!() const {return isNull();} 00098 00101 bool isAvailable() const {return ptr_.isAvailable() || backPtr_.isAvailable();} 00102 00104 bool isTransient() const {return ptr_.isTransient();} 00105 00107 ProductID id() const {return ptr_.isNonnull() ? ptr_.id() : backPtr_.id();} 00108 00110 EDProductGetter const* productGetter() const { 00111 if ( ptr_.productGetter() ) return ptr_.productGetter(); 00112 else return backPtr_.productGetter(); 00113 } 00114 00115 key_type key() const {return ptr_.isNonnull() ? ptr_.key() : backPtr_.key() ;} 00116 00117 bool hasProductCache() const { return ptr_.hasProductCache() || backPtr_.hasProductCache();} 00118 00119 RefCore const& refCore() const {return ptr_.isNonnull() ? ptr_.refCore() : backPtr_.refCore() ;} 00120 // ---------- member functions --------------------------- 00121 00122 void const* product() const {return 0;} 00123 00124 Ptr<value_type> const & ptr() const { return ptr_;} 00125 Ptr<value_type> const & backPtr() const { return backPtr_;} 00126 00127 //Used by ROOT storage 00128 CMS_CLASS_VERSION(10) 00129 00130 private: 00131 Ptr<value_type> ptr_; 00132 Ptr<value_type> backPtr_; 00133 }; 00134 00135 00136 template <typename T> 00137 inline 00138 bool 00139 operator==(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) { 00140 return ( lhs.ptr() == rhs.ptr() || 00141 lhs.backPtr() == rhs.ptr() || 00142 lhs.ptr() == rhs.backPtr() || 00143 lhs.backPtr() == rhs.backPtr() ); 00144 } 00145 00146 template <typename T> 00147 inline 00148 bool 00149 operator!=(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) { 00150 return !(lhs == rhs); 00151 } 00152 00153 template <typename T> 00154 inline 00155 bool 00156 operator<(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) { 00159 return ( lhs.ptr() < rhs.ptr() ); 00160 } 00161 00162 } 00163 00164 #endif