Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JMATH::JAverage< JValue_t > Struct Template Reference

Auxiliary class to determine average of set of values. More...

#include <JMath.hh>

Public Member Functions

 JAverage ()
 Default constructor.
 
template<class T >
 JAverage (T __begin, T __end)
 Constructor.
 
void reset ()
 Reset.
 
 operator JValue_t () const
 Type conversion operator.
 
void put (const JValue_t &value, const double w=1.0)
 Put value.
 

Private Attributes

JValue_t value
 
double weight
 

Detailed Description

template<class JValue_t>
struct JMATH::JAverage< JValue_t >

Auxiliary class to determine average of set of values.

Definition at line 409 of file JMath.hh.

Constructor & Destructor Documentation

◆ JAverage() [1/2]

template<class JValue_t >
JMATH::JAverage< JValue_t >::JAverage ( )
inline

Default constructor.

Definition at line 413 of file JMath.hh.

413 :
414 value (getZero<JValue_t>()),
415 weight(0.0)
416 {}
JValue_t value
Definition JMath.hh:474
double weight
Definition JMath.hh:475

◆ JAverage() [2/2]

template<class JValue_t >
template<class T >
JMATH::JAverage< JValue_t >::JAverage ( T __begin,
T __end )
inline

Constructor.

Parameters
__beginbegin of data
__endend of data

Definition at line 426 of file JMath.hh.

426 :
427 value (getZero<JValue_t>()),
428 weight(0.0)
429 {
430 for (T i = __begin; i != __end; ++i) {
431 value += (*i);
432 weight += 1.0;
433 }
434 }

Member Function Documentation

◆ reset()

template<class JValue_t >
void JMATH::JAverage< JValue_t >::reset ( )
inline

Reset.

Definition at line 440 of file JMath.hh.

441 {
442 this->value = getZero<JValue_t>();
443 this->weight = 0.0;
444 }
T getZero()
Get zero value for a given data type.
Definition JZero.hh:26

◆ operator JValue_t()

template<class JValue_t >
JMATH::JAverage< JValue_t >::operator JValue_t ( ) const
inline

Type conversion operator.

Returns
value

Definition at line 452 of file JMath.hh.

453 {
454 if (weight != 0.0)
455 return value * (1.0 / weight);
456 else
457 THROW(JDivisionByZero, "Invalid weight.");
458 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.

◆ put()

template<class JValue_t >
void JMATH::JAverage< JValue_t >::put ( const JValue_t & value,
const double w = 1.0 )
inline

Put value.

Parameters
valuevalue
wweight

Definition at line 467 of file JMath.hh.

468 {
469 this->value += value;
470 this->weight += w;
471 }

Member Data Documentation

◆ value

template<class JValue_t >
JValue_t JMATH::JAverage< JValue_t >::value
private

Definition at line 474 of file JMath.hh.

◆ weight

template<class JValue_t >
double JMATH::JAverage< JValue_t >::weight
private

Definition at line 475 of file JMath.hh.


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