Changeset cf1d82 for src/Parameters


Ignore:
Timestamp:
Feb 13, 2013, 3:47:46 PM (12 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:
4d4ef8
Parents:
6440c6
git-author:
Frederik Heber <heber@…> (01/10/13 16:02:33)
git-committer:
Frederik Heber <heber@…> (02/13/13 15:47:46)
Message:

Parameter now contains Value, not inherits.

  • added several function to fully wrap all Value member functions.
  • this should prevent any vtable clashes between Parameter and Value that both inherit ValueAsString.
  • MpqcParser_Parameters.hpp does not contain any reference to the templated parts of Parameter or Value. These are only contained in the .cpp module.
Location:
src/Parameters
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Parameters/Parameter.hpp

    r6440c6 rcf1d82  
    1919
    2020#include "Value.hpp"
     21#include "ValueInterface.hpp"
    2122#include "ParameterInterface.hpp"
    2223
     
    2930template <typename T>
    3031class Parameter :
    31   virtual public ParameterInterface,
    32   virtual public Value<T>
     32  public ParameterInterface,
     33  public ValueInterface<T>
    3334{
    3435public:
     
    4445  virtual ~Parameter();
    4546
    46   // catch the following functions from Value<T> to add exception information
     47  // wrap the following functions from ValueAsString to add exception information
     48  bool isValidAsString(const std::string &_value) const throw(ParameterValidatorException);
    4749  const std::string getAsString() const throw(ParameterValueException);
     50  void setAsString(const std::string &_value) throw(ParameterValueException);
     51
     52  // wrap the following functions from Value<T> to add exception information
     53  bool isValid(const T &_value) const throw(ParameterValidatorException);
    4854  const T & get() const throw(ParameterValueException);
    4955  void set(const T & _value) throw(ParameterValueException);
    50   void setAsString(const std::string &_value) throw(ParameterValueException);
     56  bool isSet() const
     57  { return value.isSet(); }
     58
     59  const Validator<T> & getValidator() const
     60  { return value.getValidator(); }
     61  Validator<T> & getValidator()
     62  { return value.getValidator(); }
    5163
    5264  // comparator
     
    5971//private: // TODO...
    6072  Parameter();
     73
     74private:
     75  //!> contained value of this parameter
     76  Value<T> value;
    6177};
    6278
  • src/Parameters/ParameterInterface.hpp

    r6440c6 rcf1d82  
    2424 */
    2525class ParameterInterface :
    26   virtual public ValueAsString,
     26  public ValueAsString,
    2727  public Clone<ParameterInterface>
    2828{
  • src/Parameters/Parameter_impl.hpp

    r6440c6 rcf1d82  
    2121Parameter<T>::Parameter(const Parameter<T> &instance) :
    2222  ParameterInterface(instance.getName()),
    23   Value<T>(instance.getValidator())
    24 {
    25   Value<T>::set(instance.Value<T>::get());
     23  value(instance.value.getValidator())
     24{
     25  value.set(instance.value.get());
    2626}
    2727
     
    3232Parameter<T>::Parameter() :
    3333  ParameterInterface("__no_name__"),
    34   Value<T>()
     34  value()
    3535{};
    3636
     
    4141Parameter<T>::Parameter(const std::string &_name) :
    4242  ParameterInterface(_name),
    43   Value<T>()
     43  value()
    4444{};
    4545
     
    5252Parameter<T>::Parameter(const std::string &_name, const T &_value) :
    5353  ParameterInterface(_name),
    54   Value<T>()
    55 {
    56   Value<T>::set(_value);
     54  value()
     55{
     56  value.set(_value);
    5757};
    5858
     
    6565Parameter<T>::Parameter(const std::string &_name, const Validator<T> &_Validator) :
    6666  ParameterInterface(_name),
    67   Value<T>(_Validator)
     67  value(_Validator)
    6868{};
    6969
     
    7777Parameter<T>::Parameter(const std::string &_name, const Validator<T> &_Validator, const T &_value) :
    7878  ParameterInterface(_name),
    79   Value<T>(_Validator)
    80 {
    81   Value<T>::set(_value);
     79  value(_Validator)
     80{
     81  value.set(_value);
    8282};
    8383
     
    9090Parameter<T>::Parameter(const std::string &_name, const std::vector<T> &_ValidValues) :
    9191  ParameterInterface(_name),
    92   Value<T>(_ValidValues)
     92  value(_ValidValues)
    9393{};
    9494
     
    102102Parameter<T>::Parameter(const std::string &_name, const std::vector<T> &_ValidValues, const T &_value) :
    103103  ParameterInterface(_name),
    104   Value<T>(_ValidValues)
    105 {
    106   Value<T>::set(_value);
     104  value(_ValidValues)
     105{
     106  value.set(_value);
    107107};
    108108
     
    115115Parameter<T>::Parameter(const std::string &_name, const range<T> &_ValidRange) :
    116116  ParameterInterface(_name),
    117   Value<T>(_ValidRange)
     117  value(_ValidRange)
    118118{};
    119119
     
    127127Parameter<T>::Parameter(const std::string &_name, const range<T> &_ValidRange, const T &_value) :
    128128  ParameterInterface(_name),
    129   Value<T>(_ValidRange)
    130 {
    131   Value<T>::set(_value);
     129  value(_ValidRange)
     130{
     131  value.set(_value);
    132132};
    133133
     
    139139{};
    140140
    141 /** Catch call to Value<T>::getAsString() to add exception information.
     141/** Catch call to value.isValidAsString() to add exception information.
     142 *
     143 * @param _value value to set to
     144 */
     145template<typename T>
     146inline
     147bool Parameter<T>::isValidAsString(const std::string &_value) const throw(ParameterValidatorException)
     148{
     149  try {
     150    return value.isValidAsString(_value);
     151  } catch(ParameterException &e) {
     152    e << ParameterName(ParameterInterface::getName());
     153    throw;
     154  }
     155}
     156
     157
     158/** Catch call to value.getAsString() to add exception information.
    142159 *
    143160 * @return parameter value as string
     
    147164{
    148165  try {
    149     return Value<T>::getAsString();
    150   } catch(ParameterException &e) {
    151     e << ParameterName(ParameterInterface::getName());
    152     throw;
    153   }
    154 }
    155 
    156 /** Catch call to Value<T>::get() to add exception information.
     166    return value.getAsString();
     167  } catch(ParameterException &e) {
     168    e << ParameterName(ParameterInterface::getName());
     169    throw;
     170  }
     171}
     172
     173/** Catch call to value.isValid() to add exception information.
    157174 *
    158175 * @return parameter value as string
    159176 */
    160177template<typename T>
     178inline bool Parameter<T>::isValid(const T &_value) const throw(ParameterValidatorException)
     179{
     180  try {
     181    return value.isValid(_value);
     182  } catch(ParameterException &e) {
     183    e << ParameterName(ParameterInterface::getName());
     184    throw;
     185  }
     186}
     187
     188
     189/** Catch call to value.get() to add exception information.
     190 *
     191 * @return parameter value as string
     192 */
     193template<typename T>
    161194inline const T & Parameter<T>::get() const throw(ParameterValueException)
    162195{
    163196  try {
    164     return Value<T>::get();
    165   } catch(ParameterException &e) {
    166     e << ParameterName(ParameterInterface::getName());
    167     throw;
    168   }
    169 }
    170 
    171 /** Catch call to Value<T>::set() to add exception information.
     197    return value.get();
     198  } catch(ParameterException &e) {
     199    e << ParameterName(ParameterInterface::getName());
     200    throw;
     201  }
     202}
     203
     204/** Catch call to value.set() to add exception information.
    172205 *
    173206 * @param _value value to set to
     
    177210{
    178211  try {
    179     Value<T>::set(_value);
    180   } catch(ParameterException &e) {
    181     e << ParameterName(ParameterInterface::getName());
    182     throw;
    183   }
    184 }
    185 
    186 /** Catch call to Value<T>::set() to add exception information.
     212    value.set(_value);
     213  } catch(ParameterException &e) {
     214    e << ParameterName(ParameterInterface::getName());
     215    throw;
     216  }
     217}
     218
     219/** Catch call to value.set() to add exception information.
    187220 *
    188221 * @param _value value to set to
     
    192225{
    193226  try {
    194     Value<T>::setAsString(_value);
     227    value.setAsString(_value);
    195228  } catch(ParameterException &e) {
    196229    e << ParameterName(ParameterInterface::getName());
     
    210243  try {
    211244    status = status &&
    212         (*dynamic_cast<const Value<T> *>(this) == dynamic_cast<const Value<T> &>(_instance));
     245        (value == _instance.value);
    213246    status = status && (ParameterInterface::getName() == _instance.ParameterInterface::getName());
    214247  } catch(ParameterException &e) {
     
    226259inline ParameterInterface* Parameter<T>::clone() const
    227260{
    228   Parameter<T> *instance = new Parameter<T>(ParameterInterface::getName(), Value<T>::getValidator());
    229   if (Value<T>::ValueSet)
    230     instance->set(Value<T>::get());
     261  Parameter<T> *instance = new Parameter<T>(ParameterInterface::getName(), value.getValidator());
     262  if (value.ValueSet)
     263    instance->set(value.get());
    231264  return instance;
    232265}
  • src/Parameters/Value.hpp

    r6440c6 rcf1d82  
    5959template <class T>
    6060class Value :
    61   virtual public ValueAsString,
     61  public ValueAsString,
    6262  public ValueInterface<T>
    6363{
Note: See TracChangeset for help on using the changeset viewer.