ATLAS Offline Software
Loading...
Searching...
No Matches
NavigableVector.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef NAVIGATION_NAVIGABLEVECTOR_H
6#define NAVIGATION_NAVIGABLEVECTOR_H
8// Simple container for navigable objects. //
10
12#include "AthLinks/ElementLink.h"
13
15
16#include <vector>
17
18template < typename CONT, typename OBJCT=typename CONT::base_value_type >
20{
21public:
22
23 // object container index type
26
27 //
29 typedef std::vector<data_type> store_type;
30 typedef typename store_type::iterator store_iter;
31 typedef typename store_type::const_iterator store_const_iter;
33 typedef OBJCT* object_ptr;
34 typedef const OBJCT* object_const_ptr;
35
38
39 virtual ~NavigableVector() = default;
40
41 // add elements
42 void addElement(const CONT* aContainer, const OBJCT* anObject)
43 {
44 data_type aLink;
45 aLink.toContainedElement(*aContainer,(object_ptr)anObject);
46 m_store.push_back(aLink);
47 }
48
49 void addElement(const CONT* aContainer, external_index_type anIndex)
50 {
51 data_type aLink;
52 aLink.toIndexedElement(*aContainer,anIndex);
53 m_store.push_back(aLink);
54 }
55
56 void addElement(const data_type& aLink)
57 {
58 m_store.push_back(aLink);
59 }
60
61 unsigned int size() const { return m_store.size(); }
62
63 // iterator access
65 {
67 }
69 {
70 return const_iterator(m_store).end();
71 }
72 const_iterator find(const OBJCT* anObject) const
73 {
74 return const_iterator(m_store).find(anObject);
75 }
76
77 // operators
78 const OBJCT* operator[](int i) const
79 {
80 return i >= 0 && i < (int)m_store.size()
81 ? *(m_store[i])
82 : 0;
83 }
84 const OBJCT* operator[](size_t i) const
85 {
86 return i < m_store.size()
87 ? *(m_store[i])
88 : 0;
89 }
90
91 // Return contained ElementLink directly.
92 const data_type& linkAt (size_t i) const
93 {
94 if (i < m_store.size())
95 return m_store[i];
96 static const data_type null;
97 return null;
98 }
99
100 void push_back(data_type& theData)
101 {
102 m_store.push_back(theData);
103 }
104
105protected:
106
108};
109#endif
NavigableVectorIterator end()
NavigableVectorIterator begin()
NavigableVectorIterator & find(const object_type *anObject)
NavigableVectorIterator< OBJCT, store_type > const_iterator
virtual ~NavigableVector()=default
const data_type & linkAt(size_t i) const
const OBJCT * operator[](int i) const
store_type::const_iterator store_const_iter
void addElement(const CONT *aContainer, const OBJCT *anObject)
const_iterator find(const OBJCT *anObject) const
store_type::iterator store_iter
const_iterator end() const
void addElement(const data_type &aLink)
const OBJCT * operator[](size_t i) const
const_iterator begin() const
ElementLink< CONT > data_type
unsigned int size() const
const OBJCT * object_const_ptr
void addElement(const CONT *aContainer, external_index_type anIndex)
std::vector< data_type > store_type
SG::GenerateIndexingPolicy< CONT >::type::index_type external_index_type
void push_back(data_type &theData)