Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_ParameterRegistration.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef SACADO_PARAMETERREGISTRATION_HPP
11 #define SACADO_PARAMETERREGISTRATION_HPP
12 
13 #include <sstream>
15 #include "Sacado_Traits.hpp"
17 
18 namespace Sacado {
19 
25  template <typename EvalType, typename EvalTypeTraits = DefaultEvalTypeTraits>
26  class ParameterRegistration :
27  public Sacado::ScalarParameterEntry<EvalType, EvalTypeTraits > {
28 
30  typedef typename EvalTypeTraits::template apply<EvalType>::type ScalarT;
31 
32 
33  public:
34 
36 
38  ParameterRegistration(const std::string &name_,
40  ParamLib& paramLib)
41  : access(access_), name(name_) {
42 
43  if (!paramLib.isParameter(name))
44  paramLib.addParameterFamily(name, true, false);
45  if (!paramLib.template isParameterForType<EvalType>(name))
46  paramLib.template addEntry<EvalType>(name, Teuchos::rcp(this,false));
47  }
48 
50  ParameterRegistration(const std::string &name_,
52  const Teuchos::RCP<ParamLib>& paramLib)
53  : access(access_), name(name_) {
54 
55  if (paramLib != Teuchos::null) {
56  if (!paramLib->isParameter(name))
57  paramLib->addParameterFamily(name, true, false);
58  if (!paramLib->template isParameterForType<EvalType>(name)) {
59  paramLib->template addEntry<EvalType>(name, Teuchos::rcp(this,false));
60  }
61  }
62  }
63 
66 
68  virtual void setRealValue(double value) {
69  setValue(ScalarT(value)); }
70 
72  virtual void setValue(const ScalarT& value) {
73  access->setValue(name, value);
74  }
75 
77  virtual const ScalarT& getValue() const {
78  return access->getValue(name);
79  }
80 
81  protected:
82 
85  const std::string name;
86 
87  };
88 
89 }
90 
91 #endif // SACADO_PARAMETERREGISTRATION_HPP
virtual const ScalarT & getValue() const
Get parameter value using ParameterAccessor.
ScalarParameterLibrary< EvalTypeTraits > ParamLib
EvalTypeTraits::template apply< EvalType >::type ScalarT
Scalar type.
ParameterAccessor< EvalType, EvalTypeTraits > * access
Pointer to source function.
bool addParameterFamily(const std::string &name, bool supports_ad, bool supports_analytic)
Create a new parameter family.
virtual void setValue(const ScalarT &value)
Set parameter values using ParameterAccessor.
ParameterRegistration(const std::string &name_, ParameterAccessor< EvalType, EvalTypeTraits > *access_, ParamLib &paramLib)
Constructor: Registers the parameter with the Parameter Library.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
ParameterRegistration(const std::string &name_, ParameterAccessor< EvalType, EvalTypeTraits > *access_, const Teuchos::RCP< ParamLib > &paramLib)
Constructor: Registers the parameter with the Parameter Library.
A base class for scalar parameter values.
std::string name_
Definition: gtest.cc:2817
int value
bool isParameter(const std::string &name) const
Determine if parameter of name name is in the library.
virtual void setRealValue(double value)
Set real parameter value.
Specialization of Sacado::ParameterLibraryBase for scalar parameters.
Abstract class that provides access to a parameter value in a code for the parameter library...