Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JTOOLS::JCollection< JElement_t, JDistance_t > Class Template Reference

General purpose class for collection of elements, see: Collection of elements. . More...

#include <JCollection.hh>

Inheritance diagram for JTOOLS::JCollection< JElement_t, JDistance_t >:
std::vector< JElement_t > JTOOLS::JMappableCollection< JElement_t::abscissa_type, JElement_t::ordinate_type > JTOOLS::JAbstractCollection< JElement_t::abscissa_type > JMATH::JMath< JFirst_t, JSecond_t > JTOOLS::JGridCollection< JElement_t, JDistance_t > JTOOLS::JGridCollection< JElement_t, JDistance_t > JTOOLS::JMap< JKey_t, JValue_t, JDistance_t > JTOOLS::JMapCollection< JMap >::collection_type JTOOLS::JMapCollection< JGridMap >::collection_type JTOOLS::JGridMap< JKey_t, JValue_t, JDistance_t >

Classes

struct  JComparator
 Auxiliary class for ordering of objects in the collection by their abscissa values. More...
 

Public Types

typedef JElement_t::abscissa_type abscissa_type
 
typedef JElement_t::ordinate_type ordinate_type
 
typedef JElement_t value_type
 
typedef JDistance_t distance_type
 
typedef JCollection< JElement_t, JDistance_t > collection_type
 
typedef std::vector< value_typecontainer_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 JCollectionElementTransformer< value_typetransformer_type
 
typedef std::pair< const_iterator, bool > pair_type
 
typedef JElement_t::abscissa_type key_type
 
typedef JElement_t::ordinate_type mapped_type
 

Public Member Functions

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

Public Attributes

JDistance_t getDistance
 Function object for distance evaluation.
 

Protected Member Functions

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

Protected Attributes

JComparator compare
 Function object for comparison.
 

Private Member Functions

void erase ()
 
void push_back ()
 
void pop_back ()
 

Friends

JCollectionoperator+= (JCollection &collection, typename JClass< ordinate_type >::argument_type value)
 Add offset to collaction.
 
JCollectionoperator-= (JCollection &collection, typename JClass< ordinate_type >::argument_type value)
 Subtract offset from collaction.
 
template<class JFunction1D_t >
JCollectionoperator+= (JCollection &collection, const JFunction1D_t &function)
 Add function.
 
template<class JFunction1D_t >
JCollectionoperator-= (JCollection &collection, const JFunction1D_t &function)
 Subtract function.
 
JReaderoperator>> (JReader &in, JCollection &collection)
 Read collection from input.
 
JWriteroperator<< (JWriter &out, const JCollection &collection)
 Write collection to output.
 

Detailed Description

template<class JElement_t, class JDistance_t>
class JTOOLS::JCollection< JElement_t, JDistance_t >

General purpose class for collection of elements, see: Collection of elements. .

This class implements the JMappableCollection and JAbstractCollection interfaces.

The data type of the elements of the collection should have the following policy type definition and member methods.

     typedef <abscissa type>   abscissa_type;
     typedef <ordinate type>   ordinate_type;

     (constructor)(abscissa_type, ordinate_type);

     abscissa_type  getX() const;
     ordinate_type  getY() const;
     ordinate_type& getY();
  

The elements in a collection are sorted according to their abscissa values and the given distance operator. The distance operator constitues a binary method returning the distance between two abscissa values; The default distance operator is JDistance.

For the binary I/O of a collection of elements, the data structure of the elements should provide for an implementation of the following operators:

        JReader& operator>>(JReader& in);
        JWriter& operator<<(JWriter& out);
  

Definition at line 22 of file JSet.hh.

Member Typedef Documentation

◆ abscissa_type

template<class JElement_t , class JDistance_t >
JElement_t::abscissa_type JTOOLS::JCollection< JElement_t, JDistance_t >::abscissa_type

Definition at line 82 of file JCollection.hh.

◆ ordinate_type

template<class JElement_t , class JDistance_t >
JElement_t::ordinate_type JTOOLS::JCollection< JElement_t, JDistance_t >::ordinate_type

Definition at line 83 of file JCollection.hh.

◆ value_type

template<class JElement_t , class JDistance_t >
JElement_t JTOOLS::JCollection< JElement_t, JDistance_t >::value_type

Definition at line 84 of file JCollection.hh.

◆ distance_type

template<class JElement_t , class JDistance_t >
JDistance_t JTOOLS::JCollection< JElement_t, JDistance_t >::distance_type

Definition at line 85 of file JCollection.hh.

◆ collection_type

template<class JElement_t , class JDistance_t >
JCollection<JElement_t, JDistance_t> JTOOLS::JCollection< JElement_t, JDistance_t >::collection_type

Definition at line 87 of file JCollection.hh.

◆ container_type

template<class JElement_t , class JDistance_t >
std::vector<value_type> JTOOLS::JCollection< JElement_t, JDistance_t >::container_type

Definition at line 89 of file JCollection.hh.

◆ const_iterator

template<class JElement_t , class JDistance_t >
container_type::const_iterator JTOOLS::JCollection< JElement_t, JDistance_t >::const_iterator

Definition at line 91 of file JCollection.hh.

◆ const_reverse_iterator

template<class JElement_t , class JDistance_t >
container_type::const_reverse_iterator JTOOLS::JCollection< JElement_t, JDistance_t >::const_reverse_iterator

Definition at line 92 of file JCollection.hh.

◆ iterator

template<class JElement_t , class JDistance_t >
container_type::iterator JTOOLS::JCollection< JElement_t, JDistance_t >::iterator

Definition at line 93 of file JCollection.hh.

◆ reverse_iterator

template<class JElement_t , class JDistance_t >
container_type::reverse_iterator JTOOLS::JCollection< JElement_t, JDistance_t >::reverse_iterator

Definition at line 94 of file JCollection.hh.

◆ transformer_type

template<class JElement_t , class JDistance_t >
JCollectionElementTransformer<value_type> JTOOLS::JCollection< JElement_t, JDistance_t >::transformer_type

Definition at line 96 of file JCollection.hh.

◆ pair_type

template<class JElement_t , class JDistance_t >
std::pair<const_iterator, bool> JTOOLS::JCollection< JElement_t, JDistance_t >::pair_type

Definition at line 97 of file JCollection.hh.

◆ key_type

JElement_t::abscissa_type JTOOLS::JMappableCollection< JElement_t::abscissa_type, JElement_t::ordinate_type >::key_type
inherited

Definition at line 33 of file JMappableCollection.hh.

◆ mapped_type

JElement_t::ordinate_type JTOOLS::JMappableCollection< JElement_t::abscissa_type, JElement_t::ordinate_type >::mapped_type
inherited

Definition at line 34 of file JMappableCollection.hh.

Constructor & Destructor Documentation

◆ JCollection()

template<class JElement_t , class JDistance_t >
JTOOLS::JCollection< JElement_t, JDistance_t >::JCollection ( )
inline

Default constructor.

Definition at line 143 of file JCollection.hh.

144 {}

Member Function Documentation

◆ clear()

template<class JElement_t , class JDistance_t >
virtual void JTOOLS::JCollection< JElement_t, JDistance_t >::clear ( )
inlineoverridevirtual

Clear.

Implements JTOOLS::JMappableCollection< JElement_t::abscissa_type, JElement_t::ordinate_type >.

Definition at line 150 of file JCollection.hh.

151 {
152 container_type::clear();
153 }

◆ get() [1/2]

template<class JElement_t , class JDistance_t >
virtual const ordinate_type & JTOOLS::JCollection< JElement_t, JDistance_t >::get ( typename JClass< abscissa_type >::argument_type x) const
inlineoverridevirtual

Get ordinate value.

Parameters
xabscissa value
Returns
ordinate value

Implements JTOOLS::JMappableCollection< JElement_t::abscissa_type, JElement_t::ordinate_type >.

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 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
JDistance_t getDistance
Function object for distance evaluation.
container_type::const_iterator const_iterator
const_iterator lower_bound(typename JClass< abscissa_type >::argument_type x) const
Get first position of element i, where x >= i->getX().

◆ get() [2/2]

template<class JElement_t , class JDistance_t >
virtual ordinate_type & JTOOLS::JCollection< JElement_t, JDistance_t >::get ( typename JClass< abscissa_type >::argument_type x)
inlineoverridevirtual

Get ordinate value.

Parameters
xabscissa value
Returns
ordinate value

Implements JTOOLS::JMappableCollection< JElement_t::abscissa_type, JElement_t::ordinate_type >.

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 }
JElement_t value_type
container_type::iterator iterator
T getZero()
Get zero value for a given data type.
Definition JZero.hh:26

◆ getSize()

template<class JElement_t , class JDistance_t >
virtual int JTOOLS::JCollection< JElement_t, JDistance_t >::getSize ( ) const
inlineoverridevirtual

Get number of elements.

Returns
number of elements

Implements JTOOLS::JAbstractCollection< JElement_t::abscissa_type >.

Definition at line 197 of file JCollection.hh.

198 {
199 return (int) this->size();
200 }

◆ getX()

template<class JElement_t , class JDistance_t >
virtual abscissa_type JTOOLS::JCollection< JElement_t, JDistance_t >::getX ( int index) const
inlineoverridevirtual

Get abscissa value.

Parameters
indexindex
Returns
abscissa value

Implements JTOOLS::JAbstractCollection< JElement_t::abscissa_type >.

Definition at line 209 of file JCollection.hh.

210 {
211 return this->at(index).getX();
212 }

◆ getXmin()

template<class JElement_t , class JDistance_t >
virtual abscissa_type JTOOLS::JCollection< JElement_t, JDistance_t >::getXmin ( ) const
inlineoverridevirtual

Get minimal abscissa value.

Returns
abscissa value

Implements JTOOLS::JAbstractCollection< JElement_t::abscissa_type >.

Definition at line 220 of file JCollection.hh.

221 {
222 return this->begin()->getX();
223 }

◆ getXmax()

template<class JElement_t , class JDistance_t >
virtual abscissa_type JTOOLS::JCollection< JElement_t, JDistance_t >::getXmax ( ) const
inlineoverridevirtual

Get maximal abscissa value.

Returns
abscissa value

Implements JTOOLS::JAbstractCollection< JElement_t::abscissa_type >.

Definition at line 231 of file JCollection.hh.

232 {
233 return this->rbegin()->getX();
234 }

◆ getY() [1/2]

template<class JElement_t , class JDistance_t >
const ordinate_type & JTOOLS::JCollection< JElement_t, JDistance_t >::getY ( int index) const
inline

Get ordinate value.

Parameters
indexindex
Returns
ordinate value

Definition at line 244 of file JCollection.hh.

245 {
246 return this->at(index).getY();
247 }

◆ getY() [2/2]

template<class JElement_t , class JDistance_t >
ordinate_type & JTOOLS::JCollection< JElement_t, JDistance_t >::getY ( int index)
inline

Get ordinate value.

Parameters
indexindex
Returns
ordinate value

Definition at line 256 of file JCollection.hh.

257 {
258 return this->at(index).getY();
259 }

◆ transform()

template<class JElement_t , class JDistance_t >
void JTOOLS::JCollection< JElement_t, JDistance_t >::transform ( const transformer_type & transformer)
inline

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 sort()
Sort elements.

◆ sort()

template<class JElement_t , class JDistance_t >
void JTOOLS::JCollection< JElement_t, JDistance_t >::sort ( )
inline

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.

◆ lower_bound() [1/2]

template<class JElement_t , class JDistance_t >
const_iterator JTOOLS::JCollection< JElement_t, JDistance_t >::lower_bound ( typename JClass< abscissa_type >::argument_type x) const
inline

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 }

◆ lower_bound() [2/2]

template<class JElement_t , class JDistance_t >
iterator JTOOLS::JCollection< JElement_t, JDistance_t >::lower_bound ( typename JClass< abscissa_type >::argument_type x)
inline

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 }

◆ insert()

template<class JElement_t , class JDistance_t >
pair_type JTOOLS::JCollection< JElement_t, JDistance_t >::insert ( const value_type & element)
inline

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 }
std::pair< const_iterator, bool > pair_type

◆ configure() [1/3]

template<class JElement_t , class JDistance_t >
void JTOOLS::JCollection< JElement_t, JDistance_t >::configure ( const JAbstractCollection< abscissa_type > & bounds)
inline

Configure collection.

Parameters
boundsabscissa values

Definition at line 332 of file JCollection.hh.

333 {
335 }
void configure(const JAbstractCollection< abscissa_type > &bounds)
Configure collection.

◆ configure() [2/3]

template<class JElement_t , class JDistance_t >
void JTOOLS::JCollection< JElement_t, JDistance_t >::configure ( const JAbstractCollection< abscissa_type > & bounds,
typename JClass< ordinate_type >::argument_type value )
inline

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 }
void resize(typename container_type::size_type size)
Resize collection.
JElement_t::abscissa_type abscissa_type

◆ configure() [3/3]

template<class JElement_t , class JDistance_t >
template<class JFunction1D_t >
void JTOOLS::JCollection< JElement_t, JDistance_t >::configure ( const JAbstractCollection< abscissa_type > & bounds,
const JFunction1D_t & function )
inline

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< JElement_t, JDistance_t > collection_type
Auxiliary classes and methods for language specific functionality.
bool is_identical(JFirst_t &first, JSecond_t &second)
Check if two objects are indentical.

◆ is_compatible()

template<class JElement_t , class JDistance_t >
bool JTOOLS::JCollection< JElement_t, JDistance_t >::is_compatible ( const JCollection< JElement_t, JDistance_t > & collection) const
inline

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 }
static double precision
Default precision.
Definition JDistance.hh:44

◆ in_range()

template<class JElement_t , class JDistance_t >
bool JTOOLS::JCollection< JElement_t, JDistance_t >::in_range ( typename JClass< abscissa_type >::argument_type x) const
inline

Check if given abscissa is in range of this collection.

Parameters
xabscissa value
Returns
true if in tange: else false

Definition at line 437 of file JCollection.hh.

438 {
439 if (!this->empty())
440 return (this->getDistance(this->getXmin(), x) >= 0.0 &&
441 this->getDistance(this->getXmax(), x) <= 0.0);
442 else
443 return false;
444 }
virtual abscissa_type getXmin() const override
Get minimal abscissa value.
virtual abscissa_type getXmax() const override
Get maximal abscissa value.

◆ negate()

template<class JElement_t , class JDistance_t >
JCollection & JTOOLS::JCollection< JElement_t, JDistance_t >::negate ( )
inline

Negate collection.

Returns
this collection

Definition at line 452 of file JCollection.hh.

453 {
454 for (iterator i = this->begin(); i != this->end(); ++i) {
455 i->getY() = -i->getY();
456 }
457
458 return *this;
459 }

◆ add() [1/3]

template<class JElement_t , class JDistance_t >
JCollection & JTOOLS::JCollection< JElement_t, JDistance_t >::add ( const JCollection< JElement_t, JDistance_t > & collection)
inline

Add collection.

Parameters
collectioncollection
Returns
this collection

Definition at line 468 of file JCollection.hh.

469 {
470 if (!collection.empty()) {
471
472 if (this->empty()) {
473
474 for (const_iterator i = collection.begin(); i != collection.end(); ++i) {
475 this->put(i->getX(), +i->getY());
476 }
477
478 } else if (this->is_compatible(collection)) {
479
480 const double precision = JDistance<abscissa_type>::precision;
481
482 iterator p = this->begin();
483 const_iterator q = collection.begin();
484
485 if (getDistance(p->getX(), q->getX()) > precision) {
486
487 do {
488 ++p;
489 } while (p != this->end() && getDistance(p->getX(), q->getX()) > precision);
490
491 } else if (getDistance(q->getX(), p->getX()) > precision) {
492
493 do {
494 ++q;
495 } while (q != collection.end() && getDistance(q->getX(), p->getX()) > precision);
496 }
497
498 const_iterator i = q;
499
500 for ( ; p != this->end() && i != collection.end(); ++p, ++i) {
501 p->getY() += i->getY();
502 }
503
504 for ( ; i != collection.end(); ++i) {
505 this->put(i->getX(), +i->getY());
506 }
507
508 for (i = collection.begin(); i != q; ++i) {
509 this->put(i->getX(), +i->getY());
510 }
511 }
512 }
513
514 return *this;
515 }
bool is_compatible(const JCollection &collection) const
Test whether collections are compatible.
void put(typename JClass< key_type > ::argument_type key, typename JClass< mapped_type >::argument_type value)

◆ sub() [1/3]

template<class JElement_t , class JDistance_t >
JCollection & JTOOLS::JCollection< JElement_t, JDistance_t >::sub ( const JCollection< JElement_t, JDistance_t > & collection)
inline

Subtract collection.

Parameters
collectioncollection
Returns
this collection

Definition at line 524 of file JCollection.hh.

525 {
526 if (!collection.empty()) {
527
528 if (this->empty()) {
529
530 for (const_iterator i = collection.begin(); i != collection.end(); ++i) {
531 this->put(i->getX(), -i->getY());
532 }
533
534 } else if (this->is_compatible(collection)) {
535
536 const double precision = JDistance<abscissa_type>::precision;
537
538 iterator p = this->begin();
539 const_iterator q = collection.begin();
540
541 if (getDistance(p->getX(), q->getX()) > precision) {
542
543 do {
544 ++p;
545 } while (p != this->end() && getDistance(p->getX(), q->getX()) > precision);
546
547 } else if (getDistance(q->getX(), p->getX()) > precision) {
548
549 do {
550 ++q;
551 } while (q != collection.end() && getDistance(q->getX(), p->getX()) > precision);
552 }
553
554 const_iterator i = q;
555
556 for ( ; p != this->end() && i != collection.end(); ++p, ++i) {
557 p->getY() -= i->getY();
558 }
559
560 for ( ; i != collection.end(); ++i) {
561 this->put(i->getX(), -i->getY());
562 }
563
564 for (i = collection.begin(); i != q; ++i) {
565 this->put(i->getX(), -i->getY());
566 }
567
568 } else {
569
570 THROW(JException, "JCollection::add() collections incompatible.");
571 }
572 }
573
574 return *this;
575 }

◆ mul() [1/2]

template<class JElement_t , class JDistance_t >
JCollection & JTOOLS::JCollection< JElement_t, JDistance_t >::mul ( const double value)
inline

Scale contents.

Parameters
valuemultiplication factor
Returns
this collection

Definition at line 584 of file JCollection.hh.

585 {
586 for (iterator i = this->begin(); i != this->end(); ++i) {
587 i->getY() *= value;
588 }
589
590 return *this;
591 }

◆ div()

template<class JElement_t , class JDistance_t >
JCollection & JTOOLS::JCollection< JElement_t, JDistance_t >::div ( const double value)
inline

Scale contents.

Parameters
valuedivision factor
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 }

◆ add() [2/3]

template<class JElement_t , class JDistance_t >
JCollection & JTOOLS::JCollection< JElement_t, JDistance_t >::add ( typename JClass< ordinate_type >::argument_type value)
inline

Add 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 }

◆ sub() [2/3]

template<class JElement_t , class JDistance_t >
JCollection & JTOOLS::JCollection< JElement_t, JDistance_t >::sub ( typename JClass< ordinate_type >::argument_type value)
inline

Subtract offset.

Parameters
valueoffset
Returns
this collection

Definition at line 632 of file JCollection.hh.

633 {
634 for (iterator i = this->begin(); i != this->end(); ++i) {
635 i->getY() -= value;
636 }
637
638 return *this;
639 }

◆ add() [3/3]

template<class JElement_t , class JDistance_t >
template<class JFunction1D_t >
JCollection & JTOOLS::JCollection< JElement_t, JDistance_t >::add ( const JFunction1D_t & function)
inline

Add function.

Parameters
functionfunction
Returns
this collection

Definition at line 649 of file JCollection.hh.

650 {
651 for (iterator i = this->begin(); i != this->end(); ++i) {
652 i->getY() += function(i->getX());
653 }
654
655 return *this;
656 }

◆ sub() [3/3]

template<class JElement_t , class JDistance_t >
template<class JFunction1D_t >
JCollection & JTOOLS::JCollection< JElement_t, JDistance_t >::sub ( const JFunction1D_t & function)
inline

Subtract function.

Parameters
functionfunction
Returns
this collection

Definition at line 666 of file JCollection.hh.

667 {
668 for (iterator i = this->begin(); i != this->end(); ++i) {
669 i->getY() -= function(i->getX());
670 }
671
672 return *this;
673 }

◆ getComparator()

template<class JElement_t , class JDistance_t >
const JComparator & JTOOLS::JCollection< JElement_t, JDistance_t >::getComparator ( ) const
inline

Get comparator.

Returns
comparator

Definition at line 780 of file JCollection.hh.

781 {
782 return compare;
783 }

◆ resize()

template<class JElement_t , class JDistance_t >
void JTOOLS::JCollection< JElement_t, JDistance_t >::resize ( typename container_type::size_type size)
inlineprotected

Resize collection.

Parameters
sizesize

Definition at line 804 of file JCollection.hh.

805 {
806 container_type::resize(size);
807 }

◆ erase()

template<class JElement_t , class JDistance_t >
void JTOOLS::JCollection< JElement_t, JDistance_t >::erase ( )
private

◆ push_back()

template<class JElement_t , class JDistance_t >
void JTOOLS::JCollection< JElement_t, JDistance_t >::push_back ( )
private

◆ pop_back()

template<class JElement_t , class JDistance_t >
void JTOOLS::JCollection< JElement_t, JDistance_t >::pop_back ( )
private

◆ operator[]() [1/2]

const mapped_type & JTOOLS::JMappableCollection< JElement_t::abscissa_type, JElement_t::ordinate_type >::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 }

◆ operator[]() [2/2]

mapped_type & JTOOLS::JMappableCollection< JElement_t::abscissa_type, JElement_t::ordinate_type >::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 }

◆ put()

void JTOOLS::JMappableCollection< JElement_t::abscissa_type, JElement_t::ordinate_type >::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 }

◆ is_equal()

bool JTOOLS::JAbstractCollection< JElement_t::abscissa_type >::is_equal ( const JAbstractCollection< JElement_t::abscissa_type > & 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

◆ mul() [2/2]

template<class JFirst_t , class JSecond_t >
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 }

Friends And Related Symbol Documentation

◆ operator+= [1/2]

template<class JElement_t , class JDistance_t >
JCollection & operator+= ( JCollection< JElement_t, JDistance_t > & collection,
typename JClass< ordinate_type >::argument_type value )
friend

Add offset to collaction.

Parameters
collectioncollection
valueoffset
Returns
collection

Definition at line 683 of file JCollection.hh.

684 {
685 return collection.add(value);
686 }

◆ operator-= [1/2]

template<class JElement_t , class JDistance_t >
JCollection & operator-= ( JCollection< JElement_t, JDistance_t > & collection,
typename JClass< ordinate_type >::argument_type value )
friend

Subtract offset from collaction.

Parameters
collectioncollection
valueoffset
Returns
collection

Definition at line 696 of file JCollection.hh.

697 {
698 return collection.sub(value);
699 }

◆ operator+= [2/2]

template<class JElement_t , class JDistance_t >
template<class JFunction1D_t >
JCollection & operator+= ( JCollection< JElement_t, JDistance_t > & collection,
const JFunction1D_t & function )
friend

Add function.

Parameters
collectioncollection
functionfunction
Returns
this collection

Definition at line 710 of file JCollection.hh.

711 {
712 return collection.add(function);
713 }

◆ operator-= [2/2]

template<class JElement_t , class JDistance_t >
template<class JFunction1D_t >
JCollection & operator-= ( JCollection< JElement_t, JDistance_t > & collection,
const JFunction1D_t & function )
friend

Subtract function.

Parameters
collectioncollection
functionfunction
Returns
this collection

Definition at line 724 of file JCollection.hh.

725 {
726 return collection.sub(function);
727 }

◆ operator>>

template<class JElement_t , class JDistance_t >
JReader & operator>> ( JReader & in,
JCollection< JElement_t, JDistance_t > & collection )
friend

Read collection from input.

Parameters
inreader
collectioncollection
Returns
reader

Definition at line 737 of file JCollection.hh.

738 {
739 int n;
740
741 if (in >> n) {
742
743 collection.resize(n);
744
745 for (typename JCollection::iterator i = collection.begin(); i != collection.end(); ++i) {
746 in >> *i;
747 }
748 }
749
750 return in;
751 }
const int n
Definition JPolint.hh:791

◆ operator<<

template<class JElement_t , class JDistance_t >
JWriter & operator<< ( JWriter & out,
const JCollection< JElement_t, JDistance_t > & collection )
friend

Write collection to output.

Parameters
outwriter
collectioncollection
Returns
writer

Definition at line 761 of file JCollection.hh.

762 {
763 const int n = collection.size();
764
765 out << n;
766
767 for (typename JCollection::const_iterator i = collection.begin(); i != collection.end(); ++i) {
768 out << *i;
769 }
770
771 return out;
772 }

Member Data Documentation

◆ getDistance

template<class JElement_t , class JDistance_t >
JDistance_t JTOOLS::JCollection< JElement_t, JDistance_t >::getDistance

Function object for distance evaluation.

Definition at line 789 of file JCollection.hh.

◆ compare

template<class JElement_t , class JDistance_t >
JComparator JTOOLS::JCollection< JElement_t, JDistance_t >::compare
protected

Function object for comparison.

Definition at line 796 of file JCollection.hh.


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