CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefVectorHolderBase.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefVectorHolderBase_h
2 #define DataFormats_Common_RefVectorHolderBase_h
5 #include "boost/shared_ptr.hpp"
6 
7 namespace edm {
8  template <typename T> class RefToBase;
9  namespace reftobase {
11  public:
12  virtual ~RefVectorHolderBase() {}
13  typedef size_t size_type;
15  void swap(RefVectorHolderBase& other) {} // nothing to swap
16  virtual bool empty() const = 0;
17  virtual size_type size() const = 0;
18  virtual void clear() = 0;
19  virtual void reserve( size_type n ) = 0;
20  virtual ProductID id() const = 0;
21  virtual EDProductGetter const* productGetter() const = 0;
22  virtual RefVectorHolderBase * clone() const = 0;
23  virtual RefVectorHolderBase * cloneEmpty() const = 0;
24  virtual void push_back( const RefHolderBase * r ) = 0;
25  // the following structure is public
26  // to allow reflex dictionary to compile
27  // protected:
29  typedef ptrdiff_t difference_type;
31  virtual ~const_iterator_imp() { }
32  virtual const_iterator_imp * clone() const = 0;
33  virtual void increase() = 0;
34  virtual void decrease() = 0;
35  virtual void increase( difference_type d ) = 0;
36  virtual void decrease( difference_type d ) = 0;
37  virtual bool equal_to( const const_iterator_imp * ) const = 0;
38  virtual bool less_than( const const_iterator_imp * ) const = 0;
39  virtual void assign( const const_iterator_imp * ) = 0;
40  virtual boost::shared_ptr<RefHolderBase> deref() const = 0;
41  virtual difference_type difference( const const_iterator_imp * ) const = 0;
42  };
43 
44  struct const_iterator : public std::iterator <std::random_access_iterator_tag, void *>{
45  typedef boost::shared_ptr<RefHolderBase> value_type;
46  typedef std::ptrdiff_t difference_type;
47  const_iterator() : i( 0 ) { }
48  const_iterator( const_iterator_imp * it ) : i( it ) { }
49  const_iterator( const const_iterator & it ) : i( it.isValid() ? it.i->clone() : 0 ) { }
50  ~const_iterator() { delete i; }
52  if ( isInvalid() ) i = it.i;
53  else i->assign( it.i );
54  return *this;
55  }
57  if ( isInvalid() )
59  "Trying to increment an inavlid RefToBaseVector<T>::const_iterator\n");
60  i->increase();
61  return *this;
62  }
64  if ( isInvalid() )
66  "Trying to postincrement an inavlid RefToBaseVector<T>::const_iterator\n");
67  const_iterator ci = *this;
68  i->increase();
69  return ci;
70  }
72  if ( isInvalid() )
74  "Trying to decrement an inavlid RefToBaseVector<T>::const_iterator\n");
75  i->decrease();
76  return *this;
77  }
79  if ( isInvalid() )
81  "Trying to postdecrement an inavlid RefToBaseVector<T>::const_iterator\n");
82  const_iterator ci = *this;
83  i->decrease();
84  return ci;
85  }
87  if ( isInvalid() && o.isInvalid() ) return 0;
88  if ( isInvalid() || o.isInvalid() )
90  "Trying to compute difference with an inavlid RefToBaseVector<T>::const_iterator\n");
91  return i->difference( o.i );
92  }
94  if ( isInvalid() )
96  "Trying to compute sum with an inavlid RefToBaseVector<T>::const_iterator\n");
97  const_iterator_imp * ii = i->clone();
98  ii->increase( n );
99  return const_iterator( ii );
100  }
102  if ( isInvalid() )
104  "Trying to compute difference with an inavlid RefToBaseVector<T>::const_iterator\n");
105  const_iterator_imp * ii = i->clone();
106  ii->decrease( n );
107  return const_iterator( ii );
108  }
109  bool operator<( const const_iterator & o ) const {
110  if ( isInvalid() && o.isInvalid() ) return false;
111  if ( isInvalid() || o.isInvalid() )
113  "Trying to compute < operator with an inavlid RefToBaseVector<T>::const_iterator\n");
114  return i->less_than( o.i );
115  }
116  bool operator==( const const_iterator& ci ) const {
117  if ( isInvalid() && ci.isInvalid() ) return true;
118  if ( isInvalid() || ci.isInvalid() ) return false;
119  return i->equal_to( ci.i );
120  }
121  bool operator!=( const const_iterator& ci ) const {
122  if ( isInvalid() && ci.isInvalid() ) return false;
123  if ( isInvalid() || ci.isInvalid() ) return true;
124  return ! i->equal_to( ci.i );
125  }
127  if ( isInvalid() )
129  "Trying to dereference an inavlid RefToBaseVector<T>::const_iterator\n");
130  return i->deref();
131  }
133  if ( isInvalid() )
135  "Trying to decrement an inavlid RefToBaseVector<T>::const_iterator\n");
136  i->decrease( d );
137  return *this;
138  }
140  if ( isInvalid() )
142  "Trying to increment an inavlid RefToBaseVector<T>::const_iterator\n");
143  i->increase( d );
144  return *this;
145  }
146  bool isValid() const { return i != 0; }
147  bool isInvalid() const { return i == 0; }
148 
149  private:
151  };
152 
153  virtual const_iterator begin() const = 0;
154  virtual const_iterator end() const = 0;
155  template <class T> RefToBase<T> getRef( size_t idx ) const;
156  virtual const void * product() const = 0;
157  virtual void reallyFillView( const void *, const ProductID &, std::vector<void const*> & ) = 0;
158  virtual size_t keyForIndex(size_t idx) const = 0;
159 
162  virtual bool isAvailable() const = 0;
163 
164  private:
165  virtual boost::shared_ptr<reftobase::RefHolderBase> refBase(size_t idx) const = 0;
166  };
167 
168  template <class T>
170  boost::shared_ptr<reftobase::RefHolderBase> rb = refBase(idx);
171  return RefToBase<T>( rb );
172  }
173 
174  // Free swap function
175  inline
177  lhs.swap(rhs);
178  }
179 
180  }
181 }
182 
183 #endif
bool operator==(const const_iterator &ci) const
virtual difference_type difference(const const_iterator_imp *) const =0
const_iterator & operator=(const const_iterator &it)
virtual void reallyFillView(const void *, const ProductID &, std::vector< void const * > &)=0
virtual const_iterator_imp * clone() const =0
bool operator<(const const_iterator &o) const
virtual RefVectorHolderBase * clone() const =0
const_iterator operator-(difference_type n) const
virtual bool empty() const =0
virtual RefVectorHolderBase * cloneEmpty() const =0
bool operator!=(const const_iterator &ci) const
virtual boost::shared_ptr< RefHolderBase > deref() const =0
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:81
virtual size_t keyForIndex(size_t idx) const =0
virtual size_type size() const =0
virtual void assign(const const_iterator_imp *)=0
virtual EDProductGetter const * productGetter() const =0
virtual bool equal_to(const const_iterator_imp *) const =0
difference_type operator-(const const_iterator &o) const
void swap(RefVectorHolderBase &other)
virtual const void * product() const =0
const_iterator operator+(difference_type n) const
virtual const_iterator begin() const =0
virtual void push_back(const RefHolderBase *r)=0
virtual void reserve(size_type n)=0
virtual const_iterator end() const =0
virtual ProductID id() const =0
virtual bool isAvailable() const =0
RefToBase< T > getRef(size_t idx) const
virtual bool less_than(const const_iterator_imp *) const =0
virtual boost::shared_ptr< reftobase::RefHolderBase > refBase(size_t idx) const =0
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:119