ATLAS Offline Software
Loading...
Searching...
No Matches
TokenList.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef COLLECTIONSVC_TOKENLIST_H
6#define COLLECTIONSVC_TOKENLIST_H
7
8#include <string>
9#include <vector>
10#include <map>
11#include <iosfwd>
12
13
14class Token;
15
16namespace pool {
17
24 {
25 public:
28
34 TokenList( const std::vector<std::string>& specification );
35
41 TokenList( const TokenList& rhs );
42
45
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;
143 iterator( const iterator_base& rhs ) : 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:
151 Token* operator->() { return m_list->m_tokenVector[ m_index ]; }
152 Token& operator*() { return *operator->(); }
154 };
155
157 iterator begin();
158
160 iterator end();
161
164 {
165 public:
166 friend class TokenList;
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.
205inline size_t
207{
208 return m_tokenVector.size();
209}
210
211inline 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
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition Token.h:21
Constant forward iterator class for navigation of TokenList objects.
Definition TokenList.h:164
const Token * operator->() const
Definition TokenList.h:176
const_iterator(const iterator_base &rhs)
Definition TokenList.h:168
const_iterator(const TokenList *list, size_t idx=0)
Definition TokenList.h:174
const_iterator & operator=(const iterator_base &rhs)
Definition TokenList.h:169
const Token & operator*() const
Definition TokenList.h:177
const_iterator & operator++()
Definition TokenList.h:178
bool operator!=(const iterator_base &rhs) const
Definition TokenList.h:123
const std::string & tokenName() const
Definition TokenList.h:126
iterator_base(const TokenList *list, size_t idx=0)
Definition TokenList.h:128
bool operator==(const iterator_base &rhs) const
Definition TokenList.h:120
Forward iterator class for navigation of TokenList objects.
Definition TokenList.h:139
iterator(TokenList *list, size_t idx=0)
Definition TokenList.h:149
iterator & operator=(const iterator_base &rhs)
Definition TokenList.h:144
iterator(const iterator_base &rhs)
Definition TokenList.h:143
A container class to facilitate the use of Token objects.
Definition TokenList.h:24
std::vector< Token * > m_tokenVector
Token vector (corresponding to m_tokenNames)
Definition TokenList.h:196
size_t size() const
Returns the size of the Token list.
Definition TokenList.h:206
TokenList(const std::vector< std::string > &specification)
Constructor that takes a list of Token names as input.
void extend(const std::string &name)
Extends the Token list by one element.
const Token & operator[](unsigned int index) const
Returns a constant reference to a metadata Token given its index.
Token & operator[](unsigned int index)
Returns a reference to a metadata Token given its index.
TokenList()
Default constructor.
void clear()
delete the content of the list
std::ostream & toOutputStream(std::ostream &os) const
Outputs the Token names and associated values to a specified stream.
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
const Token & operator[](const std::string &name) const
Returns a constant reference to a metadata Token given its name.
Token & operator[](const std::string &name)
Returns a reference to a metadata Token given its name.
std::vector< std::string > m_tokenNames
Token names.
Definition TokenList.h:193
iterator begin()
Returns a forward iterator pointing to first element in Token list.
Definition TokenList.h:218
bool operator!=(const TokenList &rhs) const
Inequality operator.
Definition TokenList.h:212
void createFromSpec(const std::vector< std::string > &specification)
bool operator==(const TokenList &rhs) const
Equality operator.
TokenList(const TokenList &rhs)
Copy constructor.
iterator end()
Returns a forward iterator pointing to last element in Token list.
Definition TokenList.h:224
TokenList & operator=(const TokenList &rhs)
Assignment operator.
~TokenList()
Default destructor.
Definition index.py:1
pool namespace
Definition libname.h:15