ATLAS Offline Software
TokenList.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef COLLECTIONBASE_TOKENLIST_H
6 #define COLLECTIONBASE_TOKENLIST_H
7 
8 #include <string>
9 #include <vector>
10 #include <map>
11 #include <iosfwd>
12 
13 
14 class Token;
15 
16 namespace pool {
17 
23  class TokenList
24  {
25  public:
28 
34  TokenList( const std::vector<std::string>& specification );
35 
41  TokenList( const TokenList& rhs );
42 
45 
51  TokenList& operator=( const TokenList& rhs );
52 
58  bool operator==( const TokenList& rhs ) const;
59 
65  bool operator!=( const TokenList& rhs ) const;
66 
72  void extend( const std::string& name );
73 
74 
76  size_t size() const;
77 
79  void clear();
80 
86  Token& operator[]( const std::string& name );
87 
93  const Token& operator[]( const std::string& name ) const;
94 
100  Token& operator[]( unsigned int index );
101 
107  const Token& operator[]( unsigned int index ) const;
108 
114  std::ostream& toOutputStream( std::ostream& os ) const;
115 
118  {
119  public:
120  bool operator==( const iterator_base& rhs ) const {
121  return m_list == rhs.m_list && m_index == rhs.m_index;
122  }
123  bool operator!=( const iterator_base& rhs ) const { return !(*this==rhs); }
124  void operator++() { ++m_index; }
125  bool next() { return ++m_index < m_list->size(); }
126  const std::string& tokenName() const { return m_list->m_tokenNames[ m_index ]; }
127  protected:
128  iterator_base( const TokenList* list, size_t idx = 0 )
129  : m_list( list ), m_index( idx ) {}
130  // default copy ctor and assignment.
131  virtual ~iterator_base() {}
132 
134  size_t m_index;
135  };
136 
138  class iterator : public iterator_base
139  {
140  public:
141  friend class TokenList;
142  ~iterator() {};
143  iterator( const iterator_base& rhs ) : iterator_base( rhs ) {}
144  iterator& operator=( const iterator_base& rhs ) {
145  iterator_base::operator=( rhs );
146  return *this;
147  }
148  private:
149  iterator( TokenList* list, size_t idx = 0 ) : iterator_base( list, idx ) {}
150  public:
152  Token& operator*() { return *operator->(); }
154  };
155 
157  iterator begin();
158 
160  iterator end();
161 
164  {
165  public:
166  friend class TokenList;
168  const_iterator( const iterator_base& rhs ): iterator_base( rhs ) {}
170  iterator_base::operator=( rhs );
171  return *this;
172  }
173  private:
174  const_iterator( const TokenList* list, size_t idx = 0 ) : iterator_base( list, idx ) {}
175  public:
176  const Token* operator->() const { return m_list->m_tokenVector[ m_index ]; }
177  const Token& operator*() const { return *operator->(); }
179  };
180 
182  const_iterator begin() const;
183 
185  const_iterator end() const;
186 
187  protected:
188  // implementation of the constructor
189  void createFromSpec( const std::vector<std::string>& specification );
190 
191  private:
193  std::vector< std::string > m_tokenNames;
194 
196  std::vector< Token* > m_tokenVector;
197 
199  std::map< std::string, Token* > m_tokenMap;
200  };
201 }
202 
203 
204 // Inline methods.
205 inline size_t
207 {
208  return m_tokenVector.size();
209 }
210 
211 inline bool
213 {
214  return !( *this == rhs );
215 }
216 
219 {
220  return pool::TokenList::iterator( this );
221 }
222 
225 {
226  return pool::TokenList::iterator( this, size() );
227 }
228 
231 {
232  return pool::TokenList::const_iterator( this );
233 }
234 
237 {
238  return pool::TokenList::const_iterator( this, size() );
239 }
240 
241 #endif
242 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
pool::TokenList::iterator_base::m_list
const TokenList * m_list
Definition: TokenList.h:133
pool::TokenList::operator==
bool operator==(const TokenList &rhs) const
Equality operator.
pool::TokenList::iterator
Forward iterator class for navigation of TokenList objects.
Definition: TokenList.h:139
pool::TokenList::iterator::iterator
iterator(TokenList *list, size_t idx=0)
Definition: TokenList.h:149
index
Definition: index.py:1
pool::TokenList::iterator_base::operator!=
bool operator!=(const iterator_base &rhs) const
Definition: TokenList.h:123
pool::TokenList::iterator::operator*
Token & operator*()
Definition: TokenList.h:152
pool
pool namespace
Definition: libname.h:15
pool::TokenList::const_iterator::~const_iterator
~const_iterator()
Definition: TokenList.h:167
pool::TokenList::TokenList
TokenList(const TokenList &rhs)
Copy constructor.
pool::TokenList::operator[]
Token & operator[](const std::string &name)
Returns a reference to a metadata Token given its name.
pool::TokenList::const_iterator::const_iterator
const_iterator(const iterator_base &rhs)
Definition: TokenList.h:168
pool::TokenList::iterator_base::operator==
bool operator==(const iterator_base &rhs) const
Definition: TokenList.h:120
pool::TokenList::m_tokenNames
std::vector< std::string > m_tokenNames
Token names.
Definition: TokenList.h:193
pool::TokenList::end
iterator end()
Returns a forward iterator pointing to last element in Token list.
Definition: TokenList.h:224
pool::TokenList::iterator_base::tokenName
const std::string & tokenName() const
Definition: TokenList.h:126
pool::TokenList::const_iterator::operator++
const_iterator & operator++()
Definition: TokenList.h:178
Token
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition: Token.h:21
pool::TokenList
Definition: TokenList.h:24
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
pool::TokenList::size
size_t size() const
Returns the size of the Token list.
Definition: TokenList.h:206
pool::TokenList::iterator::~iterator
~iterator()
Definition: TokenList.h:142
pool::TokenList::const_iterator::operator=
const_iterator & operator=(const iterator_base &rhs)
Definition: TokenList.h:169
pool::TokenList::const_iterator::operator*
const Token & operator*() const
Definition: TokenList.h:177
pool::TokenList::const_iterator::const_iterator
const_iterator(const TokenList *list, size_t idx=0)
Definition: TokenList.h:174
pool::TokenList::TokenList
TokenList(const std::vector< std::string > &specification)
Constructor that takes a list of Token names as input.
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
pool::TokenList::operator[]
const Token & operator[](unsigned int index) const
Returns a constant reference to a metadata Token given its index.
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
pool::TokenList::operator[]
Token & operator[](unsigned int index)
Returns a reference to a metadata Token given its index.
pool::TokenList::iterator_base::m_index
size_t m_index
Definition: TokenList.h:134
pool::TokenList::iterator::operator=
iterator & operator=(const iterator_base &rhs)
Definition: TokenList.h:144
pool::TokenList::iterator_base::~iterator_base
virtual ~iterator_base()
Definition: TokenList.h:131
pool::TokenList::const_iterator
Constant forward iterator class for navigation of TokenList objects.
Definition: TokenList.h:164
pool::TokenList::~TokenList
~TokenList()
Default destructor.
pool::TokenList::operator[]
const Token & operator[](const std::string &name) const
Returns a constant reference to a metadata Token given its name.
pool::TokenList::iterator_base::operator++
void operator++()
Definition: TokenList.h:124
pool::TokenList::iterator::operator++
iterator & operator++()
Definition: TokenList.h:153
pool::TokenList::extend
void extend(const std::string &name)
Extends the Token list by one element.
pool::TokenList::createFromSpec
void createFromSpec(const std::vector< std::string > &specification)
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
pool::TokenList::operator!=
bool operator!=(const TokenList &rhs) const
Inequality operator.
Definition: TokenList.h:212
pool::TokenList::toOutputStream
std::ostream & toOutputStream(std::ostream &os) const
Outputs the Token names and associated values to a specified stream.
pool::TokenList::begin
iterator begin()
Returns a forward iterator pointing to first element in Token list.
Definition: TokenList.h:218
pool::TokenList::operator=
TokenList & operator=(const TokenList &rhs)
Assignment operator.
pool::TokenList::iterator_base::next
bool next()
Definition: TokenList.h:125
pool::TokenList::iterator::operator->
Token * operator->()
Definition: TokenList.h:151
pool::TokenList::iterator_base
Base class for forward iterators used to navigate TokenList objects.
Definition: TokenList.h:118
pool::TokenList::const_iterator::operator->
const Token * operator->() const
Definition: TokenList.h:176
pool::TokenList::TokenList
TokenList()
Default constructor.
pool::TokenList::iterator_base::iterator_base
iterator_base(const TokenList *list, size_t idx=0)
Definition: TokenList.h:128
pool::TokenList::m_tokenMap
std::map< std::string, Token * > m_tokenMap
Map of Tokens with token name as key. Points to the same Token objects as m_tokenVector.
Definition: TokenList.h:199
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
pool::TokenList::clear
void clear()
delete the content of the list
pool::TokenList::iterator::iterator
iterator(const iterator_base &rhs)
Definition: TokenList.h:143
pool::TokenList::m_tokenVector
std::vector< Token * > m_tokenVector
Token vector (corresponding to m_tokenNames)
Definition: TokenList.h:196