source: src/Parameters/Validators/Ops_Validator_impl.hpp@ 8b58ac

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 8b58ac was 33d0af, checked in by Frederik Heber <heber@…>, 13 years ago
Ops_Validators: new operators (&&,
, !)
  • created a unittest for the new Validator operators
  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * Ops_Validator_impl.hpp
3 *
4 * Created on: May 9, 2012
5 * Author: ankele
6 */
7
8#ifndef OPS_VALIDATOR_IMPL_HPP_
9#define OPS_VALIDATOR_IMPL_HPP_
10
11
12
13// include config.h
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18#include "Validator.hpp"
19
20/** Logical AND composition of two Validators.
21 *
22 */
23template <class T>
24class And_Validator : public Validator<T>
25{
26public:
27 And_Validator(const Validator<T> &_a, const Validator<T> &_b) :
28 a(_a.clone()), b(_b.clone())
29 {}
30 virtual ~And_Validator()
31 {
32 delete(a);
33 delete(b);
34 }
35
36 bool isValid(const T & _value) const {
37 return (*a)(_value) && (*b)(_value);
38 }
39
40 Validator<T>* clone() const
41 { return new And_Validator(*a, *b); }
42
43 // comparator
44 bool operator==(const Validator<T> &_instance) const
45 {
46 const And_Validator<T> *inst = dynamic_cast<const And_Validator<T> *>(&_instance);
47 if (inst)
48 return (*a == *inst->a) && (*b == *inst->b);
49 return false;
50 }
51
52private:
53 Validator<T> *a;
54 Validator<T> *b;
55};
56
57/** Logical OR composition of two Validators.
58 *
59 */
60template <class T>
61class Or_Validator : public Validator<T>
62{
63public:
64 Or_Validator(const Validator<T> &_a, const Validator<T> &_b) :
65 a(_a.clone()), b(_b.clone())
66 {}
67 virtual ~Or_Validator()
68 {
69 delete(a);
70 delete(b);
71 }
72
73 bool isValid(const T & _value) const {
74 return (*a)(_value) || (*b)(_value);
75 }
76
77 Validator<T>* clone() const
78 { return new Or_Validator(*a, *b); }
79
80 // comparator
81 bool operator==(const Validator<T> &_instance) const
82 {
83 const Or_Validator<T> *inst = dynamic_cast<const Or_Validator<T> *>(&_instance);
84 if (inst)
85 return (*a == *inst->a) && (*b == *inst->b);
86 return false;
87 }
88
89private:
90 Validator<T> *a;
91 Validator<T> *b;
92};
93
94/** Logical NOT composition of a Validator.
95 *
96 */
97template <class T>
98class Not_Validator : public Validator<T>
99{
100public:
101 Not_Validator(const Validator<T> &_a) :
102 a(_a.clone())
103 {}
104 virtual ~Not_Validator()
105 {
106 delete(a);
107 }
108
109 bool isValid(const T & _value) const {
110 return !(*a)(_value);
111 }
112
113 Validator<T>* clone() const
114 { return new Not_Validator(*a); }
115
116 // comparator
117 bool operator==(const Validator<T> &_instance) const
118 {
119 const Not_Validator<T> *inst = dynamic_cast<const Not_Validator<T> *>(&_instance);
120 if (inst)
121 return (*a == *inst->a);
122 return false;
123 }
124
125private:
126 Validator<T> *a;
127};
128
129
130
131template <class T>
132And_Validator<T> operator&&(const Validator<T> &a, const Validator<T> &b)
133{
134 return And_Validator<T>(a, b);
135}
136
137template <class T>
138Or_Validator<T> operator||(const Validator<T> &a, const Validator<T> &b)
139{
140 return Or_Validator<T>(a, b);
141}
142
143template <class T>
144Not_Validator<T> operator!(const Validator<T> &a)
145{
146 return Not_Validator<T>(a);
147}
148
149
150#endif /* OPS_VALIDATOR_IMPL_HPP_ */
Note: See TracBrowser for help on using the repository browser.