Changeset e45c1d for src/Parameters/Value_impl.hpp
- Timestamp:
- Jun 13, 2012, 5:39:01 PM (14 years ago)
- Branches:
- 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, Candidate_v1.7.0, 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
- Children:
- 7951b9
- Parents:
- e5d7970
- git-author:
- Frederik Heber <heber@…> (05/09/12 18:40:56)
- git-committer:
- Frederik Heber <heber@…> (06/13/12 17:39:01)
- File:
-
- 1 edited
-
src/Parameters/Value_impl.hpp (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parameters/Value_impl.hpp
re5d7970 re45c1d 25 25 #include "Validators/DiscreteValidator.hpp" 26 26 #include "Validators/RangeValidator.hpp" 27 28 27 #include "ParameterExceptions.hpp" 29 28 30 29 // static member … … 88 87 */ 89 88 template <class T> 90 bool Value<T>::isValid(const T & _value) const 91 { 92 ASSERT(validator, 93 "Value<T>::isValid() - validator missing."); 89 bool Value<T>::isValid(const T & _value) const throw(ParameterValidatorException) 90 { 91 if (validator == NULL) throw ParameterValidatorException(); 94 92 return (*validator)(_value); 95 93 } … … 101 99 */ 102 100 template <class T> 103 bool Value<T>::operator==(const Value<T> &_instance) const 104 { 105 ASSERT(validator, 106 "Value<T>::operator==() - validator missing."); 107 ASSERT(_instance.validator, 108 "Value<T>::operator==() - instance.validator missing."); 101 bool Value<T>::operator==(const Value<T> &_instance) const throw(ParameterValidatorException) 102 { 103 if (validator == NULL) throw ParameterValidatorException(); 104 if (_instance.validator == NULL) throw ParameterValidatorException(); 109 105 bool status = true; 110 106 status = status && (*validator == *_instance.validator); … … 121 117 */ 122 118 template <class T> 123 const T & Value<T>::get() const 124 { 125 ASSERT(ValueSet, 126 "Value<T>::get() - value has never been set."); 119 const T & Value<T>::get() const throw(ParameterValueException) 120 { 121 if (!ValueSet) throw ParameterValueException(); 127 122 return value; 128 123 } … … 133 128 */ 134 129 template <class T> 135 void Value<T>::set(const T & _value) 136 { 137 ASSERT(isValid(_value), 138 "Value<T>::setValue() - trying to set invalid value "+toString(_value)+"."); 130 void Value<T>::set(const T & _value) throw(ParameterException) 131 { 132 if (!isValid(_value)) throw ParameterValueException(); 139 133 if (!ValueSet) 140 134 ValueSet = true; … … 160 154 */ 161 155 template <class T> 162 bool Value<T>::isValidAsString(const std::string _value) const 156 bool Value<T>::isValidAsString(const std::string _value) const throw(ParameterValidatorException) 163 157 { 164 158 const T castvalue = Converter(_value); … … 168 162 169 163 template <> 170 inline bool Value<std::string>::isValidAsString(const std::string _value) const 164 inline bool Value<std::string>::isValidAsString(const std::string _value) const throw(ParameterValidatorException) 171 165 { 172 166 return isValid(_value); … … 178 172 */ 179 173 template <class T> 180 const std::string Value<T>::getAsString() const 181 { 182 ASSERT(ValueSet, 183 "Value<T>::getAsString() - requesting unset value."); 174 const std::string Value<T>::getAsString() const throw(ParameterValueException) 175 { 176 if (!ValueSet) throw ParameterValueException(); 184 177 return toString(value); 185 178 } … … 190 183 */ 191 184 template <class T> 192 void Value<T>::setAsString(const std::string _value) 185 void Value<T>::setAsString(const std::string _value) throw(ParameterException) 193 186 { 194 187 const T castvalue = Converter(_value); … … 199 192 200 193 template <> 201 inline void Value<std::string>::setAsString(const std::string _value) 194 inline void Value<std::string>::setAsString(const std::string _value) throw(ParameterException) 202 195 { 203 196 set(_value); … … 212 205 const Validator<T> &Value<T>::getValidator() const 213 206 { 214 ASSERT(validator, 215 "Value<T>::getValidator() const - validator missing."); 207 if (validator == NULL) throw ParameterValidatorException(); 216 208 return *validator; 217 209 } … … 224 216 Validator<T> &Value<T>::getValidator() 225 217 { 226 ASSERT(validator, 227 "Value<T>::getValidator() - validator missing."); 218 if (validator == NULL) throw ParameterValidatorException(); 228 219 return *validator; 229 220 } … … 232 223 233 224 template <class T> 234 const range<T> & Value<T>::getValidRange() const 225 const range<T> & Value<T>::getValidRange() const throw(ParameterValidatorException) 235 226 { 236 227 dynamic_cast<RangeValidator<T>&>(getValidator()).getValidRange(); … … 239 230 /** Setter for the valid range. 240 231 * 241 * If value is invalid in new range, we throw AssertFailureand set ValueSet to false.232 * If value is invalid in new range, we throw ParameterValueException and set ValueSet to false. 242 233 * 243 234 * @param _range range (pair of values) 244 235 */ 245 236 template <class T> 246 void Value<T>::setValidRange(const range<T> &_range) 237 void Value<T>::setValidRange(const range<T> &_range) throw(ParameterValueException) 247 238 { 248 239 dynamic_cast<RangeValidator<T>&>(getValidator()).setValidRange(_range); … … 253 244 ValueSet = false; 254 245 // have full check again in assert such that it appears in output, too 255 ASSERT(isValid(value), 256 "Value<T>::setValidRange() - new range " 257 +toString(_range)+" invalidates current value "+toString(value)+"."); 246 throw ParameterValueException() << ParameterValidValues(toString(_range)); 258 247 } 259 248 } … … 262 251 263 252 template <class T> 264 void Value<T>::appendValidValue(const T &_value) 253 void Value<T>::appendValidValue(const T &_value) throw(ParameterValidatorException) 265 254 { 266 255 dynamic_cast<DiscreteValidator<T>&>(getValidator()).appendValidValue(_value); … … 268 257 269 258 template <class T> 270 const std::vector<T> &Value<T>::getValidValues() const 259 const std::vector<T> &Value<T>::getValidValues() const throw(ParameterValidatorException) 271 260 { 272 261 dynamic_cast<DiscreteValidator<T>&>(getValidator()).getValidValues();
Note:
See TracChangeset
for help on using the changeset viewer.
