Changeset e45c1d
- Timestamp:
- Jun 13, 2012, 5:39:01 PM (13 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, 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)
- Location:
- src
- Files:
-
- 1 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parameters/ContinuousValue.hpp
re5d7970 re45c1d 18 18 #include "CodePatterns/Range.hpp" 19 19 20 #include "Value.hpp" 20 21 #include "ValueInterface.hpp" 21 22 22 23 class ContinuousValueTest; 24 class ParameterException; 25 class ParameterValidatorException; 26 class ParameterValueException; 23 27 24 28 /** This class represents a discrete value, it implements ValueInterface. … … 26 30 */ 27 31 template <class T> 28 class ContinuousValue : virtual public ValueInterface<T>32 class ContinuousValue : public Value<T> 29 33 { 30 34 //!> unit test needs to have access to internal values … … 36 40 37 41 // functions for ValueInterface 38 bool isValid(const T & _value) const; 39 const T & get() const; 40 void set(const T & _value); 42 bool isValid(const T & _value) const throw(ParameterValidatorException); 41 43 42 44 // comfortable setter … … 45 47 46 48 // comparator 47 bool operator==(const ContinuousValue<T> &_instance) const ;48 bool operator!=(const ContinuousValue<T> &_instance) const 49 bool operator==(const ContinuousValue<T> &_instance) const throw(ParameterException); 50 bool operator!=(const ContinuousValue<T> &_instance) const throw(ParameterException) 49 51 { return !((*this)==(_instance)); } 50 52 51 53 // getter/setter for valid ranges 52 void setValidRange(const range<T> &_range) ;53 const range<T> & getValidRange() const ;54 void setValidRange(const range<T> &_range) throw(ParameterValueException); 55 const range<T> & getValidRange() const throw(ParameterValidatorException); 54 56 55 // string functions for ValueInterface 56 bool isValidAsString(const std::string _value) const; 57 const std::string getAsString() const; 58 void setAsString(const std::string _value); 57 // string functions for ValueInterface, taken from Value 59 58 60 59 private: -
src/Parameters/ContinuousValue_impl.hpp
re5d7970 re45c1d 23 23 24 24 #include "ContinuousValue.hpp" 25 26 #include "ParameterExceptions.hpp" 25 27 26 28 /** Constructor of class DiscreteValue. … … 56 58 */ 57 59 template <class T> 58 bool ContinuousValue<T>::isValid(const T & _value) const 60 bool ContinuousValue<T>::isValid(const T & _value) const throw(ParameterValidatorException) 59 61 { 60 62 bool isBefore = true; 61 63 bool isBeyond = true; 62 64 // check left boundary 63 isBefore = !((!ValidRangeSet.first) || (!ValidRange.isBefore(_value))); 65 if ((!ValidRangeSet.first) || (!ValidRangeSet.last)) 66 throw ParameterValidatorException(); 67 isBefore = !((!ValidRange.isBefore(_value))); 64 68 // if (isBefore) 65 69 // LOG(0, "INFO: " << _value << " is before " << ValidRange.first << "."); 66 70 // check right boundary 67 isBeyond = !((!ValidRange Set.last) || (!ValidRange.isBeyond(_value)) || (_value == ValidRange.last));71 isBeyond = !((!ValidRange.isBeyond(_value)) || (_value == ValidRange.last)); 68 72 // if (isBeyond) 69 73 // LOG(0, "INFO: " << _value << " is beyond " << ValidRange.last << "."); … … 77 81 */ 78 82 template <class T> 79 bool ContinuousValue<T>::operator==(const ContinuousValue<T> &_instance) const 83 bool ContinuousValue<T>::operator==(const ContinuousValue<T> &_instance) const const throw(ParameterException) 80 84 { 81 85 bool status = true; 86 if ((!ValueSet) || (!_instance.ValueSet)) 87 throw ParameterValueException(); 88 if ((!ValidRangeSet.first) || ((!ValidRangeSet.first)) 89 || (!_instance.ValidRangeSet.first) || ((!_instance.ValidRangeSet.first))) 90 throw ParameterValidatorException(); 82 91 status = status && (ValidRange == _instance.ValidRange); 83 92 status = status && (ValueSet == _instance.ValueSet); 84 if (ValueSet && _instance.ValueSet) 85 status = status && (value == _instance.value); 93 status = status && (value == _instance.value); 86 94 return status; 87 }88 89 /** Getter of value, returning string.90 *91 * @return string value92 */93 template <class T>94 const T & ContinuousValue<T>::get() const95 {96 ASSERT(ValueSet,97 "ContinuousValue<T>::get() - requesting unset value.");98 return value;99 }100 101 /** Setter of value for string102 *103 * @param _value string containing new value104 */105 template <class T>106 void ContinuousValue<T>::set(const T & _value)107 {108 ASSERT(isValid(_value),109 "ContinuousValue<T>::setValue() - trying to set invalid value "+toString(_value)+".");110 if (!ValueSet)111 ValueSet = true;112 value = _value;113 // LOG(0, "STATUS: Value is now set to " << value << ".");114 95 } 115 96 … … 121 102 */ 122 103 template <class T> 123 void ContinuousValue<T>::setValidRange(const range<T> &_range) 104 void ContinuousValue<T>::setValidRange(const range<T> &_range) throw(ParameterValueException) 124 105 { 125 126 106 ValidRangeSet = range<bool>(true, true); 127 107 ValidRange = _range; … … 132 112 ValueSet = false; 133 113 // have full check again in assert such that it appears in output, too 134 ASSERT(ValidRange.isInRange(value) || (value == ValidRange.last), 135 "ContinuousValue<T>::setValidRange() - new range " 136 +toString(_range)+" invalidates current value "+toString(value)+"."); 114 if (!ValidRange.isInRange(value) && (value != ValidRange.last)) 115 throw ParameterValueException() << ParameterValidValues(toString(_range)); 137 116 } 138 117 } … … 145 124 */ 146 125 template <class T> 147 const range<T> & ContinuousValue<T>::getValidRange() const 126 const range<T> & ContinuousValue<T>::getValidRange() const throw(ParameterValidatorException) 148 127 { 149 ASSERT(ValidRangeSet.first && ValidRangeSet.last,150 "ContinuousValue<T>::getValidRange() called though no valid range set so far.");128 if (!ValidRangeSet.first || !ValidRangeSet.last) 129 throw ParameterValidatorException(); 151 130 return ValidRange; 152 131 } 153 132 154 /** Checks whether \a _value is a valid value.155 * \param _value value to check for validity.156 * \return true - \a _value is valid, false - is not157 */158 template <class T>159 bool ContinuousValue<T>::isValidAsString(const std::string _value) const160 {161 /*bool isBefore = true;162 bool isBeyond = true;163 // check left boundary164 isBefore = !((!ValidRangeSet.first) || (!ValidRange.isBefore(_value)));165 // if (isBefore)166 // LOG(0, "INFO: " << _value << " is before " << ValidRange.first << ".");167 // check right boundary168 isBeyond = !((!ValidRangeSet.last) || (!ValidRange.isBeyond(_value)) || (_value == ValidRange.last));169 // if (isBeyond)170 // LOG(0, "INFO: " << _value << " is beyond " << ValidRange.last << ".");171 return (!isBefore) && (!isBeyond);*/172 return true;173 }174 175 176 /** Sets the value.177 *178 * We check for its validity, otherwise we throw an Assert::AssertionFailure.179 *180 * @param _value const reference of value to set181 */182 template <class T>183 void ContinuousValue<T>::setAsString(const std::string _value)184 {185 /*ASSERT(isValidAsString(_value),186 "ContinuousValue<T>::setValue() - trying to set invalid value "+toString(_value)+".");187 if (!ValueSet)188 ValueSet = true;189 value = _value;*/190 }191 192 /** Getter for the set value.193 *194 * We check whether it has been set, otherwise we throw an Assert::AssertionFailure.195 *196 * @return set value197 */198 template <class T>199 const std::string ContinuousValue<T>::getAsString() const200 {201 ASSERT(ValueSet,202 "ContinuousValue<T>::get() - value has never been set.");203 return toString(value);204 }205 206 133 #endif /* CONTINUOUSVALUE_IMPL_HPP_ */ -
src/Parameters/Parameter.hpp
re5d7970 re45c1d 21 21 #include "ParameterInterface.hpp" 22 22 23 class ParameterException; 24 class ParameterValueException; 25 23 26 /** This class encapsulates a clonable, continuous value. 24 27 * … … 39 42 virtual ~Parameter(); 40 43 44 // catch the following functions from Value<T> to add exception information 45 const std::string getAsString() const throw(ParameterValueException); 46 const T & get() const throw(ParameterValueException); 47 void set(const T & _value) throw(ParameterValueException); 48 void setAsString(const std::string _value) throw(ParameterValueException); 49 41 50 // comparator 42 bool operator==(const Parameter<T> &_instance) const ;43 bool operator!=(const Parameter<T> &_instance) const 51 bool operator==(const Parameter<T> &_instance) const throw(ParameterException); 52 bool operator!=(const Parameter<T> &_instance) const throw(ParameterException) 44 53 { return !((*this)==(_instance)); } 45 54 -
src/Parameters/Parameter_impl.hpp
re5d7970 re45c1d 15 15 16 16 #include "Parameter.hpp" 17 17 #include "ParameterExceptions.hpp" 18 18 19 19 … … 139 139 {}; 140 140 141 /** Catch call to Value<T>::getAsString() to add exception information. 142 * 143 * @return parameter value as string 144 */ 145 template<typename T> 146 const 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 */ 160 template<typename T> 161 const 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 */ 175 template<typename T> 176 void 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 */ 190 template<typename T> 191 void 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 141 201 /** Compares this continuous value against another \a _instance. 142 202 * … … 145 205 */ 146 206 template <class T> 147 bool Parameter<T>::operator==(const Parameter<T> &_instance) const 207 bool Parameter<T>::operator==(const Parameter<T> &_instance) const throw(ParameterException) 148 208 { 149 209 bool status = true; 150 status = status && 151 (*dynamic_cast<const Value<T> *>(this) == dynamic_cast<const Value<T> &>(_instance)); 152 status = status && (ParameterInterface<T>::getName() == _instance.ParameterInterface<T>::getName()); 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 } 153 218 return status; 154 219 } -
src/Parameters/Validators/DiscreteValidator.hpp
re5d7970 re45c1d 20 20 21 21 class DiscreteValueTest; 22 class ParameterValidatorException; 22 23 23 24 /** A validator with a discrete list of valid values. … … 40 41 bool operator==(const Validator<T> &_instance) const; 41 42 42 void appendValidValue(const T &_value) ;43 void appendValidValue(const T &_value) throw(ParameterValidatorException); 43 44 const std::vector<T> &getValidValues() const; 44 45 -
src/Parameters/Validators/DiscreteValidator_impl.hpp
re5d7970 re45c1d 15 15 #endif 16 16 17 #include "Parameters/ParameterExceptions.hpp" 17 18 #include <algorithm> 18 19 … … 47 48 48 49 template <class T> 49 void DiscreteValidator<T>::appendValidValue(const T &_value) 50 void DiscreteValidator<T>::appendValidValue(const T &_value) throw(ParameterValidatorException) 50 51 { 51 ASSERT(!isValid(_value),52 "DiscreteValidator<>::appendValidValue() - value "+toString(_value)+" is already among the valid");52 if (isValid(_value)) 53 throw ParameterValidatorException(); 53 54 ValidValues.push_back(_value); 54 55 } -
src/Parameters/Validators/RangeValidator.hpp
re5d7970 re45c1d 17 17 #include "Validator.hpp" 18 18 #include "CodePatterns/Range.hpp" 19 20 class ParameterValueException; 19 21 20 22 /** A validator with an interval of valid values. … … 37 39 38 40 // getter/setter for valid ranges 39 void setValidRange(const range<T> &_range) ;41 void setValidRange(const range<T> &_range) throw(ParameterValueException); 40 42 const range<T> & getValidRange() const { return ValidRange; }; 41 43 -
src/Parameters/Validators/RangeValidator_impl.hpp
re5d7970 re45c1d 14 14 #include <config.h> 15 15 #endif 16 17 #include "Parameters/ParameterExceptions.hpp" 16 18 17 19 template <class T> … … 50 52 /** Setter for the valid range. 51 53 * 52 * If value is invalid in new range, we throw AssertFailure and set ValueSet to false.54 * \note Check whether range invalidates values is done in Value<T>. 53 55 * 54 56 * @param _range range (pair of values) 55 57 */ 56 58 template <class T> 57 void RangeValidator<T>::setValidRange(const range<T> &_range) 59 void RangeValidator<T>::setValidRange(const range<T> &_range) throw(ParameterValueException) 58 60 { 59 61 ValidRange = _range; 60 62 } 61 62 63 64 65 66 63 67 64 // specialization for Vector -
src/Parameters/Value.hpp
re5d7970 re45c1d 29 29 template <class T> 30 30 class Parameter; 31 class ParameterException; 32 class ParameterValidatorException; 33 class ParameterValueException; 31 34 32 35 /** Converter for a string to a std::vector of any class … … 68 71 69 72 // functions for ValueInterface 70 bool isValid(const T &_value) const ;71 const T & get() const ;72 void set(const T & _value) ;73 bool isValid(const T &_value) const throw(ParameterValidatorException); 74 const T & get() const throw(ParameterValueException); 75 void set(const T & _value) throw(ParameterException); 73 76 bool isSet() const; 74 77 75 78 // string functions for ValueInterface 76 bool isValidAsString(const std::string _value) const ;77 const std::string getAsString() const ;78 void setAsString(const std::string _value) ;79 bool isValidAsString(const std::string _value) const throw(ParameterValidatorException); 80 const std::string getAsString() const throw(ParameterValueException); 81 void setAsString(const std::string _value) throw(ParameterException); 79 82 80 83 // comfortable setter … … 83 86 84 87 // comparator 85 bool operator==(const Value<T> &_instance) const ;86 bool operator!=(const Value<T> &_instance) const 88 bool operator==(const Value<T> &_instance) const throw(ParameterValidatorException); 89 bool operator!=(const Value<T> &_instance) const throw(ParameterValidatorException) 87 90 { return !((*this)==(_instance)); } 88 91 … … 91 94 92 95 // comfortable validator functions 93 const range<T> & getValidRange() const ;94 void setValidRange(const range<T> &_range) ;95 void appendValidValue(const T &_value) ;96 const std::vector<T> &getValidValues() const ;96 const range<T> & getValidRange() const throw(ParameterValidatorException); 97 void setValidRange(const range<T> &_range) throw(ParameterValueException); 98 void appendValidValue(const T &_value) throw(ParameterValidatorException); 99 const std::vector<T> &getValidValues() const throw(ParameterValidatorException); 97 100 98 101 private: -
src/Parameters/ValueInterface.hpp
re5d7970 re45c1d 16 16 #include <string> 17 17 18 #include "ParameterExceptions.hpp" 18 19 #include "ValueAsString.hpp" 19 20 … … 28 29 29 30 // direct functions 30 virtual bool isValid(const T & _value) const =0;31 virtual const T & get() const =0;32 virtual void set(const T & _value) =0;31 virtual bool isValid(const T & _value) const throw(ParameterValidatorException)=0; 32 virtual const T & get() const throw(ParameterValueException)=0; 33 virtual void set(const T & _value) throw(ParameterException)=0; 33 34 virtual bool isSet() const=0; 34 35 }; -
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(); -
src/Parameters/unittests/ContinuousValueTest.cpp
re5d7970 re45c1d 113 113 test.set(4); 114 114 CPPUNIT_ASSERT_EQUAL(true, test.ValueSet); 115 #ifndef NDEBUG116 115 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 117 CPPUNIT_ASSERT_THROW(test.setValidRange(range<int>(1,3)), Assert::AssertionFailure); 118 #else 119 test.setValidRange(range<int>(1,3)); 120 #endif 121 #ifndef NDEBUG 116 CPPUNIT_ASSERT_THROW(test.setValidRange(range<int>(1,3)), ParameterValueException); 117 122 118 // no value is not set 123 119 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 124 CPPUNIT_ASSERT_THROW(test.get(), Assert::AssertionFailure);125 #endif 120 CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException); 121 126 122 // value gets invalidated in either case 127 123 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet); … … 137 133 Value<int> test(*ValidIntRange); 138 134 139 // unset calling of get, throws 140 #ifndef NDEBUG 141 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 142 CPPUNIT_ASSERT_THROW(test.getAsString(), Assert::AssertionFailure); 143 #endif 144 145 // setting invalid, throws 146 #ifndef NDEBUG 147 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 148 CPPUNIT_ASSERT_THROW(test.setAsString(toString(5)), Assert::AssertionFailure); 149 #endif 150 #ifndef NDEBUG 151 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 152 CPPUNIT_ASSERT_THROW(test.setAsString(toString(0)), Assert::AssertionFailure); 153 #endif 135 // unset calling of get, throws ParameterValueException 136 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 137 CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException); 138 139 // setting invalid, throws ParameterValueException 140 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 141 CPPUNIT_ASSERT_THROW(test.setAsString(toString(5)), ParameterValueException); 142 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 143 CPPUNIT_ASSERT_THROW(test.setAsString(toString(0)), ParameterValueException); 154 144 155 145 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet); … … 170 160 Value<int> test(*ValidIntRange); 171 161 172 // unset calling of get, throws 173 #ifndef NDEBUG 174 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 175 CPPUNIT_ASSERT_THROW(test.get(), Assert::AssertionFailure); 176 #endif 177 178 // setting invalid, throws 179 #ifndef NDEBUG 180 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 181 CPPUNIT_ASSERT_THROW(test.set(5), Assert::AssertionFailure); 182 #endif 183 #ifndef NDEBUG 184 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 185 CPPUNIT_ASSERT_THROW(test.set(0), Assert::AssertionFailure); 186 #endif 162 // unset calling of get, throws ParameterValueException 163 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 164 CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException); 165 166 // setting invalid, throws ParameterValueException 167 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 168 CPPUNIT_ASSERT_THROW(test.set(5), ParameterValueException); 169 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 170 CPPUNIT_ASSERT_THROW(test.set(0), ParameterValueException); 187 171 188 172 // checking all valid ones … … 331 315 test.set(Vector(4,4,4)); 332 316 CPPUNIT_ASSERT_EQUAL(true, test.ValueSet); 333 #ifndef NDEBUG334 317 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 335 CPPUNIT_ASSERT_THROW(test.setValidRange(range<Vector>(Vector(1,1,1),Vector(3,3,3))), Assert::AssertionFailure); 336 #else 337 test.setValidRange(range<Vector>(Vector(1,1,1),Vector(3,3,3))); 338 #endif 339 #ifndef NDEBUG 318 CPPUNIT_ASSERT_THROW(test.setValidRange(range<Vector>(Vector(1,1,1),Vector(3,3,3))), ParameterValueException); 319 340 320 // no value is not set 341 321 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 342 CPPUNIT_ASSERT_THROW(test.get(), Assert::AssertionFailure);343 #endif 322 CPPUNIT_ASSERT_THROW(test.get(), ParameterException); 323 344 324 // value gets invalidated in either case 345 325 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet); … … 390 370 391 371 // unset calling of get, throws 392 #ifndef NDEBUG 393 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 394 CPPUNIT_ASSERT_THROW(test.get(), Assert::AssertionFailure); 395 #endif 372 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 373 CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException); 396 374 397 375 // setting invalid, throws 398 #ifndef NDEBUG 399 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 400 CPPUNIT_ASSERT_THROW(test.set(Vector(5,0,0)), Assert::AssertionFailure); 401 #endif 402 #ifndef NDEBUG 403 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 404 CPPUNIT_ASSERT_THROW(test.set(Vector(5,20,5)), Assert::AssertionFailure); 405 #endif 376 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 377 CPPUNIT_ASSERT_THROW(test.set(Vector(5,0,0)), ParameterValueException); 378 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 379 CPPUNIT_ASSERT_THROW(test.set(Vector(5,20,5)), ParameterValueException); 406 380 407 381 CPPUNIT_ASSERT_EQUAL(false, test.ValueSet); -
src/Parameters/unittests/DiscreteValueTest.cpp
re5d7970 re45c1d 24 24 #include <cppunit/ui/text/TestRunner.h> 25 25 26 #include "Parameters/ParameterExceptions.hpp" 26 27 #include "Parameters/Value.hpp" 27 28 … … 128 129 // adding same value, throws assertion 129 130 const size_t size_before = dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).getValidValues().size(); 130 #ifndef NDEBUG131 131 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 132 132 for (int i=1; i<=6;++i) 133 CPPUNIT_ASSERT_THROW(dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).appendValidValue(i), Assert::AssertionFailure); 134 #endif 133 CPPUNIT_ASSERT_THROW(dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).appendValidValue(i), ParameterValidatorException); 135 134 CPPUNIT_ASSERT_EQUAL( size_before, dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).getValidValues().size() ); 136 135 … … 157 156 158 157 // unset calling of get, throws 159 #ifndef NDEBUG 160 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 161 CPPUNIT_ASSERT_THROW(test.get(), Assert::AssertionFailure); 162 #endif 158 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 159 CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException); 163 160 164 161 // setting invalid, throws 165 #ifndef NDEBUG 166 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 167 CPPUNIT_ASSERT_THROW(test.set(4), Assert::AssertionFailure); 168 #endif 169 #ifndef NDEBUG 170 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 171 CPPUNIT_ASSERT_THROW(test.set(0), Assert::AssertionFailure); 172 #endif 162 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 163 CPPUNIT_ASSERT_THROW(test.set(4), ParameterValueException); 164 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 165 CPPUNIT_ASSERT_THROW(test.set(0), ParameterValueException); 173 166 174 167 // checking all valid ones … … 189 182 190 183 // unset calling of get, throws 191 #ifndef NDEBUG 192 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 193 CPPUNIT_ASSERT_THROW(test.getAsString(), Assert::AssertionFailure); 194 #endif 184 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 185 CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException); 195 186 196 187 // setting invalid, throws 197 #ifndef NDEBUG 198 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 199 CPPUNIT_ASSERT_THROW(test.setAsString(toString(4)), Assert::AssertionFailure); 200 #endif 201 #ifndef NDEBUG 202 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 203 CPPUNIT_ASSERT_THROW(test.setAsString(toString(0)), Assert::AssertionFailure); 204 #endif 188 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 189 CPPUNIT_ASSERT_THROW(test.setAsString(toString(4)), ParameterValueException); 190 std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; 191 CPPUNIT_ASSERT_THROW(test.setAsString(toString(0)), ParameterValueException); 205 192 206 193 // checking all valid ones -
src/Parameters/unittests/Makefile.am
re5d7970 re45c1d 34 34 ../Parameters/unittests/ContinuousValueTest.cpp \ 35 35 ../Parameters/unittests/ContinuousValueTest.hpp \ 36 ../Parameters/ParameterExceptions.hpp \ 36 37 ../Parameters/StreamOperators.hpp \ 37 38 ../Parameters/Validators/DiscreteValidator.hpp \ … … 81 82 ../Parameters/unittests/DiscreteValueTest.cpp \ 82 83 ../Parameters/unittests/DiscreteValueTest.hpp \ 84 ../Parameters/ParameterExceptions.hpp \ 83 85 ../Parameters/Validators/DiscreteValidator.hpp \ 84 86 ../Parameters/Validators/DiscreteValidator_impl.hpp \ -
src/Parser/MpqcParser_Parameters.cpp
re5d7970 re45c1d 30 30 31 31 template <> 32 const std::string Value<bool>::getAsString() const 32 const std::string Value<bool>::getAsString() const throw(ParameterValueException) 33 33 { 34 ASSERT(ValueSet,35 "Value<bool>::getAsString() - requesting unset value.");34 if(!ValueSet) 35 throw ParameterValueException(); 36 36 if (value) 37 37 return std::string("yes"); … … 41 41 42 42 template <> 43 void Value<bool>::setAsString(const std::string _value) 43 void Value<bool>::setAsString(const std::string _value) throw(ParameterException) 44 44 { 45 45 if (_value == std::string("yes")) { … … 48 48 set(false); 49 49 } else { 50 ASSERT(0, 51 "void Value<bool>::setAsString() - value "+_value+" is neither yes or no."); 50 throw ParameterValueException(); 52 51 } 53 52 } -
src/Parser/MpqcParser_Parameters.hpp
re5d7970 re45c1d 27 27 28 28 // specialization for bool (we want "yes/no" not "1/0") 29 template <> const std::string Value<bool>::getAsString() const ;30 template <> void Value<bool>::setAsString(const std::string _value) ;29 template <> const std::string Value<bool>::getAsString() const throw(ParameterValueException); 30 template <> void Value<bool>::setAsString(const std::string _value) throw(ParameterException); 31 31 32 32 class MpqcParser; -
src/Parser/Psi3Parser_Parameters.cpp
re5d7970 re45c1d 33 33 // TODO: Value<bool>::getAsString() must be defined inline otherwise we get multiple definition of virtual thunk compilation errors 34 34 template <> 35 inline const std::string Value<bool>::getAsString() const 36 { 37 ASSERT(ValueSet,38 "Value<bool>::getAsString() - requesting unset value.");35 inline const std::string Value<bool>::getAsString() const throw(ParameterValueException) 36 { 37 if(!ValueSet) 38 throw ParameterValueException(); 39 39 if (value) 40 40 return std::string("yes"); … … 45 45 // TODO: Value<bool>::setAsString must be defined inline otherwise we get multiple definition of virtual thunk compilation errors 46 46 template <> 47 inline void Value<bool>::setAsString(const std::string _value) 47 inline void Value<bool>::setAsString(const std::string _value) throw(ParameterException) 48 48 { 49 49 if (_value == std::string("yes")) { … … 52 52 set(false); 53 53 } else { 54 ASSERT(0, 55 "void ContinuousValue<bool>::set() - value "+_value+" is neither yes or no."); 54 throw ParameterValueException(); 56 55 } 57 56 } -
src/Parser/Psi3Parser_Parameters.hpp
re5d7970 re45c1d 26 26 27 27 // specialization for bool (we want "yes/no" not "1/0") 28 template <> inline const std::string Value<bool>::getAsString() const ;29 template <> inline void Value<bool>::setAsString(const std::string _value) ;28 template <> inline const std::string Value<bool>::getAsString() const throw(ParameterValueException); 29 template <> inline void Value<bool>::setAsString(const std::string _value) throw(ParameterException); 30 30 31 31 class Psi3Parser; -
src/UIElements/Dialog.cpp
re5d7970 re45c1d 26 26 #include "CodePatterns/Verbose.hpp" 27 27 28 #include "Parameters/ParameterExceptions.hpp" 29 28 30 class Atom; 29 31 class Box; … … 65 67 bool retval = true; 66 68 for(iter=queries.begin(); iter!=queries.end(); iter++){ 67 retval &= (*iter)->handle(); 69 try { 70 retval &= (*iter)->handle(); 71 } catch (ParameterException &e) { 72 if( const std::string *name=boost::get_error_info<ParameterName>(e) ) 73 ELOG(1, "The following parameter value is not valid: " << *name << "."); 74 retval = false; 75 break; 76 } 68 77 // if any query fails (is canceled), we can end the handling process 69 78 if(!retval) { … … 78 87 list<Query*>::iterator iter; 79 88 for(iter=queries.begin(); iter!=queries.end(); iter++) { 80 (*iter)->setResult(); 89 try { 90 (*iter)->setResult(); 91 } catch (ParameterException &e) { 92 if( const std::string *name=boost::get_error_info<ParameterName>(e) ) 93 ELOG(1, "The following parameter value is not valid: " << *name << "."); 94 break; 95 } 81 96 } 82 97 }
Note:
See TracChangeset
for help on using the changeset viewer.