AuboStudio SDK 0.6.3

input_validator.h
浏览该文件的文档.
1 #ifndef AUBO_SCOPE_KEYBOARD_INPUT_VALIDATOR_H
2 #define AUBO_SCOPE_KEYBOARD_INPUT_VALIDATOR_H
3
4 #include <string>
5 #include <functional>
6 #include <float.h>
7
8 #include <QObject>
9
10 #include <aubo_caps/domain/value/expression/expression.h>
11
12 namespace arcs {
13 namespace aubo_scope {
14
15 /**
16 * <p>
17 * Interface representing the input validators created by {@link
18 * InputValidationFactory}. This factory provides a set of standard input
19 * validators that can be used for validating the input entered by the user
20 * using the virtual keyboard/keypad.
21 * </p>
22 *
23 * If the standard validators available in the {@link InputValidationFactory}
24 * does not satisfy your needs, you are free to implement your own custom
25 * validator.
26 *
27 * @param <T> the (generic) type parameter for the interface representing the
28 * type of input data being validated (e.g. Integer or Double).
29 */
30 struct InputValidator
31 {
32 /**
33 * @param value to be validated.
34 * @return <code>true</code> if value is valid.
35 */
36 virtual bool isValid(std::string value) = 0;
37
38 /**
39 * Returns a meaningful message in case the value is not valid.
40 *
41 * @param value the invalid value. Can be included in the message if it
42 * makes sense.
43 * @return message.
44 */
45 virtual std::string getMessage(std::string value) = 0;
46 };
47
48 struct IntegerRangeValidator : InputValidator
49 {
50 IntegerRangeValidator(int min_value, int max_value);
51
52 IntegerRangeValidator(std::function<std::pair<int, int>()> range_func);
53
54 bool isValid(std::string value) override;
55
56 std::string getMessage(std::string value) override;
57
58 private:
59 void updateValue();
60
61 private:
62 int min_value_{ INT_MIN };
63 int max_value_{ INT_MAX };
64
65 std::function<std::pair<int, int>()> range_func_{ nullptr };
66 };
67
68 struct UIntegerRangeValidator : InputValidator
69 {
70 UIntegerRangeValidator(uint32_t min_value, uint32_t max_value);
71
72 UIntegerRangeValidator(
73 std::function<std::pair<uint32_t, uint32_t>()> range_func);
74
75 bool isValid(std::string value) override;
76
77 std::string getMessage(std::string value) override;
78
79 private:
80 void updateValue();
81
82 private:
83 uint32_t min_value_{ 0 };
84 uint32_t max_value_{ UINT_MAX };
85
86 std::function<std::pair<uint32_t, uint32_t>()> range_func_{ nullptr };
87 };
88
89 struct DoubleRangeValidator : InputValidator
90 {
91 DoubleRangeValidator(double minValue, double maxValue,
92 bool is_min_inclusive = true,
93 bool is_max_inclusive = true);
94
95 DoubleRangeValidator(std::function<std::pair<double, double>()> range_func);
96
97 DoubleRangeValidator(
98 std::function<std::tuple<double, double, bool, bool>()> range_func);
99
100 bool isValid(std::string value) override;
101
102 std::string getMessage(std::string value) override;
103
104 private:
105 void updateValue();
106
107 private:
108 double min_value_{ DBL_MIN };
109 double max_value_{ DBL_MAX };
110 std::function<std::pair<double, double>()> range_func_{ nullptr };
111 std::function<std::tuple<double, double, bool, bool>()>
112 range_func_with_flags_{ nullptr };
113 bool is_min_inclusive_{ true }; // 最小值是否闭区间
114 bool is_max_inclusive_{ true }; // 最大值是否闭区间
115 };
116
117 struct StringLengthValidator : InputValidator
118 {
119 StringLengthValidator(size_t min_length, size_t max_length);
120
121 StringLengthValidator(
122 std::function<std::pair<size_t, size_t>()> range_func);
123
124 bool isValid(std::string value) override;
125
126 std::string getMessage(std::string value) override;
127
128 private:
129 void updateValue();
130
131 private:
132 size_t min_length_{ 0 };
133 size_t max_length_{ ULONG_MAX };
134 std::function<std::pair<size_t, size_t>()> range_func_{ nullptr };
135 };
136
137 } // namespace aubo_scope
138 } // namespace arcs
139
140 #endif
expression.h
arcs
Definition: contribution_provider.h:7
arcs::aubo_scope::DoubleRangeValidator
Definition: input_validator.h:90
arcs::aubo_scope::DoubleRangeValidator::min_value_
double min_value_
Definition: input_validator.h:108
arcs::aubo_scope::DoubleRangeValidator::range_func_
std::function< std::pair< double, double >)> range_func_
Definition: input_validator.h:110
arcs::aubo_scope::DoubleRangeValidator::getMessage
std::string getMessage(std::string value) override
Returns a meaningful message in case the value is not valid.
arcs::aubo_scope::DoubleRangeValidator::max_value_
double max_value_
Definition: input_validator.h:109
arcs::aubo_scope::DoubleRangeValidator::DoubleRangeValidator
DoubleRangeValidator(double minValue, double maxValue, bool is_min_inclusive=true, bool is_max_inclusive=true)
arcs::aubo_scope::DoubleRangeValidator::DoubleRangeValidator
DoubleRangeValidator(std::function< std::pair< double, double >()> range_func)
arcs::aubo_scope::DoubleRangeValidator::range_func_with_flags_
std::function< std::tuple< double, double, bool, bool >)> range_func_with_flags_
Definition: input_validator.h:112
arcs::aubo_scope::DoubleRangeValidator::updateValue
void updateValue()
arcs::aubo_scope::DoubleRangeValidator::is_max_inclusive_
bool is_max_inclusive_
Definition: input_validator.h:114
arcs::aubo_scope::DoubleRangeValidator::is_min_inclusive_
bool is_min_inclusive_
Definition: input_validator.h:113
arcs::aubo_scope::DoubleRangeValidator::isValid
bool isValid(std::string value) override
arcs::aubo_scope::DoubleRangeValidator::DoubleRangeValidator
DoubleRangeValidator(std::function< std::tuple< double, double, bool, bool >()> range_func)
arcs::aubo_scope::InputValidator
Definition: input_validator.h:31
arcs::aubo_scope::InputValidator::isValid
virtual bool isValid(std::string value)=0
arcs::aubo_scope::InputValidator::getMessage
virtual std::string getMessage(std::string value)=0
Returns a meaningful message in case the value is not valid.
arcs::aubo_scope::IntegerRangeValidator
Definition: input_validator.h:49
arcs::aubo_scope::IntegerRangeValidator::getMessage
std::string getMessage(std::string value) override
Returns a meaningful message in case the value is not valid.
arcs::aubo_scope::IntegerRangeValidator::IntegerRangeValidator
IntegerRangeValidator(int min_value, int max_value)
arcs::aubo_scope::IntegerRangeValidator::min_value_
int min_value_
Definition: input_validator.h:62
arcs::aubo_scope::IntegerRangeValidator::max_value_
int max_value_
Definition: input_validator.h:63
arcs::aubo_scope::IntegerRangeValidator::IntegerRangeValidator
IntegerRangeValidator(std::function< std::pair< int, int >()> range_func)
arcs::aubo_scope::IntegerRangeValidator::updateValue
void updateValue()
arcs::aubo_scope::IntegerRangeValidator::isValid
bool isValid(std::string value) override
arcs::aubo_scope::IntegerRangeValidator::range_func_
std::function< std::pair< int, int >)> range_func_
Definition: input_validator.h:65
arcs::aubo_scope::StringLengthValidator
Definition: input_validator.h:118
arcs::aubo_scope::StringLengthValidator::StringLengthValidator
StringLengthValidator(size_t min_length, size_t max_length)
arcs::aubo_scope::StringLengthValidator::min_length_
size_t min_length_
Definition: input_validator.h:132
arcs::aubo_scope::StringLengthValidator::max_length_
size_t max_length_
Definition: input_validator.h:133
arcs::aubo_scope::StringLengthValidator::isValid
bool isValid(std::string value) override
arcs::aubo_scope::StringLengthValidator::updateValue
void updateValue()
arcs::aubo_scope::StringLengthValidator::getMessage
std::string getMessage(std::string value) override
Returns a meaningful message in case the value is not valid.
arcs::aubo_scope::StringLengthValidator::StringLengthValidator
StringLengthValidator(std::function< std::pair< size_t, size_t >()> range_func)
arcs::aubo_scope::StringLengthValidator::range_func_
std::function< std::pair< size_t, size_t >)> range_func_
Definition: input_validator.h:134
arcs::aubo_scope::UIntegerRangeValidator
Definition: input_validator.h:69
arcs::aubo_scope::UIntegerRangeValidator::max_value_
uint32_t max_value_
Definition: input_validator.h:84
arcs::aubo_scope::UIntegerRangeValidator::getMessage
std::string getMessage(std::string value) override
Returns a meaningful message in case the value is not valid.
arcs::aubo_scope::UIntegerRangeValidator::UIntegerRangeValidator
UIntegerRangeValidator(uint32_t min_value, uint32_t max_value)
arcs::aubo_scope::UIntegerRangeValidator::UIntegerRangeValidator
UIntegerRangeValidator(std::function< std::pair< uint32_t, uint32_t >()> range_func)
arcs::aubo_scope::UIntegerRangeValidator::range_func_
std::function< std::pair< uint32_t, uint32_t >)> range_func_
Definition: input_validator.h:86
arcs::aubo_scope::UIntegerRangeValidator::isValid
bool isValid(std::string value) override
arcs::aubo_scope::UIntegerRangeValidator::updateValue
void updateValue()
arcs::aubo_scope::UIntegerRangeValidator::min_value_
uint32_t min_value_
Definition: input_validator.h:83