source: src/Parameters/Value_impl.hpp@ 30ebdd

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

appendValidValue for DiscreteValidator

  • Property mode set to 100644
File size: 2.9 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#include "Validators/DiscreteValidator.hpp"
25#include "Validators/RangeValidator.hpp"
26
27/** Constructor of class Value.
28 */
29template <class T>
30Value<T>::Value() :
31 ValueSet(false),
32 validator(NULL)
33{}
34
35/** Constructor of class Value with a validator.
36 *
37 * @param _validator general validator to use
38 */
39template <class T>
40Value<T>::Value(const Validator<T> &_validator) :
41 ValueSet(false),
42 validator(_validator.clone())
43{}
44
45/** Constructor of class Value with a discrete validator.
46 *
47 * @param _ValidValues vector with all valid values
48 */
49template <class T>
50Value<T>::Value(const std::vector<T> &_ValidValues) :
51 ValueSet(false),
52 validator(NULL)
53{
54 validator = new DiscreteValidator<T>(_ValidValues);
55}
56
57/** Constructor of class Value with a range validator.
58 *
59 * @param _ValidRange range of valid values
60 */
61template <class T>
62Value<T>::Value(const range<T> &_ValidRange) :
63 ValueSet(false),
64 validator(NULL)
65{
66 validator = new RangeValidator<T>(_ValidRange);
67}
68
69/** Destructor of class Value.
70 */
71template <class T>
72Value<T>::~Value()
73{
74 if (validator)
75 delete(validator);
76}
77
78/** Checks whether \a _value is a valid value.
79 * \param _value value to check for validity.
80 * \return true - \a _value is valid, false - is not
81 */
82template <class T>
83bool Value<T>::isValid(const T & _value) const
84{
85 if (validator)
86 return (*validator)(_value);
87 return true;
88}
89
90/** Compares this discrete value against another \a _instance.
91 *
92 * @param _instance other value to compare to
93 * @return true - if value and valid ranges are the same, false - else
94 */
95template <class T>
96bool Value<T>::operator==(const Value<T> &_instance) const
97{
98 bool status = true;
99 status = status && (*validator == *_instance.validator);
100 status = status && (ValueSet == _instance.ValueSet);
101 if (ValueSet && _instance.ValueSet)
102 status = status && (value == _instance.value);
103 return status;
104}
105
106
107/** Getter of value
108 *
109 * @return value
110 */
111template <class T>
112const T & Value<T>::get() const
113{
114 ASSERT(ValueSet,
115 "Value<T>::get() - value has never been set.");
116 return value;
117}
118
119/** Setter of value
120 *
121 * @param _value new value
122 */
123template <class T>
124void Value<T>::set(const T & _value)
125{
126 ASSERT(isValid(_value),
127 "Value<T>::setValue() - trying to set invalid value "+toString(_value)+".");
128 if (!ValueSet)
129 ValueSet = true;
130 value = _value;
131}
132
133/** Returns the validator as a const reference.
134 *
135 * @return the validator
136 */
137template <class T>
138const Validator<T> &Value<T>::getValidator() const
139{
140 return *validator;
141}
142
143/** Returns the validator.
144 *
145 * @return the validator
146 */
147template <class T>
148Validator<T> &Value<T>::getValidator()
149{
150 return *validator;
151}
152
153
154
155#endif /* VALUE_IMPL_HPP_ */
Note: See TracBrowser for help on using the repository browser.