libMesh
parameter_accessor.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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"
28 
29 namespace libMesh
30 {
31 
32 // Forward declarations
33 template <typename T>
35 
36 template <typename T>
38 
39 
52 template <typename T=Number>
54 {
55 public:
60  virtual ~ParameterAccessor() {}
61 
65  virtual void set (const T & new_value) = 0;
66 
70  virtual const T & get () const = 0;
71 
77 #ifdef LIBMESH_ENABLE_DEPRECATED
78  virtual ParameterAccessor<T> &
79  operator= (T * /* new_ptr */) { libmesh_error(); return *this; }
80 #endif
81 
89 
91 
97  virtual UniquePtr<ParameterAccessor<T>> clone() const = 0;
98 };
99 
100 template <typename T=Number>
101 class ParameterProxy
102 {
103 public:
108  : _accessor(accessor) {}
109 
113  ParameterProxy & operator = (const T & new_value) { _accessor.set(new_value); return *this; }
114 
118  ParameterProxy & operator = (const ParameterProxy<T> & new_value) { _accessor.set(new_value.get()); }
119 
123  ParameterProxy & operator = (const ConstParameterProxy<T> & new_value) { _accessor.set(new_value.get()); return *this; }
124 
128  ParameterProxy & operator += (const T & value_increment) { _accessor.set(_accessor.get() + value_increment); return *this; }
129 
133  ParameterProxy & operator -= (const T & value_decrement) { _accessor.set(_accessor.get() - value_decrement); return *this; }
134 
138  ParameterProxy & operator *= (const T & value_multiplier) { _accessor.set(_accessor.get() * value_multiplier); return *this; }
139 
143  ParameterProxy & operator /= (const T & value_divisor) { _accessor.set(_accessor.get() / value_divisor); return *this; }
144 
148  operator T () const { return _accessor.get(); }
149 
150 private:
152 };
153 
154 
155 template <typename T=Number>
157 {
158 public:
163  : _accessor(accessor) {}
164 
168  operator T () const { return _accessor.get(); }
169 
173  T get() const { return _accessor.get(); }
174 
175 private:
177 };
178 
179 
180 } // namespace libMesh
181 
182 #endif // LIBMESH_PARAMETER_ACCESSOR_H
ParameterProxy< T > operator*()
Proxy: for backward compatibility, we allow codes to treat a ParameterAccessor as if it were a simple...
virtual ParameterAccessor< T > & operator=(T *)
Reseater: change the location of the parameter we access.
The libMesh namespace provides an interface to certain functionality in the library.
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
ConstParameterProxy(const ParameterAccessor< T > &accessor)
Constructor: which parameter are we a proxy for?
const ParameterAccessor< T > & _accessor
ParameterAccessor< T > & _accessor
virtual UniquePtr< ParameterAccessor< T > > clone() const =0
virtual ~ParameterAccessor()
Virtual destructor - we&#39;ll be deleting subclasses from pointers-to-ParameterAccessor.
T get() const
Getter: get the value of the parameter we access.
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...
ParameterProxy(ParameterAccessor< T > &accessor)
Constructor: which parameter are we a proxy for?