CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QueryableVector.h
Go to the documentation of this file.
1 #ifndef INCLUDE_ORA_QUERYABLEVECTOR_H
2 #define INCLUDE_ORA_QUERYABLEVECTOR_H
3 
4 #include "Selection.h"
5 #include "PVector.h"
6 // externals
7 #include <boost/shared_ptr.hpp>
8 
9 namespace ora {
10 
11  class IVectorLoader {
12  public:
13 
14  // destructor
15  virtual ~IVectorLoader(){
16  }
17 
18  public:
19 
20  // triggers the data loading
21  virtual bool load(void* address) const=0;
22 
23  virtual bool loadSelection(const ora::Selection& selection, void* address) const=0;
24 
25  virtual size_t getSelectionCount( const ora::Selection& selection ) const=0;
26 
27  // invalidates the current loader. Called by the underlying service at his destruction time.
28  virtual void invalidate()=0;
29 
30  // queries the validity of the current relation with the underlying storage system
31  virtual bool isValid() const=0;
32 
33  };
34 
35  template <typename Tp> class RangeIterator {
36  public:
37  typedef typename std::vector<std::pair<size_t,Tp> >::const_iterator embedded_iterator;
38 
39  public:
40  RangeIterator( embedded_iterator vectorIterator);
41 
42  RangeIterator( const RangeIterator& rhs );
43 
44  RangeIterator& operator=( const RangeIterator& rhs );
45 
46  virtual ~RangeIterator();
47 
48  bool operator==( const RangeIterator& rhs ) const;
49 
50  bool operator!=( const RangeIterator& rhs ) const;
51 
53 
55 
57 
59 
60  size_t index() const;
61 
62  const Tp* operator->() const;
63  const Tp& operator*() const;
64 
65  private:
67  };
68 
69  template <typename Tp> class RangeReverseIterator {
70  public:
71  typedef typename std::vector<std::pair<size_t,Tp> >::const_reverse_iterator embedded_iterator;
72 
73  public:
74  RangeReverseIterator( embedded_iterator vectorIterator);
75 
77 
79 
80  virtual ~RangeReverseIterator();
81 
82  bool operator==( const RangeReverseIterator& rhs ) const;
83 
84  bool operator!=( const RangeReverseIterator& rhs ) const;
85 
87 
89 
91 
93 
94  size_t index() const;
95 
96  const Tp* operator->() const;
97  const Tp& operator*() const;
98 
99  private:
101  };
102 
103  template <typename Tp> class Range {
104  public:
105  typedef const Tp& reference;
108  typedef std::vector<std::pair<size_t,Tp> > store_base_type;
109 
110  public:
111  Range();
112 
113  explicit Range(boost::shared_ptr<store_base_type>& data);
114 
115  Range(const Range& rhs);
116 
117  virtual ~Range();
118 
119  Range& operator=(const Range& rhs);
120 
121  iterator begin() const;
122 
123  iterator end() const;
124 
125  reverse_iterator rbegin() const;
126 
127  reverse_iterator rend() const;
128 
129  size_t size() const;
130 
131  size_t frontIndex() const;
132 
133  size_t backIndex() const;
134 
135  private:
136 
137  boost::shared_ptr<store_base_type> m_data;
138  };
139 
140  template <typename Tp> class Query {
141  public:
142  explicit Query(boost::shared_ptr<IVectorLoader>& loader);
143 
144  Query(const Query<Tp>& rhs);
145 
146  Query& operator=(const Query<Tp>& rhs);
147 
148  virtual ~Query(){
149  }
150 
151  template <typename Prim> void addSelection(const std::string& dataMemberName, SelectionItemType stype, Prim selectionData);
152 
153  size_t count();
154 
155  Range<Tp> execute();
156 
157  private:
159  boost::shared_ptr<IVectorLoader> m_loader;
160  };
161 
162  template <typename Tp> class QueryableVector {
163 
164  public:
165 
166  // typedefs forwarded to std::vector
171  typedef typename PVector<Tp>::iterator iterator;
175 
176  // ora specific typedef
178  //typedef typename PVector<Tp>::store_type store_type;
179  typedef std::vector<std::pair<size_t,Tp> > range_store_base_type;
180 
181  public:
182  // default constructor
183  QueryableVector();
184 
185  // constructor
186  explicit QueryableVector(size_t n, const Tp& value=Tp());
187 
188  // copy constructor: not sure what to do...
190 
191  // destructor
192  virtual ~QueryableVector();
193 
194  // assignment operator: not sure what to do...
196 
197  public:
198 
199  Range<Tp> select(int startIndex, int endIndex=Selection::endOfRange) const;
200 
201  Range<Tp> select(const Selection& sel) const;
202 
203  Query<Tp> query() const;
204 
205  bool lock();
206 
207  bool isLocked() const;
208 
209  public:
210 
211  iterator begin();
212 
213  iterator end();
214 
215  const_iterator begin() const;
216 
217  const_iterator end() const;
218 
220 
222 
224 
226 
227  size_t size() const;
228 
229  size_t max_size() const;
230 
231  void resize(size_t n, const Tp& value=Tp());
232 
233  size_t capacity() const;
234 
235  bool empty() const;
236 
237  void reserve(size_t n);
238 
239  reference operator[] ( size_t n );
240 
241  const_reference operator[] ( size_t n ) const;
242 
243  reference at( size_t n );
244 
245  const_reference at( size_t n ) const;
246 
247  reference front ( );
248 
249  const_reference front ( ) const;
250 
251  reference back ( );
252 
253  const_reference back ( ) const;
254 
255  void assign ( size_t n, const Tp& u );
256 
257  void push_back ( const Tp& x );
258 
259  void pop_back ();
260 
261  void clear ( );
262 
263  void reset ( );
264 
265  // equals operator
266  bool operator==(const QueryableVector& vec) const;
267 
268  bool operator!=(const QueryableVector& vec) const;
269 
270  public:
271  // access to persistent size
272  size_t persistentSize() const;
273 
274  const void* storageAddress() const;
275 
276  void load() const;
277 
278  private:
279  void initialize() const;
280 
281  private:
282  boost::shared_ptr<store_base_type> m_data;
284  mutable bool m_isLoaded;
285  mutable boost::shared_ptr<IVectorLoader> m_loader;
286 
287 };
288 
289 }
290 
291 #include "QueryableVectorImpl.h"
292 
293 #endif
bool operator!=(const RangeReverseIterator &rhs) const
int i
Definition: DBlmapReader.cc:9
static const int endOfRange
Definition: Selection.h:21
RangeReverseIterator(embedded_iterator vectorIterator)
bool operator!=(const RangeIterator &rhs) const
PVector< Tp > store_base_type
bool operator==(const RangeReverseIterator &rhs) const
size_t persistentSize() const
void addSelection(const std::string &dataMemberName, SelectionItemType stype, Prim selectionData)
std::vector< std::pair< size_t, Tp > >::const_iterator embedded_iterator
std::vector< Tp >::size_type size_type
Definition: PVector.h:23
QueryableVector< Tp > & operator=(const QueryableVector< Tp > &rhs)
const Tp & reference
std::vector< Tp >::reverse_iterator reverse_iterator
Definition: PVector.h:35
bool operator!=(const QueryableVector &vec) const
Range< Tp > select(int startIndex, int endIndex=Selection::endOfRange) const
const void * storageAddress() const
selection
main part
Definition: corrVsCorr.py:98
RangeReverseIterator & operator=(const RangeReverseIterator &rhs)
RangeReverseIterator operator+(int i)
reference operator[](size_t n)
PVector< Tp >::iterator iterator
RangeIterator operator-(int i)
boost::shared_ptr< store_base_type > m_data
void resize(size_t n, const Tp &value=Tp())
std::vector< std::pair< size_t, Tp > > store_base_type
iterator end() const
const Tp * operator->() const
std::vector< Tp >::value_type value_type
Definition: PVector.h:37
const Tp * operator->() const
void assign(size_t n, const Tp &u)
RangeIterator & operator++()
Selection m_selection
virtual bool load(void *address) const =0
boost::shared_ptr< IVectorLoader > m_loader
RangeIterator(embedded_iterator vectorIterator)
std::vector< std::pair< size_t, Tp > >::const_reverse_iterator embedded_iterator
bool operator==(const RangeIterator &rhs) const
reverse_iterator rbegin()
size_t size() const
void push_back(const Tp &x)
virtual bool isValid() const =0
boost::shared_ptr< IVectorLoader > m_loader
virtual ~Query()
RangeReverseIterator< Tp > reverse_iterator
RangeIterator operator+(int i)
Range & operator=(const Range &rhs)
std::vector< std::pair< size_t, Tp > > range_store_base_type
iterator begin() const
PVector< Tp >::const_reference const_reference
virtual ~IVectorLoader()
std::vector< Tp >::iterator iterator
Definition: PVector.h:31
Query & operator=(const Query< Tp > &rhs)
embedded_iterator m_vecIterator
virtual bool loadSelection(const ora::Selection &selection, void *address) const =0
embedded_iterator m_vecIterator
size_t backIndex() const
RangeReverseIterator operator-(int i)
reverse_iterator rend()
std::vector< Tp >::const_reverse_iterator const_reverse_iterator
Definition: PVector.h:33
size_t index() const
virtual size_t getSelectionCount(const ora::Selection &selection) const =0
virtual void invalidate()=0
std::vector< Tp >::const_reference const_reference
Definition: PVector.h:25
reverse_iterator rbegin() const
std::vector< Tp >::const_iterator const_iterator
Definition: PVector.h:29
reverse_iterator rend() const
const Tp & operator*() const
const Tp & operator*() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
PVector< Tp >::size_type size_type
RangeIterator< Tp > iterator
PVector< Tp >::reference reference
std::vector< Tp >::reference reference
Definition: PVector.h:27
bool operator==(const QueryableVector &vec) const
size_t frontIndex() const
PVector< Tp >::const_iterator const_iterator
boost::shared_ptr< store_base_type > m_data
Query(boost::shared_ptr< IVectorLoader > &loader)
Range< Tp > execute()
RangeIterator & operator=(const RangeIterator &rhs)
RangeReverseIterator & operator++()
Query< Tp > query() const
PVector< Tp >::reverse_iterator reverse_iterator
PVector< Tp >::value_type value_type
reference at(size_t n)
PVector< Tp >::const_reverse_iterator const_reverse_iterator
SelectionItemType
Definition: Selection.h:16