CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QueryableVectorImpl.h
Go to the documentation of this file.
1 #ifndef INCLUDE_ORA_QUERYABLEVECTORIMPL_H
2 #define INCLUDE_ORA_QUERYABLEVECTORIMPL_H
3 
5 
6 template <class Tp> ora::RangeIterator<Tp>::RangeIterator( RangeIterator<Tp>::embedded_iterator vectorIterator):m_vecIterator(vectorIterator){
7 }
8 
9 template <class Tp> ora::RangeIterator<Tp>::RangeIterator( const ora::RangeIterator<Tp>& rhs ):m_vecIterator(rhs.m_vecIterator){
10 }
11 
13  m_vecIterator = rhs.m_vecIterator;
14 }
15 
17 }
18 
19 template <class Tp> bool ora::RangeIterator<Tp>::operator==( const ora::RangeIterator<Tp>& rhs ) const{
20  return m_vecIterator == rhs.m_vecIterator;
21 }
22 
23 template <class Tp> bool ora::RangeIterator<Tp>::operator!=( const ora::RangeIterator<Tp>& rhs ) const {
24  return m_vecIterator != rhs.m_vecIterator;
25 }
26 
28  ++m_vecIterator;
29  return *this;
30 }
31 
33  this->operator++();
34  return *this;
35 }
36 
38  return RangeIterator(this->operator+(i));
39 }
40 
42  return RangeIterator(this->operator-(i));
43 }
44 
45 template <class Tp> size_t ora::RangeIterator<Tp>::index() const {
46  return m_vecIterator->first;
47 }
48 
49 template <class Tp> const Tp* ora::RangeIterator<Tp>::operator->() const {
50  return &m_vecIterator->second;
51 }
52 
53 template <class Tp> const Tp& ora::RangeIterator<Tp>::operator*() const {
54  return m_vecIterator->second;
55 }
56 
57 template <class Tp> ora::RangeReverseIterator<Tp>::RangeReverseIterator( ora::RangeReverseIterator<Tp>::embedded_iterator vectorIterator):m_vecIterator(vectorIterator){
58 }
59 
60 template <class Tp> ora::RangeReverseIterator<Tp>::RangeReverseIterator( const ora::RangeReverseIterator<Tp>& rhs ):m_vecIterator(rhs.m_vecIterator){
61 }
62 
64  m_vecIterator = rhs.m_vecIterator;
65 }
66 
68 }
69 
70 template <class Tp> bool ora::RangeReverseIterator<Tp>::operator==( const ora::RangeReverseIterator<Tp>& rhs ) const{
71  return m_vecIterator == rhs.m_vecIterator;
72 }
73 
74 template <class Tp> bool ora::RangeReverseIterator<Tp>::operator!=( const ora::RangeReverseIterator<Tp>& rhs ) const {
75  return m_vecIterator != rhs.m_vecIterator;
76 }
77 
79  ++m_vecIterator;
80  return *this;
81 }
82 
84  this->operator++();
85  return *this;
86 }
87 
89  return RangeReverseIterator(this->operator+(i));
90 }
91 
93  return RangeReverseIterator(this->operator-(i));
94 }
95 
96 template <class Tp> size_t ora::RangeReverseIterator<Tp>::index() const {
97  return m_vecIterator->first;
98 }
99 
100 template <class Tp> const Tp* ora::RangeReverseIterator<Tp>::operator->() const {
101  return &m_vecIterator->second;
102 }
103 
104 template <class Tp> const Tp& ora::RangeReverseIterator<Tp>::operator*() const {
105  return m_vecIterator->second;
106 }
107 
108 template <class Tp> ora::Range<Tp>::Range():m_data(new store_base_type ){
109 }
110 
111 template <class Tp> ora::Range<Tp>::Range(boost::shared_ptr<store_base_type>& data):m_data(data){
112 }
113 
114 template <class Tp> ora::Range<Tp>::Range(const ora::Range<Tp>& rhs):m_data(rhs.m_data){
115 }
116 
117 template <class Tp> ora::Range<Tp>::~Range(){
118 }
119 
120 template <class Tp> ora::Range<Tp>& ora::Range<Tp>::operator=(const ora::Range<Tp>& rhs){
121  if(&rhs != this){
122  m_data = rhs.m_data;
123  }
124  return *this;
125 }
126 
127 template <class Tp> typename ora::Range<Tp>::iterator ora::Range<Tp>::begin() const {
128  return RangeIterator<Tp>(m_data->begin());
129 }
130 
131 template <class Tp> typename ora::Range<Tp>::iterator ora::Range<Tp>::end() const {
132  return RangeIterator<Tp>(m_data->end());
133 }
134 
135 template <class Tp> typename ora::Range<Tp>::reverse_iterator ora::Range<Tp>::rbegin() const {
136  return RangeReverseIterator<Tp>(m_data->rbegin());
137 }
138 
139 template <class Tp> typename ora::Range<Tp>::reverse_iterator ora::Range<Tp>::rend() const {
140  return RangeReverseIterator<Tp>(m_data->rend());
141 }
142 
143 template <class Tp> size_t ora::Range<Tp>::size() const {
144  return m_data->size();
145 }
146 
147 template <class Tp> size_t ora::Range<Tp>::frontIndex() const {
148  return m_data->front().first;
149 }
150 
151 template <class Tp> size_t ora::Range<Tp>::backIndex() const {
152  return m_data->back().first;
153 }
154 
155 
156 template <class Tp>
157 ora::Query<Tp>::Query(boost::shared_ptr<ora::IVectorLoader>& loader):
158  m_selection(),
159  m_loader(loader){
160 }
161 
162 template <class Tp>
164  m_selection( rhs.m_selection),
165  m_loader( rhs.m_loader ){
166 }
167 
168 template <class Tp>
170  m_selection = rhs.m_selection;
171  m_loader = rhs.m_loader;
172  return *this;
173 }
174 
175 template <class Tp>
176 template <typename Prim> void ora::Query<Tp>::addSelection(const std::string& dataMemberName, ora::SelectionItemType stype, Prim selectionData){
177  m_selection.addDataItem(dataMemberName, stype, selectionData);
178 }
179 
180 template <class Tp> size_t ora::Query<Tp>::count(){
181  return m_loader->getSelectionCount( m_selection );
182 }
183 
185  typedef typename Range<Tp>::store_base_type range_store_base_type;
186  boost::shared_ptr<range_store_base_type> newData ( new range_store_base_type );
187  m_loader->loadSelection( m_selection, newData.get());
188  return Range<Tp>( newData );
189 }
190 
192  m_data(new PVector<Tp>),
193  m_isLocked(false),
194  m_isLoaded(false),
195  m_loader(){
196 }
197 
198 template <class Tp> ora::QueryableVector<Tp>::QueryableVector(size_t n, const Tp& value):
199  m_data(new PVector<Tp>(n,value)),
200  m_isLocked(false),
201  m_isLoaded(false),
202  m_loader(){
203 }
204 
206  m_data(rhs.m_data),
207  m_isLocked(rhs.m_isLocked),
208  m_isLoaded(rhs.m_isLoaded),
209  m_loader( rhs.m_loader ){
210 }
211 
213 }
214 
216  if(&rhs != this){
217  m_data = rhs.m_data;
218  m_isLocked = rhs.m_isLocked;
219  m_isLoaded = rhs.m_isLoaded;
220  m_loader = rhs.m_loader;
221  }
222  return *this;
223 }
224 
225 template <class Tp> ora::Range<Tp> ora::QueryableVector<Tp>::select(int startIndex, int endIndex) const {
226  Selection sel;
227  sel.addIndexItem( startIndex, endIndex );
228  return select( sel );
229 }
230 
232  if(m_isLocked ){
233  throwException("The Vector is locked in writing mode, cannot make queries.","ora::QueryableVector<Tp>::select");
234  }
235  if(!m_loader.get()){
236  throwException("The Loader is not installed.","ora::QueryableVector<Tp>::select");
237  }
239  boost::shared_ptr<range_store_base_type> newData ( new range_store_base_type );
240  m_loader->loadSelection( sel, newData.get());
241  return Range<Tp>(newData);
242 }
243 
245  if(m_isLocked ){
246  throwException("The Vector is locked in writing mode, cannot make queries.","ora::QueryableVector<Tp>::query");
247  }
248  if(!m_loader.get()){
249  throwException("The Loader is not installed.","ora::QueryableVector<Tp>::query");
250  }
251  return Query<Tp>(m_loader);
252 }
253 
254 template <class Tp> bool ora::QueryableVector<Tp>::lock() {
255  bool wasLocked = m_isLocked;
256  m_isLocked = true;
257  return wasLocked;
258 }
259 
260 template <class Tp> bool ora::QueryableVector<Tp>::isLocked() const {
261  return m_isLocked;
262 }
263 
265  initialize();
266  return m_data->begin();
267 }
268 
270  initialize();
271  return m_data->end();
272 }
273 
275  initialize();
276  return m_data->begin();
277 }
278 
280  initialize();
281  return m_data->end();
282 }
283 
285  initialize();
286  return m_data->rbegin();
287 }
288 
290  initialize();
291  return m_data->rend();
292 }
293 
295  initialize();
296  return m_data->rbegin();
297 }
298 
300  initialize();
301  return m_data->rend();
302 }
303 
304 template <class Tp> size_t ora::QueryableVector<Tp>::size() const {
305  initialize();
306  return m_data->size();
307 }
308 
309 template <class Tp> size_t ora::QueryableVector<Tp>::max_size() const {
310  initialize();
311  return m_data->max_size();
312 }
313 
314 template <class Tp> void ora::QueryableVector<Tp>::resize(size_t n, const Tp& value){
315  initialize();
316  m_data->resize(n,value);
317 }
318 
319 template <class Tp> size_t ora::QueryableVector<Tp>::capacity() const {
320  initialize();
321  return m_data->capacity();
322 }
323 
324 template <class Tp> bool ora::QueryableVector<Tp>::empty() const {
325  initialize();
326  return m_data->empty();
327 }
328 
329 template <class Tp> void ora::QueryableVector<Tp>::reserve(size_t n) {
330  initialize();
331  m_data->reserve(n);
332 }
333 
335  initialize();
336  return m_data->operator[](n);
337 }
338 
340  initialize();
341  return m_data->operator[](n);
342 }
343 
344 template <class Tp> typename ora::QueryableVector<Tp>::const_reference ora::QueryableVector<Tp>::at( size_t n ) const {
345  initialize();
346  return m_data->operator[](n);
347 }
348 
350  initialize();
351  return m_data->operator[](n);
352 }
353 
355  initialize();
356  return m_data->front();
357 }
358 
360  initialize();
361  return m_data->front();
362 }
363 
365  return m_data->back();
366 }
367 
369  initialize();
370  return m_data->back();
371 }
372 
373 template <class Tp> void ora::QueryableVector<Tp>::assign ( size_t n, const Tp& u ) {
374  initialize();
375  m_data->assign(n,u);
376 }
377 
378 template <class Tp> void ora::QueryableVector<Tp>::push_back ( const Tp& x ){
379  initialize();
380  m_isLocked = true;
381  m_data->push_back(x);
382 }
383 
384 template <class Tp> void ora::QueryableVector<Tp>::pop_back (){
385  initialize();
386  m_isLocked = true;
387  m_data->pop_back();
388 }
389 
390 template <class Tp> void ora::QueryableVector<Tp>::clear ( ){
391  initialize();
392  m_data->clear();
393  m_isLoaded = false;
394 }
395 
396 template <class Tp> void ora::QueryableVector<Tp>::reset ( ){
397  initialize();
398  m_data->clear();
399  m_isLoaded = false;
400  m_isLocked = false;
401 }
402 
403 template <class Tp> bool ora::QueryableVector<Tp>::operator==(const ora::QueryableVector<Tp>& vec) const {
404  initialize();
405  vec.initialize();
406  return m_data->operator==(*vec.m_data);
407 }
408 
409 template <class Tp> bool ora::QueryableVector<Tp>::operator!=(const ora::QueryableVector<Tp>& vec) const {
410  initialize();
411  vec.initialize();
412  return m_data->operator!=(*vec.m_data);
413 }
414 
415 template <class Tp> size_t ora::QueryableVector<Tp>::persistentSize() const {
416  // not sure needs init...
417  //initialize();
418  return m_data->persistentSize();
419 }
420 
421 template <class Tp> const void* ora::QueryableVector<Tp>::storageAddress() const {
422  return m_data.get();
423 }
424 
425 template <class Tp> void ora::QueryableVector<Tp>::load() const {
426  initialize();
427 }
428 
429 template <class Tp> void ora::QueryableVector<Tp>::initialize() const {
430  if(m_loader.get() && !m_isLocked && !m_isLoaded){
431  m_loader->load(m_data.get());
432  m_isLoaded = true;
433  }
434 }
435 
436 #endif //
bool operator!=(const RangeReverseIterator &rhs) const
static AlgebraicMatrix initialize()
int i
Definition: DBlmapReader.cc:9
RangeReverseIterator(embedded_iterator vectorIterator)
bool operator!=(const RangeIterator &rhs) const
bool operator==(const RangeReverseIterator &rhs) const
size_t persistentSize() const
void addSelection(const std::string &dataMemberName, SelectionItemType stype, Prim selectionData)
QueryableVector< Tp > & operator=(const QueryableVector< Tp > &rhs)
bool operator!=(const QueryableVector &vec) const
Range< Tp > select(int startIndex, int endIndex=Selection::endOfRange) const
const void * storageAddress() const
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
const Tp * operator->() const
void assign(size_t n, const Tp &u)
RangeIterator & operator++()
Selection m_selection
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)
boost::shared_ptr< IVectorLoader > m_loader
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
void addIndexItem(int startIndex, int endIndex=endOfRange)
Definition: Selection.cc:62
Query & operator=(const Query< Tp > &rhs)
embedded_iterator m_vecIterator
embedded_iterator m_vecIterator
size_t backIndex() const
RangeReverseIterator operator-(int i)
reverse_iterator rend()
size_t index() const
reverse_iterator rbegin() const
reverse_iterator rend() const
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
const Tp & operator*() const
const Tp & operator*() const
PVector< Tp >::reference reference
bool operator==(const QueryableVector &vec) const
size_t frontIndex() const
PVector< Tp >::const_iterator const_iterator
volatile std::atomic< bool > shutdown_flag false
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
reference at(size_t n)
PVector< Tp >::const_reverse_iterator const_reverse_iterator
SelectionItemType
Definition: Selection.h:16