Ignore:
Timestamp:
Jun 13, 2012, 5:39:01 PM (14 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, 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)
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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_ */
Note: See TracChangeset for help on using the changeset viewer.