source: src/Parameters/Value_impl.hpp@ a9a8f9

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
Last change on this file since a9a8f9 was a9a8f9, checked in by Michael Ankele <ankele@…>, 14 years ago

Value implementation

  • Validator made cloneable
  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 * Value_impl.hpp
3 *
4 * Created on: Apr 13, 2012
5 * Author: ankele
6 */
7
8#ifndef VALUE_IMPL_HPP_
9#define VALUE_IMPL_HPP_
10
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17
18#include <boost/any.hpp>
19
20#include "CodePatterns/Assert.hpp"
21
22#include "CodePatterns/Log.hpp"
23
24/** Constructor of class Value.
25 */
26template <class T>
27Value<T>::Value() :
28 ValueSet(false),
29 validator(NULL)
30{}
31
32/** Constructor of class Value with a validator.
33 *
34 * @param _ValidValues vector with all valid values
35 */
36template <class T>
37Value<T>::Value(const Validator<T> &_validator) :
38 ValueSet(false),
39 validator(_validator.clone()) // TODO...
40{}
41
42/** Destructor of class Value.
43 */
44template <class T>
45Value<T>::~Value()
46{
47 if (validator)
48 delete(validator);
49}
50
51/** Checks whether \a _value is a valid value.
52 * \param _value value to check for validity.
53 * \return true - \a _value is valid, false - is not
54 */
55template <class T>
56bool Value<T>::isValid(const T & _value) const
57{
58 if (validator)
59 return (*validator)(_value);
60 return true;
61}
62
63/** Compares this discrete value against another \a _instance.
64 *
65 * @param _instance other value to compare to
66 * @return true - if value and valid ranges are the same, false - else
67 */
68template <class T>
69bool Value<T>::operator==(const Value<T> &_instance) const
70{
71 bool status = true;
72 status = status && (ValidValues == _instance.ValidValues);
73 status = status && (ValueSet == _instance.ValueSet);
74 if (ValueSet && _instance.ValueSet)
75 status = status && (value == _instance.value);
76 return status;
77}
78
79
80/** Getter of value
81 *
82 * @return value
83 */
84template <class T>
85const T & Value<T>::get() const
86{
87 ASSERT(ValueSet,
88 "Value<T>::get() - value has never been set.");
89 return value;
90}
91
92/** Setter of value
93 *
94 * @param _value new value
95 */
96template <class T>
97void Value<T>::set(const T & _value)
98{
99 ASSERT(isValid(_value),
100 "Value<T>::setValue() - trying to set invalid value "+toString(_value)+".");
101 if (!ValueSet)
102 ValueSet = true;
103 value = _value;
104}
105
106/** Returns the validator.
107 *
108 * @return the validator
109 */
110template <class T>
111const Validator<T> &Value<T>::getValidator() const
112{
113 return *validator;
114}
115
116
117
118#endif /* VALUE_IMPL_HPP_ */
Note: See TracBrowser for help on using the repository browser.