Changeset e45c1d


Ignore:
Timestamp:
Jun 13, 2012, 5:39:01 PM (13 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

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

Location:
src
Files:
1 added
19 edited

Legend:

Unmodified
Added
Removed
  • src/Parameters/ContinuousValue.hpp

    re5d7970 re45c1d  
    1818#include "CodePatterns/Range.hpp"
    1919
     20#include "Value.hpp"
    2021#include "ValueInterface.hpp"
    2122
    2223class ContinuousValueTest;
     24class ParameterException;
     25class ParameterValidatorException;
     26class ParameterValueException;
    2327
    2428/** This class represents a discrete value, it implements ValueInterface.
     
    2630 */
    2731template <class T>
    28 class ContinuousValue : virtual public ValueInterface<T>
     32class ContinuousValue : public Value<T>
    2933{
    3034  //!> unit test needs to have access to internal values
     
    3640
    3741  // 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);
    4143
    4244  // comfortable setter
     
    4547
    4648  // 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)
    4951      { return !((*this)==(_instance)); }
    5052
    5153  // 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);
    5456
    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
    5958
    6059private:
  • src/Parameters/ContinuousValue_impl.hpp

    re5d7970 re45c1d  
    2323
    2424#include "ContinuousValue.hpp"
     25
     26#include "ParameterExceptions.hpp"
    2527
    2628/** Constructor of class DiscreteValue.
     
    5658 */
    5759template <class T>
    58 bool ContinuousValue<T>::isValid(const T & _value) const
     60bool ContinuousValue<T>::isValid(const T & _value) const throw(ParameterValidatorException)
    5961{
    6062  bool isBefore = true;
    6163  bool isBeyond = true;
    6264  // check left boundary
    63   isBefore = !((!ValidRangeSet.first) || (!ValidRange.isBefore(_value)));
     65  if ((!ValidRangeSet.first) || (!ValidRangeSet.last))
     66    throw ParameterValidatorException();
     67  isBefore = !((!ValidRange.isBefore(_value)));
    6468//  if (isBefore)
    6569//    LOG(0, "INFO: " << _value << " is before " << ValidRange.first << ".");
    6670  // check right boundary
    67   isBeyond = !((!ValidRangeSet.last) || (!ValidRange.isBeyond(_value)) || (_value == ValidRange.last));
     71  isBeyond = !((!ValidRange.isBeyond(_value)) || (_value == ValidRange.last));
    6872//  if (isBeyond)
    6973//    LOG(0, "INFO: " << _value << " is beyond " << ValidRange.last << ".");
     
    7781 */
    7882template <class T>
    79 bool ContinuousValue<T>::operator==(const ContinuousValue<T> &_instance) const
     83bool ContinuousValue<T>::operator==(const ContinuousValue<T> &_instance) const const throw(ParameterException)
    8084{
    8185  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();
    8291  status = status && (ValidRange == _instance.ValidRange);
    8392  status = status && (ValueSet == _instance.ValueSet);
    84   if (ValueSet && _instance.ValueSet)
    85     status = status && (value == _instance.value);
     93  status = status && (value == _instance.value);
    8694  return status;
    87 }
    88 
    89 /** Getter of value, returning string.
    90  *
    91  * @return string value
    92  */
    93 template <class T>
    94 const T & ContinuousValue<T>::get() const
    95 {
    96   ASSERT(ValueSet,
    97       "ContinuousValue<T>::get() - requesting unset value.");
    98   return value;
    99 }
    100 
    101 /** Setter of value for string
    102  *
    103  * @param _value string containing new value
    104  */
    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 << ".");
    11495}
    11596
     
    121102 */
    122103template <class T>
    123 void ContinuousValue<T>::setValidRange(const range<T> &_range)
     104void ContinuousValue<T>::setValidRange(const range<T> &_range) throw(ParameterValueException)
    124105{
    125 
    126106  ValidRangeSet = range<bool>(true, true);
    127107  ValidRange = _range;
     
    132112      ValueSet = false;
    133113      // 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));
    137116    }
    138117  }
     
    145124 */
    146125template <class T>
    147 const range<T> & ContinuousValue<T>::getValidRange() const
     126const range<T> & ContinuousValue<T>::getValidRange() const throw(ParameterValidatorException)
    148127{
    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();
    151130  return ValidRange;
    152131}
    153132
    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 not
    157  */
    158 template <class T>
    159 bool ContinuousValue<T>::isValidAsString(const std::string _value) const
    160 {
    161   /*bool isBefore = true;
    162   bool isBeyond = true;
    163   // check left boundary
    164   isBefore = !((!ValidRangeSet.first) || (!ValidRange.isBefore(_value)));
    165 //  if (isBefore)
    166 //    LOG(0, "INFO: " << _value << " is before " << ValidRange.first << ".");
    167   // check right boundary
    168   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 set
    181  */
    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 value
    197  */
    198 template <class T>
    199 const std::string ContinuousValue<T>::getAsString() const
    200 {
    201   ASSERT(ValueSet,
    202       "ContinuousValue<T>::get() - value has never been set.");
    203   return toString(value);
    204 }
    205 
    206133#endif /* CONTINUOUSVALUE_IMPL_HPP_ */
  • src/Parameters/Parameter.hpp

    re5d7970 re45c1d  
    2121#include "ParameterInterface.hpp"
    2222
     23class ParameterException;
     24class ParameterValueException;
     25
    2326/** This class encapsulates a clonable, continuous value.
    2427 *
     
    3942  virtual ~Parameter();
    4043
     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
    4150  // 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)
    4453      { return !((*this)==(_instance)); }
    4554
  • src/Parameters/Parameter_impl.hpp

    re5d7970 re45c1d  
    1515
    1616#include "Parameter.hpp"
    17 
     17#include "ParameterExceptions.hpp"
    1818
    1919
     
    139139{};
    140140
     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
    141201/** Compares this continuous value against another \a _instance.
    142202 *
     
    145205 */
    146206template <class T>
    147 bool Parameter<T>::operator==(const Parameter<T> &_instance) const
     207bool Parameter<T>::operator==(const Parameter<T> &_instance) const throw(ParameterException)
    148208{
    149209  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  }
    153218  return status;
    154219}
  • src/Parameters/Validators/DiscreteValidator.hpp

    re5d7970 re45c1d  
    2020
    2121class DiscreteValueTest;
     22class ParameterValidatorException;
    2223
    2324/** A validator with a discrete list of valid values.
     
    4041  bool operator==(const Validator<T> &_instance) const;
    4142
    42   void appendValidValue(const T &_value);
     43  void appendValidValue(const T &_value) throw(ParameterValidatorException);
    4344  const std::vector<T> &getValidValues() const;
    4445
  • src/Parameters/Validators/DiscreteValidator_impl.hpp

    re5d7970 re45c1d  
    1515#endif
    1616
     17#include "Parameters/ParameterExceptions.hpp"
    1718#include <algorithm>
    1819
     
    4748
    4849template <class T>
    49 void DiscreteValidator<T>::appendValidValue(const T &_value)
     50void DiscreteValidator<T>::appendValidValue(const T &_value) throw(ParameterValidatorException)
    5051{
    51   ASSERT(!isValid(_value),
    52       "DiscreteValidator<>::appendValidValue() - value "+toString(_value)+" is already among the valid");
     52  if (isValid(_value))
     53    throw ParameterValidatorException();
    5354  ValidValues.push_back(_value);
    5455}
  • src/Parameters/Validators/RangeValidator.hpp

    re5d7970 re45c1d  
    1717#include "Validator.hpp"
    1818#include "CodePatterns/Range.hpp"
     19
     20class ParameterValueException;
    1921
    2022/** A validator with an interval of valid values.
     
    3739
    3840  // getter/setter for valid ranges
    39   void setValidRange(const range<T> &_range);
     41  void setValidRange(const range<T> &_range) throw(ParameterValueException);
    4042  const range<T> & getValidRange() const {  return ValidRange;  };
    4143
  • src/Parameters/Validators/RangeValidator_impl.hpp

    re5d7970 re45c1d  
    1414#include <config.h>
    1515#endif
     16
     17#include "Parameters/ParameterExceptions.hpp"
    1618
    1719template <class T>
     
    5052/** Setter for the valid range.
    5153 *
    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>.
    5355 *
    5456 * @param _range range (pair of values)
    5557 */
    5658template <class T>
    57 void RangeValidator<T>::setValidRange(const range<T> &_range)
     59void RangeValidator<T>::setValidRange(const range<T> &_range) throw(ParameterValueException)
    5860{
    5961  ValidRange = _range;
    6062}
    61 
    62 
    63 
    64 
    65 
    6663
    6764// specialization for Vector
  • src/Parameters/Value.hpp

    re5d7970 re45c1d  
    2929template <class T>
    3030class Parameter;
     31class ParameterException;
     32class ParameterValidatorException;
     33class ParameterValueException;
    3134
    3235/** Converter for a string to a std::vector of any class
     
    6871
    6972  // 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);
    7376  bool isSet() const;
    7477
    7578  // 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);
    7982
    8083  // comfortable setter
     
    8386
    8487  // 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)
    8790      { return !((*this)==(_instance)); }
    8891
     
    9194
    9295  // 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);
    97100
    98101private:
  • src/Parameters/ValueInterface.hpp

    re5d7970 re45c1d  
    1616#include <string>
    1717
     18#include "ParameterExceptions.hpp"
    1819#include "ValueAsString.hpp"
    1920
     
    2829
    2930  // 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;
    3334  virtual bool isSet() const=0;
    3435};
  • src/Parameters/Value_impl.hpp

    re5d7970 re45c1d  
    2525#include "Validators/DiscreteValidator.hpp"
    2626#include "Validators/RangeValidator.hpp"
    27 
    28 
     27#include "ParameterExceptions.hpp"
    2928
    3029// static member
     
    8887 */
    8988template <class T>
    90 bool Value<T>::isValid(const T & _value) const
    91 {
    92   ASSERT(validator,
    93       "Value<T>::isValid() - validator missing.");
     89bool Value<T>::isValid(const T & _value) const throw(ParameterValidatorException)
     90{
     91  if (validator == NULL) throw ParameterValidatorException();
    9492  return (*validator)(_value);
    9593}
     
    10199 */
    102100template <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.");
     101bool Value<T>::operator==(const Value<T> &_instance) const throw(ParameterValidatorException)
     102{
     103  if (validator == NULL) throw ParameterValidatorException();
     104  if (_instance.validator == NULL) throw ParameterValidatorException();
    109105  bool status = true;
    110106  status = status && (*validator == *_instance.validator);
     
    121117 */
    122118template <class T>
    123 const T & Value<T>::get() const
    124 {
    125   ASSERT(ValueSet,
    126       "Value<T>::get() - value has never been set.");
     119const T & Value<T>::get() const throw(ParameterValueException)
     120{
     121  if (!ValueSet) throw ParameterValueException();
    127122  return value;
    128123}
     
    133128 */
    134129template <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)+".");
     130void Value<T>::set(const T & _value) throw(ParameterException)
     131{
     132  if (!isValid(_value)) throw ParameterValueException();
    139133  if (!ValueSet)
    140134    ValueSet = true;
     
    160154 */
    161155template <class T>
    162 bool Value<T>::isValidAsString(const std::string _value) const
     156bool Value<T>::isValidAsString(const std::string _value) const throw(ParameterValidatorException)
    163157{
    164158  const T castvalue = Converter(_value);
     
    168162
    169163template <>
    170 inline bool Value<std::string>::isValidAsString(const std::string _value) const
     164inline bool Value<std::string>::isValidAsString(const std::string _value) const throw(ParameterValidatorException)
    171165{
    172166  return isValid(_value);
     
    178172 */
    179173template <class T>
    180 const std::string Value<T>::getAsString() const
    181 {
    182   ASSERT(ValueSet,
    183       "Value<T>::getAsString() - requesting unset value.");
     174const std::string Value<T>::getAsString() const throw(ParameterValueException)
     175{
     176  if (!ValueSet) throw ParameterValueException();
    184177  return toString(value);
    185178}
     
    190183 */
    191184template <class T>
    192 void Value<T>::setAsString(const std::string _value)
     185void Value<T>::setAsString(const std::string _value) throw(ParameterException)
    193186{
    194187  const T castvalue = Converter(_value);
     
    199192
    200193template <>
    201 inline void Value<std::string>::setAsString(const std::string _value)
     194inline void Value<std::string>::setAsString(const std::string _value) throw(ParameterException)
    202195{
    203196  set(_value);
     
    212205const Validator<T> &Value<T>::getValidator() const
    213206{
    214   ASSERT(validator,
    215       "Value<T>::getValidator() const - validator missing.");
     207  if (validator == NULL) throw ParameterValidatorException();
    216208  return *validator;
    217209}
     
    224216Validator<T> &Value<T>::getValidator()
    225217{
    226   ASSERT(validator,
    227       "Value<T>::getValidator() - validator missing.");
     218  if (validator == NULL) throw ParameterValidatorException();
    228219  return *validator;
    229220}
     
    232223
    233224template <class T>
    234 const range<T> & Value<T>::getValidRange() const
     225const range<T> & Value<T>::getValidRange() const throw(ParameterValidatorException)
    235226{
    236227  dynamic_cast<RangeValidator<T>&>(getValidator()).getValidRange();
     
    239230/** Setter for the valid range.
    240231 *
    241  * If value is invalid in new range, we throw AssertFailure and set ValueSet to false.
     232 * If value is invalid in new range, we throw ParameterValueException and set ValueSet to false.
    242233 *
    243234 * @param _range range (pair of values)
    244235 */
    245236template <class T>
    246 void Value<T>::setValidRange(const range<T> &_range)
     237void Value<T>::setValidRange(const range<T> &_range) throw(ParameterValueException)
    247238{
    248239  dynamic_cast<RangeValidator<T>&>(getValidator()).setValidRange(_range);
     
    253244      ValueSet = false;
    254245      // 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));
    258247    }
    259248  }
     
    262251
    263252template <class T>
    264 void Value<T>::appendValidValue(const T &_value)
     253void Value<T>::appendValidValue(const T &_value) throw(ParameterValidatorException)
    265254{
    266255  dynamic_cast<DiscreteValidator<T>&>(getValidator()).appendValidValue(_value);
     
    268257
    269258template <class T>
    270 const std::vector<T> &Value<T>::getValidValues() const
     259const std::vector<T> &Value<T>::getValidValues() const throw(ParameterValidatorException)
    271260{
    272261  dynamic_cast<DiscreteValidator<T>&>(getValidator()).getValidValues();
  • src/Parameters/unittests/ContinuousValueTest.cpp

    re5d7970 re45c1d  
    113113    test.set(4);
    114114    CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
    115 #ifndef NDEBUG
    116115    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
    122118    // no value is not set
    123119    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
    126122    // value gets invalidated in either case
    127123    CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
     
    137133  Value<int> test(*ValidIntRange);
    138134
    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);
    154144
    155145  CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
     
    170160  Value<int> test(*ValidIntRange);
    171161
    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);
    187171
    188172  // checking all valid ones
     
    331315    test.set(Vector(4,4,4));
    332316    CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
    333 #ifndef NDEBUG
    334317    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
    340320    // no value is not set
    341321    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
    344324    // value gets invalidated in either case
    345325    CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
     
    390370
    391371  // 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);
    396374
    397375  // 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);
    406380
    407381  CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
  • src/Parameters/unittests/DiscreteValueTest.cpp

    re5d7970 re45c1d  
    2424#include <cppunit/ui/text/TestRunner.h>
    2525
     26#include "Parameters/ParameterExceptions.hpp"
    2627#include "Parameters/Value.hpp"
    2728
     
    128129  // adding same value, throws assertion
    129130  const size_t size_before = dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).getValidValues().size();
    130 #ifndef NDEBUG
    131131  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    132132  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);
    135134  CPPUNIT_ASSERT_EQUAL( size_before, dynamic_cast<DiscreteValidator<int> &>(test.getValidator()).getValidValues().size() );
    136135
     
    157156
    158157  // 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);
    163160
    164161  // 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);
    173166
    174167  // checking all valid ones
     
    189182
    190183  // 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);
    195186
    196187  // 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);
    205192
    206193  // checking all valid ones
  • src/Parameters/unittests/Makefile.am

    re5d7970 re45c1d  
    3434        ../Parameters/unittests/ContinuousValueTest.cpp \
    3535        ../Parameters/unittests/ContinuousValueTest.hpp \
     36        ../Parameters/ParameterExceptions.hpp \
    3637        ../Parameters/StreamOperators.hpp \
    3738        ../Parameters/Validators/DiscreteValidator.hpp \
     
    8182        ../Parameters/unittests/DiscreteValueTest.cpp \
    8283        ../Parameters/unittests/DiscreteValueTest.hpp \
     84        ../Parameters/ParameterExceptions.hpp \
    8385        ../Parameters/Validators/DiscreteValidator.hpp \
    8486        ../Parameters/Validators/DiscreteValidator_impl.hpp \
  • src/Parser/MpqcParser_Parameters.cpp

    re5d7970 re45c1d  
    3030
    3131template <>
    32 const std::string Value<bool>::getAsString() const
     32const std::string Value<bool>::getAsString() const throw(ParameterValueException)
    3333{
    34   ASSERT(ValueSet,
    35       "Value<bool>::getAsString() - requesting unset value.");
     34  if(!ValueSet)
     35    throw ParameterValueException();
    3636  if (value)
    3737    return std::string("yes");
     
    4141
    4242template <>
    43 void Value<bool>::setAsString(const std::string _value)
     43void Value<bool>::setAsString(const std::string _value) throw(ParameterException)
    4444{
    4545  if (_value == std::string("yes")) {
     
    4848    set(false);
    4949  } else {
    50     ASSERT(0,
    51         "void Value<bool>::setAsString() - value "+_value+" is neither yes or no.");
     50    throw ParameterValueException();
    5251  }
    5352}
  • src/Parser/MpqcParser_Parameters.hpp

    re5d7970 re45c1d  
    2727
    2828// 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);
     29template <> const std::string Value<bool>::getAsString() const throw(ParameterValueException);
     30template <> void Value<bool>::setAsString(const std::string _value) throw(ParameterException);
    3131
    3232class MpqcParser;
  • src/Parser/Psi3Parser_Parameters.cpp

    re5d7970 re45c1d  
    3333// TODO: Value<bool>::getAsString() must be defined inline otherwise we get multiple definition of virtual thunk compilation errors
    3434template <>
    35 inline const std::string Value<bool>::getAsString() const
    36 {
    37   ASSERT(ValueSet,
    38       "Value<bool>::getAsString() - requesting unset value.");
     35inline const std::string Value<bool>::getAsString() const throw(ParameterValueException)
     36{
     37  if(!ValueSet)
     38    throw ParameterValueException();
    3939  if (value)
    4040    return std::string("yes");
     
    4545// TODO: Value<bool>::setAsString must be defined inline otherwise we get multiple definition of virtual thunk compilation errors
    4646template <>
    47 inline void Value<bool>::setAsString(const std::string _value)
     47inline void Value<bool>::setAsString(const std::string _value) throw(ParameterException)
    4848{
    4949  if (_value == std::string("yes")) {
     
    5252    set(false);
    5353  } else {
    54     ASSERT(0,
    55         "void ContinuousValue<bool>::set() - value "+_value+" is neither yes or no.");
     54    throw ParameterValueException();
    5655  }
    5756}
  • src/Parser/Psi3Parser_Parameters.hpp

    re5d7970 re45c1d  
    2626
    2727// 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);
     28template <> inline const std::string Value<bool>::getAsString() const throw(ParameterValueException);
     29template <> inline void Value<bool>::setAsString(const std::string _value) throw(ParameterException);
    3030
    3131class Psi3Parser;
  • src/UIElements/Dialog.cpp

    re5d7970 re45c1d  
    2626#include "CodePatterns/Verbose.hpp"
    2727
     28#include "Parameters/ParameterExceptions.hpp"
     29
    2830class Atom;
    2931class Box;
     
    6567  bool retval = true;
    6668  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    }
    6877    // if any query fails (is canceled), we can end the handling process
    6978    if(!retval) {
     
    7887  list<Query*>::iterator iter;
    7988  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    }
    8196  }
    8297}
Note: See TracChangeset for help on using the changeset viewer.