parameter_accessor.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_PARAMETER_ACCESSOR_H
21 #define LIBMESH_PARAMETER_ACCESSOR_H
22 
23 
24 // Local Includes
25 #include "libmesh/libmesh_common.h"
26 #include "libmesh/compare_types.h" // remove_const
27 #include "libmesh/auto_ptr.h" // deprecated
28 
29 // C++ includes
30 #include <memory>
31 
32 namespace libMesh
33 {
34 
35 // Forward declarations
36 template <typename T>
38 
39 template <typename T>
41 
42 
55 template <typename T=Number>
57 {
58 public:
63  virtual ~ParameterAccessor() {}
64 
68  virtual void set (const T & new_value) = 0;
69 
73  virtual const T & get () const = 0;
74 
80 #ifdef LIBMESH_ENABLE_DEPRECATED
81  virtual ParameterAccessor<T> &
82  operator= (T * /* new_ptr */) { libmesh_error(); return *this; }
83 #endif
84 
92 
94 
100  virtual std::unique_ptr<ParameterAccessor<T>> clone() const = 0;
101 };
102 
103 template <typename T=Number>
104 class ParameterProxy
105 {
106 public:
111  : _accessor(accessor) {}
112 
116  ParameterProxy & operator = (const T & new_value) { _accessor.set(new_value); return *this; }
117 
121  ParameterProxy & operator = (const ParameterProxy<T> & new_value) { _accessor.set(new_value.get()); }
122 
126  ParameterProxy & operator = (const ConstParameterProxy<T> & new_value) { _accessor.set(new_value.get()); return *this; }
127 
131  ParameterProxy & operator += (const T & value_increment) { _accessor.set(_accessor.get() + value_increment); return *this; }
132 
136  ParameterProxy & operator -= (const T & value_decrement) { _accessor.set(_accessor.get() - value_decrement); return *this; }
137 
141  ParameterProxy & operator *= (const T & value_multiplier) { _accessor.set(_accessor.get() * value_multiplier); return *this; }
142 
146  ParameterProxy & operator /= (const T & value_divisor) { _accessor.set(_accessor.get() / value_divisor); return *this; }
147 
151  operator T () const { return _accessor.get(); }
152 
153 private:
155 };
156 
157 
158 template <typename T=Number>
160 {
161 public:
166  : _accessor(accessor) {}
167 
171  operator T () const { return _accessor.get(); }
172 
176  T get() const { return _accessor.get(); }
177 
178 private:
180 };
181 
182 
183 } // namespace libMesh
184 
185 #endif // LIBMESH_PARAMETER_ACCESSOR_H
ParameterProxy & operator*=(const T &value_multiplier)
ParameterProxy< T > operator*()
ParameterProxy & operator+=(const T &value_increment)
virtual ParameterAccessor< T > & operator=(T *)
ConstParameterProxy(const ParameterAccessor< T > &accessor)
const ParameterAccessor< T > & _accessor
ParameterProxy & operator-=(const T &value_decrement)
ParameterAccessor< T > & _accessor
ParameterProxy & operator=(const T &new_value)
ParameterProxy & operator/=(const T &value_divisor)
virtual std::unique_ptr< ParameterAccessor< T > > clone() const =0
Base class for reading/writing sensitivity parameters.
ParameterProxy(ParameterAccessor< T > &accessor)