Jpp  17.0.0-rc.1
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 >

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 175 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 179 of file JRouter.hh.

Constructor & Destructor Documentation

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

Default constructor.

Definition at line 252 of file JRouter.hh.

252  :
255  {}
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 263 of file JRouter.hh.

263  :
265  defaultAddress(address)
266  {}
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 274 of file JRouter.hh.

275  {
276  return defaultAddress.is_valid();
277  }
bool is_valid() const
Check validity.
Definition: JRouter.hh:213
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 285 of file JRouter.hh.

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

Set default address.

Parameters
addressdefault address

Definition at line 296 of file JRouter.hh.

297  {
298  defaultAddress = JAddress(address);
299  }
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 308 of file JRouter.hh.

309  {
310  return (this->in_range(id) && !this->defaultAddress.equals(this->get(id)));
311  }
bool in_range(const int id) const
Check whether given identifier is in range of this router.
Definition: JRouter.hh:149
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:236
template<class JAddress_t >
void JTOOLS::JRouter< JAddress_t, false >::clear ( )
inlineinherited

Clear.

Definition at line 72 of file JRouter.hh.

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

Swap router.

Parameters
routerrouter

Definition at line 85 of file JRouter.hh.

86  {
87  std::swap(this->first, router.first);
88 
89  static_cast<std::deque<JAddress_t>&>(*this).swap(router);
90  }
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 98 of file JRouter.hh.

99  {
100  this->first = router.first;
101 
102  if (router.size() > this->size()) {
103  this->resize(router.size());
104  }
105  }
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 114 of file JRouter.hh.

115  {
116  if (this->empty()) {
117 
118  this->push_back(address);
119 
120  this->first = id;
121 
122  } else if (id < this->first) {
123 
124  this->insert(this->begin(), this->first - id, getDefaultAddress());
125 
126  this->first = id;
127 
128  this->at(0) = address;
129 
130  } else {
131 
132  const size_t index = (size_t) (id - this->first);
133 
134  if (index >= this->size()) {
135  this->resize(index + 1, getDefaultAddress());
136  }
137 
138  this->at(index) = address;
139  }
140  }
virtual const JAddress_t & getDefaultAddress() const
Get default address.
Definition: JRouter.hh:61
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 149 of file JRouter.hh.

150  {
151  return (id >= this->first && id < this->first + (int) this->size());
152  }
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 161 of file JRouter.hh.

162  {
163  return this->at(id - this->first);
164  }

Member Data Documentation

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

Definition at line 315 of file JRouter.hh.

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

Definition at line 167 of file JRouter.hh.


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