Jpp  17.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Public Attributes | Protected Attributes | List of all members
JDETECTOR::JStringRouter Struct Reference

Router for mapping of string identifier to index. More...

#include <JStringRouter.hh>

Inheritance diagram for JDETECTOR::JStringRouter:
JTOOLS::JHashCollection< int > std::vector< int >

Public Types

typedef int value_type
 
typedef JHashEvaluator evaluator_type
 
typedef std::vector< value_typecontainer_type
 
typedef
container_type::const_iterator 
const_iterator
 
typedef
container_type::const_reverse_iterator 
const_reverse_iterator
 
typedef container_type::iterator iterator
 
typedef
container_type::reverse_iterator 
reverse_iterator
 

Public Member Functions

 JStringRouter (const JDetector &detector)
 Constructor. More...
 
void clear ()
 Clear. More...
 
void swap (JHashCollection &collection)
 Swap hash collection. More...
 
const_iterator find (const T &value) const
 Find element with given value. More...
 
iterator find (const T &value)
 Find element with given value. More...
 
value_typeget (const T &value)
 Get element with given value. More...
 
const value_typeget (const T &value) const
 Get element with given value. More...
 
virtual bool insert (const value_type &element)
 Insert element. More...
 
void insert (T __begin, T __end)
 Insert values. More...
 
void erase (iterator pos)
 Erase element at given position. More...
 
void erase (iterator __begin, iterator __end)
 Erase elements in given range. More...
 
bool erase (const T &value)
 Erase element with given value. More...
 
bool has (const T &value) const
 Test whether given value is present. More...
 
int getIndex (const T &value) const
 Get index of given value. More...
 

Public Attributes

JHashEvaluator getValue
 Function object for evaluation of element. More...
 

Protected Attributes

JTOOLS::JHashCollection::router_type router
 

Detailed Description

Router for mapping of string identifier to index.

Definition at line 21 of file JStringRouter.hh.

Member Typedef Documentation

typedef int JTOOLS::JHashCollection< int , JHashEvaluator >::value_type
inherited

Definition at line 41 of file JHashCollection.hh.

Definition at line 42 of file JHashCollection.hh.

Definition at line 44 of file JHashCollection.hh.

typedef container_type::const_iterator JTOOLS::JHashCollection< int , JHashEvaluator >::const_iterator
inherited

Definition at line 46 of file JHashCollection.hh.

typedef container_type::const_reverse_iterator JTOOLS::JHashCollection< int , JHashEvaluator >::const_reverse_iterator
inherited

Definition at line 47 of file JHashCollection.hh.

typedef container_type::iterator JTOOLS::JHashCollection< int , JHashEvaluator >::iterator
inherited

Definition at line 48 of file JHashCollection.hh.

typedef container_type::reverse_iterator JTOOLS::JHashCollection< int , JHashEvaluator >::reverse_iterator
inherited

Definition at line 49 of file JHashCollection.hh.

Constructor & Destructor Documentation

JDETECTOR::JStringRouter::JStringRouter ( const JDetector detector)
inline

Constructor.

Parameters
detectordetector

Definition at line 29 of file JStringRouter.hh.

30  {
31  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
32  this->insert(module->getString());
33  }
34  }
virtual bool insert(const value_type &element)
Insert element.

Member Function Documentation

void JTOOLS::JHashCollection< int , JHashEvaluator >::clear ( )
inlineinherited

Clear.

Definition at line 108 of file JHashCollection.hh.

109  {
110  for (const_iterator i = this->begin(); i != this->end(); ++i) {
111  router.put(this->getValue(*i), router.getDefaultAddress());
112  }
113 
114  container_type::clear();
115  }
JTOOLS::JHashCollection::router_type router
container_type::const_iterator const_iterator
JHashEvaluator getValue
Function object for evaluation of element.
void JTOOLS::JHashCollection< int , JHashEvaluator >::swap ( JHashCollection< int > &  collection)
inlineinherited

Swap hash collection.

Parameters
collectionhash collection

Definition at line 123 of file JHashCollection.hh.

124  {
125  router.swap(collection.router);
126 
127  container_type::swap(collection);
128  }
JTOOLS::JHashCollection::router_type router
const_iterator JTOOLS::JHashCollection< int , JHashEvaluator >::find ( const T value) const
inlineinherited

Find element with given value.

Parameters
valuevalue
Returns
position of element with given value or end()

Definition at line 138 of file JHashCollection.hh.

139  {
140  const int ival = this->getValue(value);
141 
142  if (router.has(ival))
143  return this->begin() + router.get(ival);
144  else
145  return this->end();
146  }
JTOOLS::JHashCollection::router_type router
JHashEvaluator getValue
Function object for evaluation of element.
iterator JTOOLS::JHashCollection< int , JHashEvaluator >::find ( const T value)
inlineinherited

Find element with given value.

Parameters
valuevalue
Returns
position of element with given value or end()

Definition at line 156 of file JHashCollection.hh.

157  {
158  const int ival = this->getValue(value);
159 
160  if (router.has(ival))
161  return this->begin() + router.get(ival);
162  else
163  return this->end();
164  }
JTOOLS::JHashCollection::router_type router
JHashEvaluator getValue
Function object for evaluation of element.
value_type& JTOOLS::JHashCollection< int , JHashEvaluator >::get ( const T value)
inlineinherited

Get element with given value.

This method will throw an exception if given value is not present following the prerequisite of constness.

Parameters
valuevalue
Returns
element

Definition at line 176 of file JHashCollection.hh.

177  {
178  const int ival = this->getValue(value);
179 
180  if (!router.has(ival)) {
181  this->insert(value);
182  }
183 
184  return container_type::operator[](router.get(ival)).second;
185  }
JTOOLS::JHashCollection::router_type router
virtual bool insert(const value_type &element)
Insert element.
JHashEvaluator getValue
Function object for evaluation of element.
const value_type& JTOOLS::JHashCollection< int , JHashEvaluator >::get ( const T value) const
inlineinherited

Get element with given value.

This method will throw an exception if given value is not present following the prerequisite of constness.

Parameters
valuevalue
Returns
element

Definition at line 197 of file JHashCollection.hh.

198  {
199  const int ival = this->getValue(value);
200 
201  if (router.has(ival)) {
202  return container_type::operator[](router.get(ival)).second;
203  }
204 
205  THROW(JIndexOutOfRange, "JHasCollection::get(): invalid value.");
206  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
JTOOLS::JHashCollection::router_type router
JHashEvaluator getValue
Function object for evaluation of element.
virtual bool JTOOLS::JHashCollection< int , JHashEvaluator >::insert ( const value_type element)
inlinevirtualinherited

Insert element.

Parameters
elementelement
Returns
true if inserted; else false

Definition at line 215 of file JHashCollection.hh.

216  {
217  const int ival = this->getValue(element);
218 
219  if (!router.has(ival)) {
220 
221  container_type::push_back(element);
222 
223  router.put(ival, this->size() - 1);
224 
225  return true;
226  }
227 
228  return false;
229  }
JTOOLS::JHashCollection::router_type router
JHashEvaluator getValue
Function object for evaluation of element.
void JTOOLS::JHashCollection< int , JHashEvaluator >::insert ( T  __begin,
T  __end 
)
inlineinherited

Insert values.

Parameters
__beginbegin of values
__endend of values

Definition at line 239 of file JHashCollection.hh.

240  {
241  for (T i = __begin; i != __end; ++i) {
242  insert(*i);
243  }
244  }
virtual bool insert(const value_type &element)
Insert element.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
void JTOOLS::JHashCollection< int , JHashEvaluator >::erase ( iterator  pos)
inlineinherited

Erase element at given position.

Parameters
posvalid position

Definition at line 252 of file JHashCollection.hh.

253  {
254  router.put(this->getValue(*pos), router.getDefaultAddress());
255 
256  for (iterator i = container_type::erase(pos); i != this->end(); ++i) {
257  router.put(this->getValue(*i), distance(this->begin(), i));
258  }
259  }
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
JTOOLS::JHashCollection::router_type router
container_type::iterator iterator
JHashEvaluator getValue
Function object for evaluation of element.
void JTOOLS::JHashCollection< int , JHashEvaluator >::erase ( iterator  __begin,
iterator  __end 
)
inlineinherited

Erase elements in given range.

Parameters
__beginbegin position (included)
__endend position (excluded)

Definition at line 268 of file JHashCollection.hh.

269  {
270  for (iterator i = __begin; i != __end; ++i) {
271  router.put(this->getValue(*i), router.getDefaultAddress());
272  }
273 
274  for (iterator i = container_type::erase(__begin, __end); i != this->end(); ++i) {
275  router.put(this->getValue(*i), distance(this->begin(), i));
276  }
277  }
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
JTOOLS::JHashCollection::router_type router
container_type::iterator iterator
JHashEvaluator getValue
Function object for evaluation of element.
bool JTOOLS::JHashCollection< int , JHashEvaluator >::erase ( const T value)
inlineinherited

Erase element with given value.

Parameters
valuevalue
Returns
true if element has been erased; else false

Definition at line 287 of file JHashCollection.hh.

288  {
289  const int ival = this->getValue(value);
290 
291  if (router.has(ival)) {
292 
293  this->erase(this->begin() + router.get(ival));
294 
295  return true;
296  }
297 
298  return false;
299  }
JTOOLS::JHashCollection::router_type router
void erase(iterator pos)
Erase element at given position.
JHashEvaluator getValue
Function object for evaluation of element.
bool JTOOLS::JHashCollection< int , JHashEvaluator >::has ( const T value) const
inlineinherited

Test whether given value is present.

Parameters
valuevalue
Returns
true if present; else false

Definition at line 309 of file JHashCollection.hh.

310  {
311  return router.has(this->getValue(value));
312  }
JTOOLS::JHashCollection::router_type router
JHashEvaluator getValue
Function object for evaluation of element.
int JTOOLS::JHashCollection< int , JHashEvaluator >::getIndex ( const T value) const
inlineinherited

Get index of given value.

Parameters
valuevalue
Returns
indecx

Definition at line 322 of file JHashCollection.hh.

323  {
324  return router.get(this->getValue(value));
325  }
JTOOLS::JHashCollection::router_type router
JHashEvaluator getValue
Function object for evaluation of element.

Member Data Documentation

Function object for evaluation of element.

Definition at line 331 of file JHashCollection.hh.


The documentation for this struct was generated from the following file: