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 clear ()
 Clear. More...
 
void copy (const JRouter &router, const bool option=true)
 Copy 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 166 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 170 of file JRouter.hh.

Constructor & Destructor Documentation

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

Default constructor.

Definition at line 243 of file JRouter.hh.

243  :
246  {}
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 254 of file JRouter.hh.

254  :
256  defaultAddress(address)
257  {}
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 265 of file JRouter.hh.

266  {
267  return defaultAddress.is_valid();
268  }
bool is_valid() const
Check validity.
Definition: JRouter.hh:204
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 276 of file JRouter.hh.

277  {
278  return defaultAddress.getAddress();
279  }
const JAddress_t & getAddress() const
Get address.
Definition: JRouter.hh:215
template<class JAddress_t >
void JTOOLS::JRouter< JAddress_t, true >::setDefaultAddress ( argument_type  address)
inline

Set default address.

Parameters
addressdefault address

Definition at line 287 of file JRouter.hh.

288  {
289  defaultAddress = JAddress(address);
290  }
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 299 of file JRouter.hh.

300  {
301  return (this->in_range(id) && !this->defaultAddress.equals(this->get(id)));
302  }
bool in_range(const int id) const
Check whether given identifier is in range of this router.
Definition: JRouter.hh:140
bool equals(argument_type address) const
Compare to given address.
Definition: JRouter.hh:227
template<class JAddress_t >
void JTOOLS::JRouter< JAddress_t, false >::clear ( )
inlineinherited

Clear.

Definition at line 71 of file JRouter.hh.

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

Copy router.

Parameters
routerrouter
optioncopy addresses

Definition at line 85 of file JRouter.hh.

86  {
87  if (option) {
88 
89  *this = router;
90 
91  } else {
92 
93  this->resize(router.size());
94  this->first = router.first;
95  }
96  }
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 105 of file JRouter.hh.

106  {
107  if (this->empty()) {
108 
109  this->push_back(address);
110 
111  this->first = id;
112 
113  } else if (id < this->first) {
114 
115  this->insert(this->begin(), this->first - id, getDefaultAddress());
116 
117  this->first = id;
118 
119  this->at(0) = address;
120 
121  } else {
122 
123  const size_t index = (size_t) (id - this->first);
124 
125  if (index >= this->size()) {
126  this->resize(index + 1, getDefaultAddress());
127  }
128 
129  this->at(index) = address;
130  }
131  }
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 140 of file JRouter.hh.

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

153  {
154  return this->at(id - this->first);
155  }

Member Data Documentation

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

Definition at line 306 of file JRouter.hh.

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

Definition at line 158 of file JRouter.hh.


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