source: src/Parameters/Validators/Ops_Validator_impl.hpp

Candidate_v1.6.1
Last change on this file was dae158, checked in by Frederik Heber <heber@…>, 10 years ago

FileQtQuery retrieves valid suffixes from validators.

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