00001 #ifndef DataFormats_Common_RefItem_h 00002 #define DataFormats_Common_RefItem_h 00003 00004 /*---------------------------------------------------------------------- 00005 00006 RefItem: Index and pointer to a referenced item. 00007 00008 $Id: RefItem.h,v 1.11 2007/08/20 13:57:12 chrjones Exp $ 00009 00010 ----------------------------------------------------------------------*/ 00011 #include "DataFormats/Common/interface/traits.h" 00012 #include "DataFormats/Common/interface/ConstPtrCache.h" 00013 00014 namespace edm { 00015 00016 template<typename KEY> 00017 class RefItem { 00018 public: 00019 typedef KEY key_type; 00020 00021 RefItem() : index_(key_traits<key_type>::value), cache_(0) {} 00022 00023 RefItem(key_type inx, void const* p) : index_(inx), cache_(p) {} 00024 00025 ~RefItem() {} 00026 00027 key_type key() const {return index_;} 00028 void const *ptr() const {return cache_.ptr_;} 00029 void const *setPtr(void const* p) const {return(cache_.ptr_ = p);} 00030 00031 bool isValid() const { return index_!=edm::key_traits<key_type>::value; } 00032 bool isNonnull() const { return isValid(); } 00033 bool isNull() const { return !isValid(); } 00034 00035 private: 00036 key_type index_; 00037 mutable ConstPtrCache cache_; //Type handles the transient 00038 }; 00039 00040 template<typename KEY> 00041 inline 00042 bool 00043 operator==(RefItem<KEY> const& lhs, RefItem<KEY> const& rhs) { 00044 return lhs.key() == rhs.key(); 00045 } 00046 00047 template<typename KEY> 00048 inline 00049 bool 00050 operator!=(RefItem<KEY> const& lhs, RefItem<KEY> const& rhs) { 00051 return !(lhs == rhs); 00052 } 00053 00054 template<typename KEY> 00055 inline 00056 bool 00057 operator<(RefItem<KEY> const& lhs, RefItem<KEY> const& rhs) { 00058 return lhs.key() < rhs.key(); 00059 } 00060 } 00061 00062 #endif