Jpp
software
JMath
JCalculator.hh
Go to the documentation of this file.
1
#ifndef __JMATH__JCALCULATOR__
2
#define __JMATH__JCALCULATOR__
3
4
5
/**
6
* \author mdejong
7
*/
8
9
namespace
JMATH
{}
10
namespace
JPP
{
using namespace
JMATH
; }
11
12
namespace
JMATH
{
13
14
/**
15
* Auxiliary class for arithmetic operations on objects.
16
*/
17
template
<
class
T,
int
N = 0>
18
struct
JCalculator
:
19
public
T
// object
20
{
21
/**
22
* Set calculator value.
23
*
24
* \param value value
25
* \return this calculator
26
*/
27
JCalculator
&
set
(
const
T& value)
28
{
29
static_cast<T&>(*
this
) = value;
30
31
return
*
this
;
32
}
33
34
static
JCalculator
calculator
;
// calculator
35
};
36
37
38
/**
39
* Calculator.
40
*/
41
template
<
class
T,
int
N>
42
JCalculator<T,N>
JCalculator<T,N>::calculator
;
43
44
45
/**
46
* Product evaluation of objects.
47
*
48
* \param first first object
49
* \param second second object
50
* \return calculator
51
*/
52
template
<
class
T>
53
inline
const
JCalculator<T, 1>
&
operator*
(
const
T& first,
const
T& second)
54
{
55
JCalculator<T, 1>::calculator
.mul(first, second);
56
57
return
JCalculator<T, 1>::calculator
;
58
}
59
60
61
/**
62
* Recursive product evaluation of objects.
63
*
64
* \param first first object
65
* \param second second object
66
* \return calculator
67
*/
68
template
<
class
T,
int
N>
69
inline
const
JCalculator<T, N+1>
&
operator*
(
const
T& first,
const
JCalculator<T, N>
& second)
70
{
71
JCalculator<T, N+1>::calculator
.mul(first, second);
72
73
return
JCalculator<T, N+1>::calculator
;
74
}
75
76
77
/**
78
* Recursive product evaluation of objects.
79
*
80
* \param first first object
81
* \param second second object
82
* \return calculator
83
*/
84
template
<
class
T,
int
N>
85
inline
const
JCalculator<T, N+1>
&
operator*
(
const
JCalculator<T, N>
& first,
const
T& second)
86
{
87
JCalculator<T, N+1>::calculator
.mul(first, second);
88
89
return
JCalculator<T, N+1>::calculator
;
90
}
91
}
92
93
#endif
JMATH::operator*
const JCalculator< T, N+1 > & operator*(const JCalculator< T, N > &first, const T &second)
Recursive product evaluation of objects.
Definition:
JCalculator.hh:85
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition:
JAAnetToolkit.hh:37
JMATH::JCalculator::set
JCalculator & set(const T &value)
Set calculator value.
Definition:
JCalculator.hh:27
JMATH
Auxiliary classes and methods for mathematical operations.
Definition:
JCalculator.hh:9
JMATH::JCalculator::calculator
static JCalculator calculator
Calculator.
Definition:
JCalculator.hh:34
JMATH::JCalculator
Auxiliary class for arithmetic operations on objects.
Definition:
JCalculator.hh:18
Generated by
1.8.16