source: src/Parameters/Validators/Ops_Validator_impl.hpp@ 97dff0

Last change on this file since 97dff0 was e59e8e, checked in by Frederik Heber <heber@…>, 12 years ago

ParserTypeValidator + And_Validator: values readable by QtQueryList

  • Property mode set to 100644
File size: 2.8 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
52 Validator<T> *getA(){ return a; }
53 Validator<T> *getB(){ return b; }
54
55private:
56 Validator<T> *a;
57 Validator<T> *b;
58};
59
60/** Logical OR composition of two Validators.
61 *
62 */
63template <class T>
64class Or_Validator : public Validator<T>
65{
66public:
67 Or_Validator(const Validator<T> &_a, const Validator<T> &_b) :
68 a(_a.clone()), b(_b.clone())
69 {}
70 virtual ~Or_Validator()
71 {
72 delete(a);
73 delete(b);
74 }
75
76 bool isValid(const T & _value) const {
77 return (*a)(_value) || (*b)(_value);
78 }
79
80 Validator<T>* clone() const
81 { return new Or_Validator(*a, *b); }
82
83 // comparator
84 bool operator==(const Validator<T> &_instance) const
85 {
86 const Or_Validator<T> *inst = dynamic_cast<const Or_Validator<T> *>(&_instance);
87 if (inst)
88 return (*a == *inst->a) && (*b == *inst->b);
89 return false;
90 }
91
92private:
93 Validator<T> *a;
94 Validator<T> *b;
95};
96
97/** Logical NOT composition of a Validator.
98 *
99 */
100template <class T>
101class Not_Validator : public Validator<T>
102{
103public:
104 Not_Validator(const Validator<T> &_a) :
105 a(_a.clone())
106 {}
107 virtual ~Not_Validator()
108 {
109 delete(a);
110 }
111
112 bool isValid(const T & _value) const {
113 return !(*a)(_value);
114 }
115
116 Validator<T>* clone() const
117 { return new Not_Validator(*a); }
118
119 // comparator
120 bool operator==(const Validator<T> &_instance) const
121 {
122 const Not_Validator<T> *inst = dynamic_cast<const Not_Validator<T> *>(&_instance);
123 if (inst)
124 return (*a == *inst->a);
125 return false;
126 }
127
128private:
129 Validator<T> *a;
130};
131
132
133
134template <class T>
135And_Validator<T> operator&&(const Validator<T> &a, const Validator<T> &b)
136{
137 return And_Validator<T>(a, b);
138}
139
140template <class T>
141Or_Validator<T> operator||(const Validator<T> &a, const Validator<T> &b)
142{
143 return Or_Validator<T>(a, b);
144}
145
146template <class T>
147Not_Validator<T> operator!(const Validator<T> &a)
148{
149 return Not_Validator<T>(a);
150}
151
152
153#endif /* OPS_VALIDATOR_IMPL_HPP_ */
Note: See TracBrowser for help on using the repository browser.