source: src/Parameters/Parameter_impl.hpp@ 270bdf

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 270bdf was b56114, checked in by Frederik Heber <heber@…>, 10 years ago

FIX: Action..::outputAsPython now accesses parameters via getUnvalidated().

  • added Value::getUnvalidated() and Parameter::getUnvalidated() for access at store-session.
  • this fixes a bug when OutputAsAction had been used whose filename would no longer be valid as the file now exists. This would cause an assertion and the whole OutputAsAction would fail.
  • Property mode set to 100644
File size: 6.7 KB
RevLine 
[adcfc6]1/*
2 * Parameter_impl.hpp
3 *
4 * Created on: Apr 16, 2012
5 * Author: ankele
6 */
7
8#ifndef PARAMETER_IMPL_HPP_
9#define PARAMETER_IMPL_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include "Parameter.hpp"
[e45c1d]17#include "ParameterExceptions.hpp"
[f10b0c]18
19
20template<typename T>
21Parameter<T>::Parameter(const Parameter<T> &instance) :
[6440c6]22 ParameterInterface(instance.getName()),
[cf1d82]23 value(instance.value.getValidator())
[f10b0c]24{
[0d4168]25 value.set(instance.value.value);
[f10b0c]26}
27
28/** Constructor for class Parameter.
29 *
30 */
31template<typename T>
32Parameter<T>::Parameter() :
[6440c6]33 ParameterInterface("__no_name__"),
[cf1d82]34 value()
[f10b0c]35{};
36
[adcfc6]37/** Constructor for class Parameter.
38 *
39 */
40template<typename T>
41Parameter<T>::Parameter(const std::string &_name) :
[6440c6]42 ParameterInterface(_name),
[cf1d82]43 value()
[adcfc6]44{};
45
46/** Constructor for class Parameter.
47 *
48 * @param _name name of this parameter
49 * @param _value initial value to set
50 */
51template<typename T>
52Parameter<T>::Parameter(const std::string &_name, const T &_value) :
[6440c6]53 ParameterInterface(_name),
[cf1d82]54 value()
[adcfc6]55{
[cf1d82]56 value.set(_value);
[adcfc6]57};
58
59/** Constructor for class Parameter.
60 *
61 * @param _name name of this parameter
62 * @param _ValidRange valid range for this ContinuousValue
63 */
64template<typename T>
65Parameter<T>::Parameter(const std::string &_name, const Validator<T> &_Validator) :
[6440c6]66 ParameterInterface(_name),
[cf1d82]67 value(_Validator)
[adcfc6]68{};
69
70/** Constructor for class Parameter.
71 *
72 * @param _name name of this parameter
73 * @param _ValidRange valid range for this ContinuousValue
74 * @param _value initial value to set
75 */
76template<typename T>
77Parameter<T>::Parameter(const std::string &_name, const Validator<T> &_Validator, const T &_value) :
[6440c6]78 ParameterInterface(_name),
[cf1d82]79 value(_Validator)
[adcfc6]80{
[cf1d82]81 value.set(_value);
[adcfc6]82};
83
84/** Constructor for class Parameter.
85 *
86 * @param _name name of this parameter
87 * @param _ValidRange valid range for this ContinuousValue
88 */
89template<typename T>
90Parameter<T>::Parameter(const std::string &_name, const std::vector<T> &_ValidValues) :
[6440c6]91 ParameterInterface(_name),
[cf1d82]92 value(_ValidValues)
[adcfc6]93{};
94
95/** Constructor for class Parameter.
96 *
97 * @param _name name of this parameter
98 * @param _ValidRange valid range for this ContinuousValue
99 * @param _value initial value to set
100 */
101template<typename T>
102Parameter<T>::Parameter(const std::string &_name, const std::vector<T> &_ValidValues, const T &_value) :
[6440c6]103 ParameterInterface(_name),
[cf1d82]104 value(_ValidValues)
[adcfc6]105{
[cf1d82]106 value.set(_value);
[adcfc6]107};
108
109/** Constructor for class Parameter.
110 *
111 * @param _name name of this parameter
112 * @param _ValidRange valid range for this ContinuousValue
113 */
114template<typename T>
115Parameter<T>::Parameter(const std::string &_name, const range<T> &_ValidRange) :
[6440c6]116 ParameterInterface(_name),
[cf1d82]117 value(_ValidRange)
[adcfc6]118{};
119
120/** Constructor for class Parameter.
121 *
122 * @param _name name of this parameter
123 * @param _ValidRange valid range for this ContinuousValue
124 * @param _value initial value to set
125 */
126template<typename T>
127Parameter<T>::Parameter(const std::string &_name, const range<T> &_ValidRange, const T &_value) :
[6440c6]128 ParameterInterface(_name),
[cf1d82]129 value(_ValidRange)
[adcfc6]130{
[cf1d82]131 value.set(_value);
[adcfc6]132};
133
134/** Destructor for class Parameter.
135 *
136 */
137template<typename T>
138Parameter<T>::~Parameter()
139{};
140
[cf1d82]141/** Catch call to value.isValidAsString() to add exception information.
142 *
143 * @param _value value to set to
144 */
145template<typename T>
146inline
147bool Parameter<T>::isValidAsString(const std::string &_value) const throw(ParameterValidatorException)
148{
149 try {
150 return value.isValidAsString(_value);
151 } catch(ParameterException &e) {
152 e << ParameterName(ParameterInterface::getName());
153 throw;
154 }
155}
156
157
158/** Catch call to value.getAsString() to add exception information.
[e45c1d]159 *
160 * @return parameter value as string
161 */
162template<typename T>
[9e6722]163inline const std::string Parameter<T>::getAsString() const throw(ParameterValueException)
[e45c1d]164{
165 try {
[cf1d82]166 return value.getAsString();
[e45c1d]167 } catch(ParameterException &e) {
[6440c6]168 e << ParameterName(ParameterInterface::getName());
[e45c1d]169 throw;
170 }
171}
172
[cf1d82]173/** Catch call to value.isValid() to add exception information.
174 *
175 * @return parameter value as string
176 */
177template<typename T>
178inline bool Parameter<T>::isValid(const T &_value) const throw(ParameterValidatorException)
179{
180 try {
181 return value.isValid(_value);
182 } catch(ParameterException &e) {
183 e << ParameterName(ParameterInterface::getName());
184 throw;
185 }
186}
187
188
[b56114]189/** Catch call to value.getUnvalidated() to add exception information.
190 *
191 * @return parameter value as string
192 */
193template<typename T>
194inline const T & Parameter<T>::getUnvalidated() const throw(ParameterValueException)
195{
196 try {
197 return value.getUnvalidated();
198 } catch(ParameterException &e) {
199 e << ParameterName(ParameterInterface::getName());
200 throw;
201 }
202}
203
[cf1d82]204/** Catch call to value.get() to add exception information.
[e45c1d]205 *
206 * @return parameter value as string
207 */
208template<typename T>
[9e6722]209inline const T & Parameter<T>::get() const throw(ParameterValueException)
[e45c1d]210{
211 try {
[cf1d82]212 return value.get();
[e45c1d]213 } catch(ParameterException &e) {
[6440c6]214 e << ParameterName(ParameterInterface::getName());
[e45c1d]215 throw;
216 }
217}
218
[cf1d82]219/** Catch call to value.set() to add exception information.
[e45c1d]220 *
221 * @param _value value to set to
222 */
223template<typename T>
[9e6722]224inline void Parameter<T>::set(const T & _value) throw(ParameterValueException)
[e45c1d]225{
226 try {
[cf1d82]227 value.set(_value);
[e45c1d]228 } catch(ParameterException &e) {
[6440c6]229 e << ParameterName(ParameterInterface::getName());
[e45c1d]230 throw;
231 }
232}
233
[cf1d82]234/** Catch call to value.set() to add exception information.
[e45c1d]235 *
236 * @param _value value to set to
237 */
238template<typename T>
[b11f5e]239inline void Parameter<T>::setAsString(const std::string &_value) throw(ParameterValueException)
[e45c1d]240{
241 try {
[cf1d82]242 value.setAsString(_value);
[e45c1d]243 } catch(ParameterException &e) {
[6440c6]244 e << ParameterName(ParameterInterface::getName());
[e45c1d]245 throw;
246 }
247}
248
[adcfc6]249/** Compares this continuous value against another \a _instance.
250 *
251 * @param _instance other value to compare to
252 * @return true - if contained ContinuousValue and name are the same, false - else
253 */
254template <class T>
[e45c1d]255bool Parameter<T>::operator==(const Parameter<T> &_instance) const throw(ParameterException)
[adcfc6]256{
257 bool status = true;
[e45c1d]258 try {
259 status = status &&
[cf1d82]260 (value == _instance.value);
[6440c6]261 status = status && (ParameterInterface::getName() == _instance.ParameterInterface::getName());
[e45c1d]262 } catch(ParameterException &e) {
[6440c6]263 e << ParameterName(ParameterInterface::getName());
[e45c1d]264 throw;
265 }
[adcfc6]266 return status;
267}
268
269/** Creates a clone of this Parameter instance.
270 *
271 * @return cloned instance
272 */
273template<typename T>
[6440c6]274inline ParameterInterface* Parameter<T>::clone() const
[adcfc6]275{
[cf1d82]276 Parameter<T> *instance = new Parameter<T>(ParameterInterface::getName(), value.getValidator());
[0d4168]277 // do not use get, we do not check for validity here
[cf1d82]278 if (value.ValueSet)
[0d4168]279 instance->set(value.value);
[adcfc6]280 return instance;
281}
282
283
284#endif /* Parameter_IMPL_HPP_ */
Note: See TracBrowser for help on using the repository browser.