YAP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IntegralElement.h
Go to the documentation of this file.
1 /* YAP - Yet another PWA toolkit
2  Copyright 2015, Technische Universitaet Muenchen,
3  Authors: Daniel Greenwald, Johannes Rauch
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
20 
21 #ifndef yap_IntegralElement_h
22 #define yap_IntegralElement_h
23 
24 #include "fwd/IntegralElement.h"
25 
26 #include "complex_to_string.h"
27 
28 namespace yap {
29 
34 template <typename T>
36 {
37 public:
38 
41  explicit IntegralElement(T val = 0) : Value_(val) {}
42 
44  void reset()
45  { Value_ = 0; }
46 
48  const T value() const
49  { return Value_; }
50 
52  T& value()
53  { return Value_; }
54 
56  template <typename U>
57  IntegralElement& operator*=(const U& rhs)
58  { Value_ *= rhs; return *this; }
59 
62  { Value_ += B.Value_; return *this; }
63 
66  { Value_ *= -1; return *this; }
67 
70  { return *this += -B; }
71 
74  { Value_ *= B.Value_; return *this; }
75 
78  { Value_ /= B.Value_; return *this; }
79 
81  template <typename U>
82  friend const IntegralElement operator*(IntegralElement A, const U& B)
83  { return A *= B; }
84 
86  template <typename U>
87  friend const IntegralElement operator*(const U& A, IntegralElement B)
88  { return operator*(B, A); }
89 
91  explicit operator T() const
92  { return value; }
93 
95  template <typename U>
96  explicit operator std::complex<U>() const
97  { return static_cast<std::complex<U> >(Value_); }
98 
100  template <typename U>
101  explicit operator IntegralElement<std::complex<U> >() const
102  { return IntegralElement<std::complex<U> >(static_cast<std::complex<U> >(Value_)); }
103 
104 private:
105 
108 
109 };
110 
112 template <typename T>
114 { return A += B; }
115 
117 template <typename T>
119 { return A -= B; }
120 
122 template <typename T>
124 { return A *= B; }
125 
127 template <typename T>
129 { return A /= B; }
130 
132 template <typename T>
133 inline std::string to_string(const IntegralElement<T>& a)
134 { using std::to_string; return to_string(a.value()); }
135 
138 
140 inline ComplexIntegralElement conj(const ComplexIntegralElement& Z)
141 { return ComplexIntegralElement(conj(Z.value())); }
142 
144 inline RealIntegralElement real(const ComplexIntegralElement& Z)
145 { return RealIntegralElement(real(Z.value())); }
146 
148 inline RealIntegralElement imag(const ComplexIntegralElement& Z)
149 { return RealIntegralElement(imag(Z.value())); }
150 
152 
153 
154 }
155 
156 #endif
RealIntegralElement real(const ComplexIntegralElement &Z)
Definition: IntegralElement.h:144
IntegralElement(T val=0)
Definition: IntegralElement.h:41
T Value_
integral value
Definition: IntegralElement.h:107
const IntegralElement< T > operator/(IntegralElement< T > A, const IntegralElement< T > &B)
Definition: IntegralElement.h:128
IntegralElement & operator-=(const IntegralElement &B)
subtraction assignment operator
Definition: IntegralElement.h:69
friend const IntegralElement operator*(const U &A, IntegralElement B)
multiplication operator
Definition: IntegralElement.h:87
T & value()
access value
Definition: IntegralElement.h:52
ComplexIntegralElement conj(const ComplexIntegralElement &Z)
Definition: IntegralElement.h:140
IntegralElement & operator*=(const IntegralElement &B)
multiplication assignment operator
Definition: IntegralElement.h:73
void reset()
reset
Definition: IntegralElement.h:44
Holds the values of a component of an integral.
Definition: IntegralElement.h:35
IntegralElement & operator-() const
unary minus operator
Definition: IntegralElement.h:65
const DataIterator operator-(const DataIterator &lhs, DataIterator::difference_type n)
subraction operator
Definition: DataPartition.h:139
IntegralElement & operator/=(const IntegralElement &B)
division assignment operator
Definition: IntegralElement.h:77
IntegralElement & operator+=(const IntegralElement &B)
addition assignment operator
Definition: IntegralElement.h:61
std::string to_string(const IntegralElement< T > &a)
Definition: IntegralElement.h:133
const CoordinateSystem< T, N > operator*(const SquareMatrix< T, N > &M, const CoordinateSystem< T, N > &C)
Definition: CoordinateSystem.h:62
const T value() const
access value
Definition: IntegralElement.h:48
std::string to_string(const CachedValue::Status &S)
streaming operator for CachedValue::Status
Definition: CachedValue.cxx:27
const DataIterator operator+(DataIterator lhs, DataIterator::difference_type n)
addition operator
Definition: DataPartition.h:131
friend const IntegralElement operator*(IntegralElement A, const U &B)
multiplication operator
Definition: IntegralElement.h:82
RealIntegralElement imag(const ComplexIntegralElement &Z)
Definition: IntegralElement.h:148
IntegralElement & operator*=(const U &rhs)
multiplication (by T) assignment operator
Definition: IntegralElement.h:57