CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefVectorBase.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefVectorBase_h
2 #define DataFormats_Common_RefVectorBase_h
3 
4 /*----------------------------------------------------------------------
5 
6 RefVectorBase: Base class for a vector of interproduct references.
7 
8 
9 ----------------------------------------------------------------------*/
10 
14 #include <vector>
16 
17 namespace edm {
18 
19  class EDProductGetter;
20  template <typename KEY>
21  class RefVectorBase {
22  public:
23  typedef std::vector<KEY > keys_type;
24  typedef KEY key_type;
25  typedef typename keys_type::size_type size_type;
28  RefVectorBase( RefVectorBase const & rhs) : product_(rhs.product_), keys_(rhs.keys_) {}
29 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
30  RefVectorBase( RefVectorBase && rhs) noexcept : product_(std::move(rhs.product_)), keys_(std::move(rhs.keys_)) {}
31 #endif
32 
33  explicit RefVectorBase(ProductID const& productID, void const* prodPtr = 0,
34  EDProductGetter const* prodGetter = 0) :
35  product_(productID, prodPtr, prodGetter, false), keys_() {}
36 
39 
41  RefCore const& refCore() const {return product_;}
42 
44  keys_type const& keys() const {return keys_;}
45 
47  bool empty() const {return keys_.empty();}
48 
50  size_type size() const {return keys_.size();}
51 
52  void pushBack(RefCore const& product, KEY const& key) {
53  product_.pushBackItem(product, true);
54  keys_.push_back(key);
55  }
56 
58  size_type capacity() const {return keys_.capacity();}
59 
61  void reserve(size_type n) {keys_.reserve(n);}
62 
64  typename keys_type::iterator eraseAtIndex(size_type index) {
65  return keys_.erase(keys_.begin() + index);
66  }
67 
69  void clear() {
70  keys_.clear();
71  product_ = RefCore();
72  }
73 
76  product_.swap(other.product_);
77  keys_.swap(other.keys_);
78  }
79 
82  RefVectorBase temp(rhs);
83  this->swap(temp);
84  return *this;
85  }
86 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
88  product_ = std::move(rhs.product_);
89  keys_ =std::move(rhs.keys_);
90  return *this;
91  }
92 #endif
93 
94  //Needed for ROOT storage
96 
97  private:
100  };
101 
103  template<typename KEY>
104  bool
105  operator==(RefVectorBase<KEY> const& lhs, RefVectorBase<KEY> const& rhs) {
106  return lhs.refCore() == rhs.refCore() && lhs.keys() == rhs.keys();
107  }
108 
110  template<typename KEY>
111  bool
113  return !(lhs == rhs);
114  }
115 
117  template<typename KEY>
118  inline
119  void
121  a.swap(b);
122  }
123 
124 }
125 #endif
void pushBackItem(RefCore const &productToBeInserted, bool checkPointer)
Definition: RefCore.cc:133
void swap(RefCore &)
Definition: RefCore.h:116
RefVectorBase & operator=(RefVectorBase const &rhs)
Copy assignment.
Definition: RefVectorBase.h:81
RefVectorBase(RefVectorBase const &rhs)
Definition: RefVectorBase.h:28
bool empty() const
Is vector empty?
Definition: RefVectorBase.h:47
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
keys_type::iterator eraseAtIndex(size_type index)
erase an element from the vector
Definition: RefVectorBase.h:64
#define CMS_CLASS_VERSION(_version_)
uint16_t size_type
void pushBack(RefCore const &product, KEY const &key)
Definition: RefVectorBase.h:52
RefVectorBase()
Default constructor needed for reading from persistent store. Not for direct use. ...
Definition: RefVectorBase.h:27
size_type capacity() const
Capacity of vector.
Definition: RefVectorBase.h:58
RefCore const & refCore() const
Accessor for product ID and product getter.
Definition: RefVectorBase.h:41
void clear()
clear the vector
Definition: RefVectorBase.h:69
keys_type const & keys() const
Accessor for vector of keys and pointers.
Definition: RefVectorBase.h:44
#define noexcept
RefVectorBase(ProductID const &productID, void const *prodPtr=0, EDProductGetter const *prodGetter=0)
Definition: RefVectorBase.h:33
double b
Definition: hdecay.h:120
string const
Definition: compareJSON.py:14
#define private
Definition: FWFileEntry.h:17
~RefVectorBase() noexcept
Destructor.
Definition: RefVectorBase.h:38
list key
Definition: combine.py:13
double a
Definition: hdecay.h:121
keys_type::size_type size_type
Definition: RefVectorBase.h:25
volatile std::atomic< bool > shutdown_flag false
size_type size() const
Size of vector.
Definition: RefVectorBase.h:50
std::vector< KEY > keys_type
Definition: RefVectorBase.h:23
def template
Definition: svgfig.py:520
void reserve(size_type n)
Reserve space for vector.
Definition: RefVectorBase.h:61
void swap(RefVectorBase< KEY > &other) noexcept
swap two vectors
Definition: RefVectorBase.h:75