00001 #ifndef DataFormats_Common_DetSet_h 00002 #define DataFormats_Common_DetSet_h 00003 00004 /*---------------------------------------------------------------------- 00005 00006 DetSet: A struct which combines a collection of homogeneous objects 00007 associated with a common DetId with a DetId instance, holding the 00008 common DetId value. The collected objects may or may not contain their 00009 own copy of the common DetId. 00010 00011 $Id: DetSet.h,v 1.13 2010/12/17 14:22:51 innocent Exp $ 00012 00013 ----------------------------------------------------------------------*/ 00014 00015 #include <vector> 00016 #include <stdint.h> 00017 00018 namespace edm { 00019 typedef uint32_t det_id_type; 00020 00021 template <class T> 00022 struct DetSet 00023 { 00024 typedef std::vector<T> collection_type; 00025 // We don't just use T as value-type, in case we switch to a 00026 // fancier underlying container. 00027 typedef typename collection_type::value_type value_type; 00028 typedef typename collection_type::reference reference; 00029 typedef typename collection_type::const_reference const_reference; 00030 typedef typename collection_type::iterator iterator; 00031 typedef typename collection_type::const_iterator const_iterator; 00032 typedef typename collection_type::size_type size_type; 00033 00035 DetSet() : id(0), data() { } 00037 explicit DetSet(det_id_type i) : id(i), data() { } 00038 00039 #if defined( __GXX_EXPERIMENTAL_CXX0X__) 00040 DetSet(DetSet<T> && rh) : id(rh.id), data(std::move(rh.data)){} 00041 00042 DetSet<T> & operator=(DetSet<T> && rh) { 00043 id = rh.id; 00044 data.swap(rh.data); 00045 return * this; 00046 } 00047 #endif 00048 00049 iterator begin() { return data.begin(); } 00050 iterator end() { return data.end(); } 00051 const_iterator begin() const { return data.begin(); } 00052 const_iterator end() const { return data.end(); } 00053 size_type size() const { return data.size(); } 00054 bool empty() const { return data.empty(); } 00055 reference operator[](size_type i) { return data[ i ]; } 00056 const_reference operator[](size_type i) const { return data[ i ]; } 00057 void reserve(size_t s) { data.reserve(s); } 00058 void push_back(const T & t) { data.push_back(t); } 00059 void clear() { data.clear(); } 00060 void swap(DetSet<T> & other); 00061 00062 det_id_type detId() const { return id; } 00063 00064 det_id_type id; 00065 collection_type data; 00066 }; // template struct DetSet 00067 00068 00069 // TODO: If it turns out that it is confusing to have operator< 00070 // defined for DetSet, because this op< ignores the data member 00071 // 'data', we could instead specialize the std::less class template 00072 // directly. 00073 00074 template <class T> 00075 inline 00076 bool 00077 operator< (DetSet<T> const& x, DetSet<T> const& y) { 00078 return x.detId() < y.detId(); 00079 } 00080 00081 template <class T> 00082 inline 00083 bool 00084 operator< (DetSet<T> const& x, det_id_type y) { 00085 return x.detId() < y; 00086 } 00087 00088 template <class T> 00089 inline 00090 bool 00091 operator< (det_id_type x, DetSet<T> const& y) { 00092 return x < y.detId(); 00093 } 00094 00095 template <class T> 00096 inline 00097 void 00098 DetSet<T>::swap(DetSet<T> & other) { 00099 data.swap(other.data); 00100 std::swap(id, other.id); 00101 } 00102 00103 template <class T> 00104 inline 00105 void 00106 swap(DetSet<T> & a, DetSet<T> & b) { 00107 a.swap(b); 00108 } 00109 00110 } // namespace edm; 00111 00112 #endif