Jpp
 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
 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 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 131 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 135 of file JRouter.hh.

Constructor & Destructor Documentation

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

Default constructor.

Definition at line 208 of file JRouter.hh.

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

Constructor.

Parameters
addressdefault address

Definition at line 219 of file JRouter.hh.

219  :
221  defaultAddress(address)
222  {}
Template specialisation of JRouter without default address comparison.
Definition: JRouter.hh:33

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

231  {
232  return defaultAddress.is_valid();
233  }
bool is_valid() const
Check validity.
Definition: JRouter.hh:169
template<class JAddress_t >
virtual const JAddress_t& JTOOLS::JRouter< JAddress_t, true >::getDefaultAddress ( ) const
inlinevirtual

Get default address.

Returns
default address

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

Definition at line 241 of file JRouter.hh.

242  {
243  return defaultAddress.getAddress();
244  }
const JAddress_t & getAddress() const
Get address.
Definition: JRouter.hh:180
template<class JAddress_t >
void JTOOLS::JRouter< JAddress_t, true >::setDefaultAddress ( argument_type  address)
inline

Set default address.

Parameters
addressdefault address

Definition at line 252 of file JRouter.hh.

253  {
254  defaultAddress = JAddress(address);
255  }
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 264 of file JRouter.hh.

265  {
266  return (this->in_range(id) && !this->defaultAddress.equals(this->get(id)));
267  }
bool in_range(const int id) const
Check whether given identifier is in range of this router.
Definition: JRouter.hh:105
bool equals(argument_type address) const
Compare to given address.
Definition: JRouter.hh:192
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 74 of file JRouter.hh.

75  {
76  if (this->empty()) {
77 
78  this->push_back(address);
79 
80  this->first = id;
81 
82  } else {
83 
84  for ( ; id < this->first; --(this->first)) {
85  this->push_front(getDefaultAddress());
86  }
87 
88  const unsigned int index = (unsigned int) (id - this->first);
89 
90  while (index >= this->size()) {
91  this->push_back(getDefaultAddress());
92  }
93 
94  this->at(index) = address;
95  }
96  }
virtual const JAddress_t & getDefaultAddress() const
Get default address.
Definition: JRouter.hh:60
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 105 of file JRouter.hh.

106  {
107  return (id >= this->first && id < this->first + (int) this->size());
108  }
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 117 of file JRouter.hh.

118  {
119  return this->at(id - this->first);
120  }

Member Data Documentation

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

Definition at line 271 of file JRouter.hh.

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

Definition at line 123 of file JRouter.hh.


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