version 0.4.1
scalarwrapper.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
12#pragma once
13
14#include <dune/common/referencehelper.hh>
15
25template <typename T>
27{
33 : val{val} {}
34
35 using RawScalarType = Dune::ResolveRef_t<T>;
36
41 operator RawScalarType&() const { return Dune::resolveRef(val); }
42
47 const RawScalarType& value() const { return Dune::resolveRef(val); }
48
53 RawScalarType& value() { return Dune::resolveRef(val); }
54
61 return RawScalarType{Dune::resolveRef(val) + Dune::resolveRef(v.val)};
62 }
69 return RawScalarType{Dune::resolveRef(val) - Dune::resolveRef(v.val)};
70 }
71
76 RawScalarType operator-() const { return RawScalarType{-Dune::resolveRef(val)}; }
77
84
91 Dune::resolveRef(val) += Dune::resolveRef(v.val);
92 return *this;
93 }
94
101 Dune::resolveRef(val) -= Dune::resolveRef(v.val);
102 return *this;
103 }
104
111 Dune::resolveRef(val) *= v;
112 return *this;
113 }
114
121 Dune::resolveRef(val) /= v;
122 return *this;
123 }
124
125private:
126 T val;
127
135 return RawScalarType{f * Dune::resolveRef(v.val)};
136 }
137};
A wrapper class for scalar types to facilitate reference passing in Python bindings.
Definition: scalarwrapper.hh:27
RawScalarType operator*(RawScalarType value) const
Multiplies the wrapped scalar value by another value.
Definition: scalarwrapper.hh:83
const RawScalarType & value() const
Gets the wrapped scalar value as a constant reference.
Definition: scalarwrapper.hh:47
RawScalarType operator-(const ScalarWrapper &v) const
Subtracts the value of another ScalarWrapper from this instance.
Definition: scalarwrapper.hh:68
ScalarWrapper & operator-=(const ScalarWrapper &v)
Subtracts another ScalarWrapper's value from this instance.
Definition: scalarwrapper.hh:100
RawScalarType & value()
Gets the wrapped scalar value as a reference.
Definition: scalarwrapper.hh:53
RawScalarType operator+(const ScalarWrapper &v) const
Adds the values of two ScalarWrapper instances. This returns the raw type since this makes makes no s...
Definition: scalarwrapper.hh:60
ScalarWrapper(T val)
Constructs a ScalarWrapper with the given value.
Definition: scalarwrapper.hh:32
friend RawScalarType operator*(RawScalarType f, const ScalarWrapper &v)
Multiplies a scalar value by a ScalarWrapper's value.
Definition: scalarwrapper.hh:134
ScalarWrapper & operator/=(RawScalarType v)
Divides the wrapped scalar value by another value and assigns the result.
Definition: scalarwrapper.hh:120
ScalarWrapper & operator*=(RawScalarType v)
Multiplies the wrapped scalar value by another value and assigns the result.
Definition: scalarwrapper.hh:110
ScalarWrapper & operator+=(const ScalarWrapper &v)
Adds another ScalarWrapper's value to this instance.
Definition: scalarwrapper.hh:90
Dune::ResolveRef_t< T > RawScalarType
Definition: scalarwrapper.hh:35
RawScalarType operator-() const
Negates the wrapped scalar value.
Definition: scalarwrapper.hh:76