![]() |
![]() |
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 // user include files 00022 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h" 00023 #include "DataFormats/Common/interface/EDProductGetter.h" 00024 #include "DataFormats/Common/interface/GetProduct.h" 00025 #include "DataFormats/Common/interface/Handle.h" 00026 #include "DataFormats/Common/interface/OrphanHandle.h" 00027 #include "DataFormats/Common/interface/Ptr.h" 00028 #include "DataFormats/Common/interface/RefCore.h" 00029 #include "DataFormats/Common/interface/TestHandle.h" 00030 #include "DataFormats/Common/interface/traits.h" 00031 00032 #include "FWCore/Utilities/interface/EDMException.h" 00033 00034 // system include files 00035 #include "boost/type_traits/is_base_of.hpp" 00036 #include "boost/utility/enable_if.hpp" 00037 00038 // forward declarations 00039 namespace edm { 00040 template<typename T> 00041 class FwdPtr { 00042 friend class FwdPtrVectorBase; 00043 public: 00044 00045 typedef unsigned long key_type; 00046 typedef T value_type; 00047 00048 // General purpose constructor from two Ptrs. 00049 template<typename C> 00050 FwdPtr(Ptr<C> f, Ptr<C> b): 00051 ptr_(f), backPtr_(b) 00052 {} 00053 00054 FwdPtr() : 00055 ptr_(), backPtr_() 00056 {} 00057 00058 FwdPtr(FwdPtr<T> const& iOther) : 00059 ptr_(iOther.ptr_), backPtr_(iOther.backPtr_) 00060 {} 00061 00062 /* template<typename U> */ 00063 /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<T, U>::value>::type * t = 0): */ 00064 /* ptr_(iOther.ptr_, t), backPtr_(iOther.backPtr_,t) */ 00065 /* { */ 00066 /* } */ 00067 00068 /* template<typename U> */ 00069 /* explicit */ 00070 /* FwdPtr(FwdPtr<U> const& iOther, typename boost::enable_if_c<boost::is_base_of<U, T>::value>::type * t = 0): */ 00071 /* ptr_(iOther.ptr_,t), backPtr_(iOther.backPtr_,t){} */ 00072 00073 00075 ~FwdPtr() {} 00076 00078 T const& 00079 operator*() const { return ptr_.isNonnull() ? ptr_.operator*() : backPtr_.operator*();} 00080 00082 T const* 00083 operator->() const{ return ptr_.isNonnull() ? ptr_.operator->() : backPtr_.operator->();} 00084 00086 T const* get() const { return ptr_.isNonnull() ? ptr_.get() : backPtr_.get();} 00087 00088 00090 bool isNull() const {return !isNonnull(); } 00091 00093 //bool isNonnull() const {return id().isValid(); } 00094 bool isNonnull() const {return ptr_.isNonnull() || backPtr_.isNonnull(); } 00096 bool operator!() const {return isNull();} 00097 00100 bool isAvailable() const {return ptr_.isAvailable() || backPtr_.isAvailable();} 00101 00103 bool isTransient() const {return ptr_.isTransient();} 00104 00106 ProductID id() const {return ptr_.isNonnull() ? ptr_.id() : backPtr_.id();} 00107 00109 EDProductGetter const* productGetter() const { 00110 if (ptr_.productGetter()) return ptr_.productGetter(); 00111 else return backPtr_.productGetter(); 00112 } 00113 00114 key_type key() const {return ptr_.isNonnull() ? ptr_.key() : backPtr_.key() ;} 00115 00116 bool hasProductCache() const { return ptr_.hasProductCache() || backPtr_.hasProductCache();} 00117 00118 RefCore const& refCore() const {return ptr_.isNonnull() ? ptr_.refCore() : backPtr_.refCore() ;} 00119 // ---------- member functions --------------------------- 00120 00121 void const* product() const {return 0;} 00122 00123 Ptr<value_type> const& ptr() const { return ptr_;} 00124 Ptr<value_type> const& backPtr() const { return backPtr_;} 00125 00126 //Used by ROOT storage 00127 CMS_CLASS_VERSION(10) 00128 00129 private: 00130 Ptr<value_type> ptr_; 00131 Ptr<value_type> backPtr_; 00132 }; 00133 00134 00135 template<typename T> 00136 inline 00137 bool 00138 operator==(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) { 00139 return (lhs.ptr() == rhs.ptr() || 00140 lhs.backPtr() == rhs.ptr() || 00141 lhs.ptr() == rhs.backPtr() || 00142 lhs.backPtr() == rhs.backPtr()); 00143 } 00144 00145 template<typename T> 00146 inline 00147 bool 00148 operator!=(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) { 00149 return !(lhs == rhs); 00150 } 00151 00152 template<typename T> 00153 inline 00154 bool 00155 operator<(FwdPtr<T> const& lhs, FwdPtr<T> const& rhs) { 00158 return (lhs.ptr() < rhs.ptr()); 00159 } 00160 00161 } 00162 #endif