source: src/Parameters/Parameter_impl.hpp@ e45c1d

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 e45c1d was e45c1d, checked in by Frederik Heber <heber@…>, 13 years ago

Added ParameterExceptions, is caught by Dialog::checkAll() for the moment.

  • Property mode set to 100644
File size: 5.6 KB
Line 
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"
17#include "ParameterExceptions.hpp"
18
19
20template<typename T>
21Parameter<T>::Parameter(const Parameter<T> &instance) :
22 ParameterInterface<T>(instance.getName()),
23 Value<T>(instance.getValidator())
24{
25 Value<T>::set(instance.Value<T>::get());
26}
27
28/** Constructor for class Parameter.
29 *
30 */
31template<typename T>
32Parameter<T>::Parameter() :
33 ParameterInterface<T>("__no_name__"),
34 Value<T>()
35{};
36
37/** Constructor for class Parameter.
38 *
39 */
40template<typename T>
41Parameter<T>::Parameter(const std::string &_name) :
42 ParameterInterface<T>(_name),
43 Value<T>()
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) :
53 ParameterInterface<T>(_name),
54 Value<T>()
55{
56 Value<T>::set(_value);
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) :
66 ParameterInterface<T>(_name),
67 Value<T>(_Validator)
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) :
78 ParameterInterface<T>(_name),
79 Value<T>(_Validator)
80{
81 Value<T>::set(_value);
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) :
91 ParameterInterface<T>(_name),
92 Value<T>(_ValidValues)
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) :
103 ParameterInterface<T>(_name),
104 Value<T>(_ValidValues)
105{
106 Value<T>::set(_value);
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) :
116 ParameterInterface<T>(_name),
117 Value<T>(_ValidRange)
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) :
128 ParameterInterface<T>(_name),
129 Value<T>(_ValidRange)
130{
131 Value<T>::set(_value);
132};
133
134/** Destructor for class Parameter.
135 *
136 */
137template<typename T>
138Parameter<T>::~Parameter()
139{};
140
141/** Catch call to Value<T>::getAsString() to add exception information.
142 *
143 * @return parameter value as string
144 */
145template<typename T>
146const std::string Parameter<T>::getAsString() const throw(ParameterValueException)
147{
148 try {
149 return Value<T>::getAsString();
150 } catch(ParameterException &e) {
151 e << ParameterName(ParameterInterface<T>::getName());
152 throw;
153 }
154}
155
156/** Catch call to Value<T>::get() to add exception information.
157 *
158 * @return parameter value as string
159 */
160template<typename T>
161const T & Parameter<T>::get() const throw(ParameterValueException)
162{
163 try {
164 return Value<T>::get();
165 } catch(ParameterException &e) {
166 e << ParameterName(ParameterInterface<T>::getName());
167 throw;
168 }
169}
170
171/** Catch call to Value<T>::set() to add exception information.
172 *
173 * @param _value value to set to
174 */
175template<typename T>
176void Parameter<T>::set(const T & _value) throw(ParameterValueException)
177{
178 try {
179 Value<T>::set(_value);
180 } catch(ParameterException &e) {
181 e << ParameterName(ParameterInterface<T>::getName());
182 throw;
183 }
184}
185
186/** Catch call to Value<T>::set() to add exception information.
187 *
188 * @param _value value to set to
189 */
190template<typename T>
191void Parameter<T>::setAsString(const std::string _value) throw(ParameterValueException)
192{
193 try {
194 Value<T>::setAsString(_value);
195 } catch(ParameterException &e) {
196 e << ParameterName(ParameterInterface<T>::getName());
197 throw;
198 }
199}
200
201/** Compares this continuous value against another \a _instance.
202 *
203 * @param _instance other value to compare to
204 * @return true - if contained ContinuousValue and name are the same, false - else
205 */
206template <class T>
207bool Parameter<T>::operator==(const Parameter<T> &_instance) const throw(ParameterException)
208{
209 bool status = true;
210 try {
211 status = status &&
212 (*dynamic_cast<const Value<T> *>(this) == dynamic_cast<const Value<T> &>(_instance));
213 status = status && (ParameterInterface<T>::getName() == _instance.ParameterInterface<T>::getName());
214 } catch(ParameterException &e) {
215 e << ParameterName(ParameterInterface<T>::getName());
216 throw;
217 }
218 return status;
219}
220
221/** Creates a clone of this Parameter instance.
222 *
223 * @return cloned instance
224 */
225template<typename T>
226ParameterAsString* Parameter<T>::clone() const
227{
228 Parameter<T> *instance = new Parameter<T>(ParameterInterface<T>::getName(), Value<T>::getValidator());
229 if (Value<T>::ValueSet)
230 instance->set(Value<T>::get());
231 return instance;
232}
233
234
235#endif /* Parameter_IMPL_HPP_ */
Note: See TracBrowser for help on using the repository browser.