Jpp  18.5.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | Protected Attributes | Private Types | Private Attributes | List of all members
JTOOLS::JRouter< JAddress_t, true > Class Template Reference

Template specialisation of JRouter with default address comparison. More...

#include <JRouter.hh>

Inheritance diagram for JTOOLS::JRouter< JAddress_t, true >:
JTOOLS::JRouter< JAddress_t, false > std::vector< JAddress_t >

Classes

class  JAddress
 Simple data structure for validation of address. More...
 

Public Member Functions

 JRouter ()
 Default constructor. More...
 
 JRouter (argument_type address)
 Constructor. More...
 
bool hasDefaultAddress () const
 Check availability of default address. More...
 
virtual const JAddress_t & getDefaultAddress () const override
 Get default address. More...
 
void setDefaultAddress (argument_type address)
 Set default address. More...
 
bool has (const int id) const
 Test whether given identifier has valid address (i.e identifier is in range and corresponding address is not equal to default address). More...
 
void clear ()
 Clear. More...
 
void swap (JRouter &router)
 Swap router. More...
 
void align (const JRouter &router)
 Align router. More...
 
void put (const int id, argument_type address)
 Store address for given identifier. More...
 
bool in_range (const int id) const
 Check whether given identifier is in range of this router. More...
 
const JAddress_t & get (const int id) const
 Get address of given identifier. More...
 

Protected Attributes

int first
 

Private Types

typedef JLANG::JClass
< JAddress_t >::argument_type 
argument_type
 

Private Attributes

JAddress defaultAddress
 

Detailed Description

template<class JAddress_t>
class JTOOLS::JRouter< JAddress_t, true >

Template specialisation of JRouter with default address comparison.

Definition at line 176 of file JRouter.hh.

Member Typedef Documentation

template<class JAddress_t >
typedef JLANG::JClass<JAddress_t>::argument_type JTOOLS::JRouter< JAddress_t, true >::argument_type
private

Definition at line 180 of file JRouter.hh.

Constructor & Destructor Documentation

template<class JAddress_t >
JTOOLS::JRouter< JAddress_t, true >::JRouter ( )
inline

Default constructor.

Definition at line 253 of file JRouter.hh.

253  :
256  {}
Template specialisation of JRouter without default address comparison.
Definition: JRouter.hh:34
template<class JAddress_t >
JTOOLS::JRouter< JAddress_t, true >::JRouter ( argument_type  address)
inline

Constructor.

Parameters
addressdefault address

Definition at line 264 of file JRouter.hh.

264  :
266  defaultAddress(address)
267  {}
Template specialisation of JRouter without default address comparison.
Definition: JRouter.hh:34

Member Function Documentation

template<class JAddress_t >
bool JTOOLS::JRouter< JAddress_t, true >::hasDefaultAddress ( ) const
inline

Check availability of default address.

Returns
true if available; else false

Definition at line 275 of file JRouter.hh.

276  {
277  return defaultAddress.is_valid();
278  }
bool is_valid() const
Check validity.
Definition: JRouter.hh:214
template<class JAddress_t >
virtual const JAddress_t& JTOOLS::JRouter< JAddress_t, true >::getDefaultAddress ( ) const
inlineoverridevirtual

Get default address.

Returns
default address

Reimplemented from JTOOLS::JRouter< JAddress_t, false >.

Definition at line 286 of file JRouter.hh.

287  {
288  return defaultAddress.getAddress();
289  }
const JAddress_t & getAddress() const
Get address.
Definition: JRouter.hh:225
template<class JAddress_t >
void JTOOLS::JRouter< JAddress_t, true >::setDefaultAddress ( argument_type  address)
inline

Set default address.

Parameters
addressdefault address

Definition at line 297 of file JRouter.hh.

298  {
299  defaultAddress = JAddress(address);
300  }
template<class JAddress_t >
bool JTOOLS::JRouter< JAddress_t, true >::has ( const int  id) const
inline

Test whether given identifier has valid address (i.e identifier is in range and corresponding address is not equal to default address).

Parameters
ididentifier
Returns
true if identifier in range and address not equal to default; else false

Definition at line 309 of file JRouter.hh.

310  {
311  return (this->in_range(id) && !this->defaultAddress.equals(this->get(id)));
312  }
bool in_range(const int id) const
Check whether given identifier is in range of this router.
Definition: JRouter.hh:150
then usage $script< detector file >< detectorfile > nIf the range of floors is the first detector file is aligned to the second before the comparison nIn this
bool equals(argument_type address) const
Compare to given address.
Definition: JRouter.hh:237
template<class JAddress_t >
void JTOOLS::JRouter< JAddress_t, false >::clear ( )
inlineinherited

Clear.

Definition at line 73 of file JRouter.hh.

74  {
75  static_cast<std::vector<JAddress_t>&>(*this).clear();
76 
77  this->first = 0;
78  }
template<class JAddress_t >
void JTOOLS::JRouter< JAddress_t, false >::swap ( JRouter< JAddress_t, false > &  router)
inlineinherited

Swap router.

Parameters
routerrouter

Definition at line 86 of file JRouter.hh.

87  {
88  std::swap(this->first, router.first);
89 
90  static_cast<std::vector<JAddress_t>&>(*this).swap(router);
91  }
template<class JAddress_t >
void JTOOLS::JRouter< JAddress_t, false >::align ( const JRouter< JAddress_t, false > &  router)
inlineinherited

Align router.

Parameters
routerrouter

Definition at line 99 of file JRouter.hh.

100  {
101  this->first = router.first;
102 
103  if (router.size() > this->size()) {
104  this->resize(router.size());
105  }
106  }
template<class JAddress_t >
void JTOOLS::JRouter< JAddress_t, false >::put ( const int  id,
argument_type  address 
)
inlineinherited

Store address for given identifier.

Parameters
ididentifier
addressaddress

Definition at line 115 of file JRouter.hh.

116  {
117  if (this->empty()) {
118 
119  this->push_back(address);
120 
121  this->first = id;
122 
123  } else if (id < this->first) {
124 
125  this->insert(this->begin(), this->first - id, getDefaultAddress());
126 
127  this->first = id;
128 
129  (*this)[0] = address;
130 
131  } else {
132 
133  const size_t index = (size_t) (id - this->first);
134 
135  if (index >= this->size()) {
136  this->resize(index + 1, getDefaultAddress());
137  }
138 
139  (*this)[index] = address;
140  }
141  }
virtual const JAddress_t & getDefaultAddress() const
Get default address.
Definition: JRouter.hh:62
template<class JAddress_t >
bool JTOOLS::JRouter< JAddress_t, false >::in_range ( const int  id) const
inlineinherited

Check whether given identifier is in range of this router.

Parameters
ididentifier
Returns
true if in range; else false

Definition at line 150 of file JRouter.hh.

151  {
152  return (id >= this->first && id < this->first + (int) this->size());
153  }
template<class JAddress_t >
const JAddress_t& JTOOLS::JRouter< JAddress_t, false >::get ( const int  id) const
inlineinherited

Get address of given identifier.

Parameters
ididentifier
Returns
address

Definition at line 162 of file JRouter.hh.

163  {
164  return (*this)[id - this->first];
165  }

Member Data Documentation

template<class JAddress_t >
JAddress JTOOLS::JRouter< JAddress_t, true >::defaultAddress
private

Definition at line 316 of file JRouter.hh.

template<class JAddress_t >
int JTOOLS::JRouter< JAddress_t, false >::first
protectedinherited

Definition at line 168 of file JRouter.hh.


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