Jpp  18.4.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 Member Functions | Protected Attributes | List of all members
JTOOLS::JMap< JKey_t, JValue_t, JDistance_t > Class Template Referenceabstract

Map of pair-wise elements. More...

#include <JMap.hh>

Inheritance diagram for JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >:
JTOOLS::JCollection< JElement2D< JKey_t, JValue_t >, JDistance_t > JMATH::JMath< JFirst_t, JSecond_t > std::vector< JElement_t, JAllocator_t > JTOOLS::JMappableCollection< JKey_t, JValue_t > JTOOLS::JAbstractCollection< JAbscissa_t > JMATH::JMath< JFirst_t, JSecond_t > JTOOLS::JSplineMap< JKey_t, JValue_t, JMap, JResultDerivative< JResultType< JValue_t >::result_type >, JDistance_t > JTOOLS::JSplineMap< JKey_t, JValue_t, JMap, JResultType< JValue_t >::result_type, JDistance_t > JTOOLS::JSplineFunctionalMapH< JKey_t, JValue_t, JDistance_t > JTOOLS::JSplineFunctionalMap< JKey_t, JValue_t, JDistance_t >

Public Types

typedef JKey_t key_type
 
typedef JValue_t mapped_type
 
typedef JCollection
< JElement2D< JKey_t, JValue_t >
, JDistance_t > 
container_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
 
typedef JElement2D< JKey_t,
JValue_t >::abscissa_type 
abscissa_type
 
typedef JElement2D< JKey_t,
JValue_t >::ordinate_type 
ordinate_type
 
typedef JElement2D< JKey_t,
JValue_t > 
value_type
 
typedef JDistance_t distance_type
 
typedef JCollection
< JElement2D< JKey_t, JValue_t >
, JDistance_t > 
collection_type
 
typedef
JCollectionElementTransformer
< value_type
transformer_type
 
typedef std::pair
< const_iterator, bool > 
pair_type
 

Public Member Functions

 JMap ()
 Default constructor. More...
 
JMapadd (const JMap &map)
 Add map. More...
 
JMapsub (const JMap &map)
 Subtract map. More...
 
JMapmul (const double value)
 Scale contents. More...
 
JMapdiv (const double value)
 Scale contents. More...
 
virtual void clear () override
 Clear. More...
 
virtual const ordinate_typeget (typename JClass< abscissa_type >::argument_type x) const override
 Get ordinate value. More...
 
virtual ordinate_typeget (typename JClass< abscissa_type >::argument_type x) override
 Get ordinate value. More...
 
virtual const mapped_typeget (typename JClass< key_type >::argument_type key) const =0
 Get mapped value. More...
 
virtual mapped_typeget (typename JClass< key_type >::argument_type key)=0
 Get mapped value. More...
 
virtual int getSize () const override
 Get number of elements. More...
 
virtual abscissa_type getX (int index) const override
 Get abscissa value. More...
 
virtual abscissa_type getXmin () const override
 Get minimal abscissa value. More...
 
virtual abscissa_type getXmax () const override
 Get maximal abscissa value. More...
 
const ordinate_typegetY (int index) const
 Get ordinate value. More...
 
ordinate_typegetY (int index)
 Get ordinate value. More...
 
void transform (const transformer_type &transformer)
 Transform collection. More...
 
void sort ()
 Sort elements. More...
 
const_iterator lower_bound (typename JClass< abscissa_type >::argument_type x) const
 Get first position of element i, where x >= i->getX(). More...
 
iterator lower_bound (typename JClass< abscissa_type >::argument_type x)
 Get first position of element i, where x >= i->getX(). More...
 
pair_type insert (const value_type &element)
 Insert element. More...
 
void configure (const JAbstractCollection< abscissa_type > &bounds)
 Configure collection. More...
 
void configure (const JAbstractCollection< abscissa_type > &bounds, typename JClass< ordinate_type >::argument_type value)
 Configure collection. More...
 
void configure (const JAbstractCollection< abscissa_type > &bounds, const JFunction1D_t &function)
 Configure collection. More...
 
bool is_compatible (const JCollection &collection) const
 Test whether collections are compatible. More...
 
JCollectionnegate ()
 Negate collection. More...
 
JCollectionadd (const JCollection &collection)
 Add collection. More...
 
JCollectionadd (typename JClass< ordinate_type >::argument_type value)
 Add offset. More...
 
JCollectionadd (const JFunction1D_t &function)
 Add function. More...
 
JCollectionsub (const JCollection &collection)
 Subtract collection. More...
 
JCollectionsub (typename JClass< ordinate_type >::argument_type value)
 Subtract offset. More...
 
JCollectionsub (const JFunction1D_t &function)
 Subtract function. More...
 
JFirst_t & mul (const JSecond_t &object)
 Multiply with object. More...
 
const JComparatorgetComparator () const
 Get comparator. More...
 
const mapped_typeoperator[] (typename JClass< key_type >::argument_type key) const
 Get mapped value. More...
 
mapped_typeoperator[] (typename JClass< key_type >::argument_type key)
 Get mapped value. More...
 
void put (typename JClass< key_type >::argument_type key, typename JClass< mapped_type >::argument_type value)
 Put pair-wise element (key,value) into collection. More...
 
bool is_equal (const JAbstractCollection &collection) const
 Test whether abstract collections are equal. More...
 
JFirst_t & mul (const JSecond_t &object)
 Multiply with object. More...
 

Public Attributes

JDistance_t getDistance
 Function object for distance evaluation. More...
 

Protected Member Functions

void resize (typename container_type::size_type size)
 Resize collection. More...
 

Protected Attributes

JComparator compare
 Function object for comparison. More...
 

Detailed Description

template<class JKey_t, class JValue_t, class JDistance_t = JDistance<JKey_t>>
class JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >

Map of pair-wise elements.

The key_type and mapped_type refer to the pair-wise element of this map, respectively.

Definition at line 30 of file JMap.hh.

Member Typedef Documentation

template<class JKey_t, class JValue_t, class JDistance_t = JDistance<JKey_t>>
typedef JKey_t JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >::key_type

Definition at line 36 of file JMap.hh.

template<class JKey_t, class JValue_t, class JDistance_t = JDistance<JKey_t>>
typedef JValue_t JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >::mapped_type

Definition at line 37 of file JMap.hh.

template<class JKey_t, class JValue_t, class JDistance_t = JDistance<JKey_t>>
typedef JCollection<JElement2D<JKey_t, JValue_t>, JDistance_t> JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >::container_type

Definition at line 39 of file JMap.hh.

template<class JKey_t, class JValue_t, class JDistance_t = JDistance<JKey_t>>
typedef container_type::const_iterator JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >::const_iterator

Definition at line 41 of file JMap.hh.

template<class JKey_t, class JValue_t, class JDistance_t = JDistance<JKey_t>>
typedef container_type::const_reverse_iterator JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >::const_reverse_iterator

Definition at line 42 of file JMap.hh.

template<class JKey_t, class JValue_t, class JDistance_t = JDistance<JKey_t>>
typedef container_type::iterator JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >::iterator

Definition at line 43 of file JMap.hh.

template<class JKey_t, class JValue_t, class JDistance_t = JDistance<JKey_t>>
typedef container_type::reverse_iterator JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >::reverse_iterator

Definition at line 44 of file JMap.hh.

typedef JElement2D< JKey_t, JValue_t > ::abscissa_type JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::abscissa_type
inherited

Definition at line 82 of file JCollection.hh.

typedef JElement2D< JKey_t, JValue_t > ::ordinate_type JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::ordinate_type
inherited

Definition at line 83 of file JCollection.hh.

typedef JElement2D< JKey_t, JValue_t > JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::value_type
inherited

Definition at line 84 of file JCollection.hh.

typedef JDistance_t JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::distance_type
inherited

Definition at line 85 of file JCollection.hh.

typedef JCollection<JElement2D< JKey_t, JValue_t > , JDistance_t> JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::collection_type
inherited

Definition at line 87 of file JCollection.hh.

typedef JCollectionElementTransformer<value_type> JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::transformer_type
inherited

Definition at line 96 of file JCollection.hh.

typedef std::pair<const_iterator, bool> JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::pair_type
inherited

Definition at line 97 of file JCollection.hh.

Constructor & Destructor Documentation

template<class JKey_t, class JValue_t, class JDistance_t = JDistance<JKey_t>>
JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >::JMap ( )
inline

Default constructor.

Definition at line 50 of file JMap.hh.

51  {}

Member Function Documentation

template<class JKey_t, class JValue_t, class JDistance_t = JDistance<JKey_t>>
JMap& JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >::add ( const JMap< JKey_t, JValue_t, JDistance_t > &  map)
inline

Add map.

Parameters
mapmap
Returns
this map

Definition at line 60 of file JMap.hh.

61  {
62  static_cast<container_type&>(*this).add(static_cast<const container_type&>(map));
63 
64  return *this;
65  }
JCollection & add(const JCollection &collection)
Add collection.
Definition: JCollection.hh:452
JCollection< JElement2D< JKey_t, JValue_t >, JDistance_t > container_type
Definition: JMap.hh:39
template<class JKey_t, class JValue_t, class JDistance_t = JDistance<JKey_t>>
JMap& JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >::sub ( const JMap< JKey_t, JValue_t, JDistance_t > &  map)
inline

Subtract map.

Parameters
mapmap
Returns
this map

Definition at line 74 of file JMap.hh.

75  {
76  static_cast<container_type&>(*this).sub(static_cast<const container_type&>(map));
77 
78  return *this;
79  }
JCollection & sub(const JCollection &collection)
Subtract collection.
Definition: JCollection.hh:508
JCollection< JElement2D< JKey_t, JValue_t >, JDistance_t > container_type
Definition: JMap.hh:39
template<class JKey_t, class JValue_t, class JDistance_t = JDistance<JKey_t>>
JMap& JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >::mul ( const double  value)
inline

Scale contents.

Parameters
valuemultiplication factor
Returns
this map

Definition at line 88 of file JMap.hh.

89  {
90  static_cast<container_type&>(*this).mul(value);
91 
92  return *this;
93  }
JCollection & mul(const double value)
Scale contents.
Definition: JCollection.hh:568
JCollection< JElement2D< JKey_t, JValue_t >, JDistance_t > container_type
Definition: JMap.hh:39
template<class JKey_t, class JValue_t, class JDistance_t = JDistance<JKey_t>>
JMap& JTOOLS::JMap< JKey_t, JValue_t, JDistance_t >::div ( const double  value)
inline

Scale contents.

Parameters
valuedivision factor
Returns
this map

Definition at line 101 of file JMap.hh.

102  {
103  static_cast<container_type&>(*this).div(value);
104 
105  return *this;
106  }
JCollection & div(const double value)
Scale contents.
Definition: JCollection.hh:584
JCollection< JElement2D< JKey_t, JValue_t >, JDistance_t > container_type
Definition: JMap.hh:39
virtual void JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::clear ( )
inlineoverridevirtualinherited

Clear.

Implements JTOOLS::JMappableCollection< JKey_t, JValue_t >.

Definition at line 150 of file JCollection.hh.

151  {
152  container_type::clear();
153  }
virtual const ordinate_type& JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::get ( typename JClass< abscissa_type >::argument_type  x) const
inlineoverridevirtualinherited

Get ordinate value.

Parameters
xabscissa value
Returns
ordinate value

Definition at line 162 of file JCollection.hh.

163  {
164  const_iterator i = this->lower_bound(x);
165 
166  if (i == this->end() || this->getDistance(x, i->getX()) > distance_type::precision) {
167  THROW(JValueOutOfRange, "Invalid abscissa value " << x);
168  }
169 
170  return i->getY();
171  }
JDistance_t getDistance
Function object for distance evaluation.
Definition: JCollection.hh:773
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
const_iterator lower_bound(typename JClass< abscissa_type >::argument_type x) const
Get first position of element i, where x &gt;= i-&gt;getX().
Definition: JCollection.hh:292
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
virtual ordinate_type& JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::get ( typename JClass< abscissa_type >::argument_type  x)
inlineoverridevirtualinherited

Get ordinate value.

Parameters
xabscissa value
Returns
ordinate value

Definition at line 180 of file JCollection.hh.

181  {
182  iterator i = this->lower_bound(x);
183 
184  if (i == this->end() || this->getDistance(x, i->getX()) > distance_type::precision) {
185  i = container_type::insert(i, value_type(x, JMATH::getZero<ordinate_type>()));
186  }
187 
188  return i->getY();
189  }
JDistance_t getDistance
Function object for distance evaluation.
Definition: JCollection.hh:773
const_iterator lower_bound(typename JClass< abscissa_type >::argument_type x) const
Get first position of element i, where x &gt;= i-&gt;getX().
Definition: JCollection.hh:292
template<class JKey_t, class JValue_t>
virtual const mapped_type& JTOOLS::JMappableCollection< JKey_t, JValue_t >::get ( typename JClass< key_type >::argument_type  key) const
pure virtualinherited
template<class JKey_t, class JValue_t>
virtual mapped_type& JTOOLS::JMappableCollection< JKey_t, JValue_t >::get ( typename JClass< key_type >::argument_type  key)
pure virtualinherited
virtual int JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::getSize ( ) const
inlineoverridevirtualinherited

Get number of elements.

Returns
number of elements

Implements JTOOLS::JAbstractCollection< JAbscissa_t >.

Definition at line 197 of file JCollection.hh.

198  {
199  return (int) this->size();
200  }
virtual abscissa_type JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::getX ( int  index) const
inlineoverridevirtualinherited

Get abscissa value.

Parameters
indexindex
Returns
abscissa value

Implements JTOOLS::JAbstractCollection< JAbscissa_t >.

Definition at line 209 of file JCollection.hh.

210  {
211  return this->at(index).getX();
212  }
virtual abscissa_type JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::getXmin ( ) const
inlineoverridevirtualinherited

Get minimal abscissa value.

Returns
abscissa value

Implements JTOOLS::JAbstractCollection< JAbscissa_t >.

Definition at line 220 of file JCollection.hh.

221  {
222  return this->begin()->getX();
223  }
virtual abscissa_type JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::getXmax ( ) const
inlineoverridevirtualinherited

Get maximal abscissa value.

Returns
abscissa value

Implements JTOOLS::JAbstractCollection< JAbscissa_t >.

Definition at line 231 of file JCollection.hh.

232  {
233  return this->rbegin()->getX();
234  }
const ordinate_type& JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::getY ( int  index) const
inlineinherited

Get ordinate value.

Parameters
indexindex
Returns
ordinate value

Definition at line 244 of file JCollection.hh.

245  {
246  return this->at(index).getY();
247  }
ordinate_type& JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::getY ( int  index)
inlineinherited

Get ordinate value.

Parameters
indexindex
Returns
ordinate value

Definition at line 256 of file JCollection.hh.

257  {
258  return this->at(index).getY();
259  }
void JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::transform ( const transformer_type transformer)
inlineinherited

Transform collection.

Parameters
transformerelement transformer

Definition at line 267 of file JCollection.hh.

268  {
269  for (iterator i = this->begin(); i != this->end(); ++i) {
270  *i = transformer(*i);
271  }
272 
273  sort();
274  }
void JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::sort ( )
inlineinherited

Sort elements.

Definition at line 280 of file JCollection.hh.

281  {
282  std::sort(this->begin(), this->end(), compare);
283  }
JComparator compare
Function object for comparison.
Definition: JCollection.hh:780
const_iterator JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::lower_bound ( typename JClass< abscissa_type >::argument_type  x) const
inlineinherited

Get first position of element i, where x >= i->getX().

Parameters
xabscissa value
Returns
position of corresponding element

Definition at line 292 of file JCollection.hh.

293  {
294  return std::lower_bound(this->begin(), this->end(), x, compare);
295  }
JComparator compare
Function object for comparison.
Definition: JCollection.hh:780
iterator JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::lower_bound ( typename JClass< abscissa_type >::argument_type  x)
inlineinherited

Get first position of element i, where x >= i->getX().

Parameters
xabscissa value
Returns
position of corresponding element

Definition at line 304 of file JCollection.hh.

305  {
306  return std::lower_bound(this->begin(), this->end(), x, compare);
307  }
JComparator compare
Function object for comparison.
Definition: JCollection.hh:780
pair_type JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::insert ( const value_type element)
inlineinherited

Insert element.

Parameters
elementelement
Returns
(iterator, status), where status is true if inserted; else false

Definition at line 316 of file JCollection.hh.

317  {
318  iterator i = this->lower_bound(element.getX());
319 
320  if (i == this->end() || this->getDistance(element.getX(), i->getX()) > 0.0)
321  return pair_type(container_type::insert(i, element), true);
322  else
323  return pair_type(this->end(), false);
324  }
JDistance_t getDistance
Function object for distance evaluation.
Definition: JCollection.hh:773
const_iterator lower_bound(typename JClass< abscissa_type >::argument_type x) const
Get first position of element i, where x &gt;= i-&gt;getX().
Definition: JCollection.hh:292
void JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::configure ( const JAbstractCollection< abscissa_type > &  bounds)
inlineinherited

Configure collection.

Parameters
boundsabscissa values

Definition at line 332 of file JCollection.hh.

333  {
334  configure(bounds, JMATH::getZero<ordinate_type>());
335  }
void configure(const JAbstractCollection< abscissa_type > &bounds)
Configure collection.
Definition: JCollection.hh:332
void JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::configure ( const JAbstractCollection< abscissa_type > &  bounds,
typename JClass< ordinate_type >::argument_type  value 
)
inlineinherited

Configure collection.

Parameters
boundsabscissa values
valueordinate value

Definition at line 344 of file JCollection.hh.

346  {
347  this->resize(bounds.getSize());
348 
349  for (iterator i = this->begin(); i != this->end(); ++i) {
350 
351  const abscissa_type x = bounds.getX(std::distance(this->begin(),i));
352 
353  *i = value_type(x,value);
354  }
355  }
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
void resize(typename container_type::size_type size)
Resize collection.
Definition: JCollection.hh:788
JElement2D< JKey_t, JValue_t >::abscissa_type abscissa_type
Definition: JCollection.hh:82
virtual abscissa_type getX(int index) const =0
Get abscissa value.
virtual int getSize() const =0
Get number of elements.
void JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::configure ( const JAbstractCollection< abscissa_type > &  bounds,
const JFunction1D_t &  function 
)
inlineinherited

Configure collection.

Parameters
boundsabscissa values
functionfunction

Definition at line 365 of file JCollection.hh.

367  {
368  using namespace JLANG;
369 
370  collection_type* out = (is_identical(*this, function) ? new collection_type() : this);
371 
372  for (int i = 0; i != bounds.getSize(); ++i) {
373 
374  const abscissa_type x = bounds.getX(i);
375 
376  out->put(x, function(x));
377  }
378 
379  if (is_identical(*this, function)) {
380 
381  this->swap(*out);
382 
383  delete out;
384  }
385  }
JCollection< JElement2D< JKey_t, JValue_t >, JDistance_t > collection_type
Definition: JCollection.hh:87
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
JElement2D< JKey_t, JValue_t >::abscissa_type abscissa_type
Definition: JCollection.hh:82
bool is_identical(JFirst_t &first, JSecond_t &second)
Check if two objects are indentical.
Definition: JLangToolkit.hh:46
virtual abscissa_type getX(int index) const =0
Get abscissa value.
virtual int getSize() const =0
Get number of elements.
bool JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::is_compatible ( const JCollection< JElement2D< JKey_t, JValue_t >, JDistance_t > &  collection) const
inlineinherited

Test whether collections are compatible.

Parameters
collectioncollection
Returns
true if collections are compatible; else false

Definition at line 394 of file JCollection.hh.

395  {
396  if (this->empty() || collection.empty()) {
397 
398  return true;
399 
400  } else {
401 
402  const double precision = JDistance<abscissa_type>::precision;
403 
404  const_iterator p = this->begin();
405  const_iterator q = collection.begin();
406 
407  if (getDistance(p->getX(), q->getX()) > precision) {
408 
409  do {
410  ++p;
411  } while (p != this->end() && getDistance(p->getX(), q->getX()) > precision);
412 
413  } else if (getDistance(q->getX(), p->getX()) > precision) {
414 
415  do {
416  ++q;
417  } while (q != collection.end() && getDistance(q->getX(), p->getX()) > precision);
418  }
419 
420  for ( ; p != this->end() && q != collection.end(); ++p, ++q) {
421  if (fabs(getDistance(p->getX(), q->getX())) > precision) {
422  return false;
423  }
424  }
425 
426  return true;
427  }
428  }
Template class for distance evaluation.
Definition: JDistance.hh:24
JDistance_t getDistance
Function object for distance evaluation.
Definition: JCollection.hh:773
JCollection& JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::negate ( )
inlineinherited

Negate collection.

Returns
this collection

Definition at line 436 of file JCollection.hh.

437  {
438  for (iterator i = this->begin(); i != this->end(); ++i) {
439  i->getY() = -i->getY();
440  }
441 
442  return *this;
443  }
JCollection& JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::add ( const JCollection< JElement2D< JKey_t, JValue_t >, JDistance_t > &  collection)
inlineinherited

Add collection.

Parameters
collectioncollection
Returns
this collection

Definition at line 452 of file JCollection.hh.

453  {
454  if (!collection.empty()) {
455 
456  if (this->empty()) {
457 
458  for (const_iterator i = collection.begin(); i != collection.end(); ++i) {
459  this->put(i->getX(), +i->getY());
460  }
461 
462  } else if (this->is_compatible(collection)) {
463 
464  const double precision = JDistance<abscissa_type>::precision;
465 
466  iterator p = this->begin();
467  const_iterator q = collection.begin();
468 
469  if (getDistance(p->getX(), q->getX()) > precision) {
470 
471  do {
472  ++p;
473  } while (p != this->end() && getDistance(p->getX(), q->getX()) > precision);
474 
475  } else if (getDistance(q->getX(), p->getX()) > precision) {
476 
477  do {
478  ++q;
479  } while (q != collection.end() && getDistance(q->getX(), p->getX()) > precision);
480  }
481 
482  const_iterator i = q;
483 
484  for ( ; p != this->end() && i != collection.end(); ++p, ++i) {
485  p->getY() += i->getY();
486  }
487 
488  for ( ; i != collection.end(); ++i) {
489  this->put(i->getX(), +i->getY());
490  }
491 
492  for (i = collection.begin(); i != q; ++i) {
493  this->put(i->getX(), +i->getY());
494  }
495  }
496  }
497 
498  return *this;
499  }
Template class for distance evaluation.
Definition: JDistance.hh:24
JDistance_t getDistance
Function object for distance evaluation.
Definition: JCollection.hh:773
bool is_compatible(const JCollection &collection) const
Test whether collections are compatible.
Definition: JCollection.hh:394
void put(typename JClass< key_type >::argument_type key, typename JClass< mapped_type >::argument_type value)
Put pair-wise element (key,value) into collection.
JCollection& JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::add ( typename JClass< ordinate_type >::argument_type  value)
inlineinherited

Add offset.

Parameters
valueoffset
Returns
this collection

Definition at line 600 of file JCollection.hh.

601  {
602  for (iterator i = this->begin(); i != this->end(); ++i) {
603  i->getY() += value;
604  }
605 
606  return *this;
607  }
JCollection& JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::add ( const JFunction1D_t &  function)
inlineinherited

Add function.

Parameters
functionfunction
Returns
this collection

Definition at line 633 of file JCollection.hh.

634  {
635  for (iterator i = this->begin(); i != this->end(); ++i) {
636  i->getY() += function(i->getX());
637  }
638 
639  return *this;
640  }
JCollection& JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::sub ( const JCollection< JElement2D< JKey_t, JValue_t >, JDistance_t > &  collection)
inlineinherited

Subtract collection.

Parameters
collectioncollection
Returns
this collection

Definition at line 508 of file JCollection.hh.

509  {
510  if (!collection.empty()) {
511 
512  if (this->empty()) {
513 
514  for (const_iterator i = collection.begin(); i != collection.end(); ++i) {
515  this->put(i->getX(), -i->getY());
516  }
517 
518  } else if (this->is_compatible(collection)) {
519 
520  const double precision = JDistance<abscissa_type>::precision;
521 
522  iterator p = this->begin();
523  const_iterator q = collection.begin();
524 
525  if (getDistance(p->getX(), q->getX()) > precision) {
526 
527  do {
528  ++p;
529  } while (p != this->end() && getDistance(p->getX(), q->getX()) > precision);
530 
531  } else if (getDistance(q->getX(), p->getX()) > precision) {
532 
533  do {
534  ++q;
535  } while (q != collection.end() && getDistance(q->getX(), p->getX()) > precision);
536  }
537 
538  const_iterator i = q;
539 
540  for ( ; p != this->end() && i != collection.end(); ++p, ++i) {
541  p->getY() -= i->getY();
542  }
543 
544  for ( ; i != collection.end(); ++i) {
545  this->put(i->getX(), -i->getY());
546  }
547 
548  for (i = collection.begin(); i != q; ++i) {
549  this->put(i->getX(), -i->getY());
550  }
551 
552  } else {
553 
554  THROW(JException, "JCollection::add() collections incompatible.");
555  }
556  }
557 
558  return *this;
559  }
General exception.
Definition: JException.hh:24
Template class for distance evaluation.
Definition: JDistance.hh:24
JDistance_t getDistance
Function object for distance evaluation.
Definition: JCollection.hh:773
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
bool is_compatible(const JCollection &collection) const
Test whether collections are compatible.
Definition: JCollection.hh:394
void put(typename JClass< key_type >::argument_type key, typename JClass< mapped_type >::argument_type value)
Put pair-wise element (key,value) into collection.
JCollection& JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::sub ( typename JClass< ordinate_type >::argument_type  value)
inlineinherited

Subtract offset.

Parameters
valueoffset
Returns
this collection

Definition at line 616 of file JCollection.hh.

617  {
618  for (iterator i = this->begin(); i != this->end(); ++i) {
619  i->getY() -= value;
620  }
621 
622  return *this;
623  }
JCollection& JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::sub ( const JFunction1D_t &  function)
inlineinherited

Subtract function.

Parameters
functionfunction
Returns
this collection

Definition at line 650 of file JCollection.hh.

651  {
652  for (iterator i = this->begin(); i != this->end(); ++i) {
653  i->getY() -= function(i->getX());
654  }
655 
656  return *this;
657  }
template<class JFirst_t, class JSecond_t = JNullType>
JFirst_t& JMATH::JMath< JFirst_t, JSecond_t >::mul ( const JSecond_t &  object)
inlineinherited

Multiply with object.

Parameters
objectobject
Returns
result object

Definition at line 354 of file JMath.hh.

355  {
356  return static_cast<JFirst_t&>(*this) = JFirst_t().mul(static_cast<const JFirst_t&>(*this), object);
357  }
const JComparator& JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::getComparator ( ) const
inlineinherited

Get comparator.

Returns
comparator

Definition at line 764 of file JCollection.hh.

765  {
766  return compare;
767  }
JComparator compare
Function object for comparison.
Definition: JCollection.hh:780
void JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::resize ( typename container_type::size_type  size)
inlineprotectedinherited

Resize collection.

Parameters
sizesize

Definition at line 788 of file JCollection.hh.

789  {
790  container_type::resize(size);
791  }
template<class JKey_t, class JValue_t>
const mapped_type& JTOOLS::JMappableCollection< JKey_t, JValue_t >::operator[] ( typename JClass< key_type >::argument_type  key) const
inlineinherited

Get mapped value.

Parameters
keykey
Returns
value

Definition at line 73 of file JMappableCollection.hh.

74  {
75  return get(key);
76  }
template<class JKey_t, class JValue_t>
mapped_type& JTOOLS::JMappableCollection< JKey_t, JValue_t >::operator[] ( typename JClass< key_type >::argument_type  key)
inlineinherited

Get mapped value.

Parameters
keykey
Returns
value

Definition at line 85 of file JMappableCollection.hh.

86  {
87  return get(key);
88  }
template<class JKey_t, class JValue_t>
void JTOOLS::JMappableCollection< JKey_t, JValue_t >::put ( typename JClass< key_type >::argument_type  key,
typename JClass< mapped_type >::argument_type  value 
)
inlineinherited

Put pair-wise element (key,value) into collection.

Parameters
keykey
valuevalue

Definition at line 97 of file JMappableCollection.hh.

99  {
100  get(key) = value;
101  }
template<class JAbscissa_t>
bool JTOOLS::JAbstractCollection< JAbscissa_t >::is_equal ( const JAbstractCollection< JAbscissa_t > &  collection) const
inlineinherited

Test whether abstract collections are equal.

Parameters
collectionabstract collection
Returns
true if collections are equals; else false

Definition at line 72 of file JAbstractCollection.hh.

73  {
74  if (this->getSize() == collection.getSize()) {
75 
76  for (int i = 0; i != this->getSize(); ++i) {
77 
78  if (this->getX(i) != collection.getX(i)) {
79  return false;
80  }
81  }
82 
83  return true;
84  }
85 
86  return false;
87  }
virtual abscissa_type getX(int index) const =0
Get abscissa value.
virtual int getSize() const =0
Get number of elements.
template<class JFirst_t, class JSecond_t = JNullType>
JFirst_t& JMATH::JMath< JFirst_t, JSecond_t >::mul ( const JSecond_t &  object)
inlineinherited

Multiply with object.

Parameters
objectobject
Returns
result object

Definition at line 354 of file JMath.hh.

355  {
356  return static_cast<JFirst_t&>(*this) = JFirst_t().mul(static_cast<const JFirst_t&>(*this), object);
357  }

Member Data Documentation

JDistance_t JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::getDistance
inherited

Function object for distance evaluation.

Definition at line 773 of file JCollection.hh.

JComparator JTOOLS::JCollection< JElement2D< JKey_t, JValue_t > , JDistance_t >::compare
protectedinherited

Function object for comparison.

Definition at line 780 of file JCollection.hh.


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