PDF
AuboStudio SDK  0.6.3
input_validator.h
Go to the documentation of this file.
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
11
12namespace arcs {
13namespace aubo_scope {
14
15/**
16 * \chinese
17 * 输入验证器
18 * 表示由 {@link InputValidationFactory} 创建的输入验证器接口。该工厂提供一组标准
19 * 输入验证器,可用于验证用户使用虚拟键盘/小键盘输入的内容。
20 *
21 * 如果 {@link InputValidationFactory} 中可用的标准验证器不能满足您的需求,您可以
22 * 自由实现自己的自定义验证器。
23 *
24 * @param <T> 表示正在验证的输入数据类型的接口(通用)类型参数(例如 Integer 或 Double)。
25 * \endchinese
26 * \english
27 * InputValidator
28 * Interface representing the input validators created by {@link
29 * InputValidationFactory}. This factory provides a set of standard input
30 * validators that can be used for validating the input entered by the user
31 * using the virtual keyboard/keypad.
32 *
33 * If the standard validators available in the {@link InputValidationFactory}
34 * does not satisfy your needs, you are free to implement your own custom
35 * validator.
36 *
37 * @param <T> the (generic) type parameter for the interface representing the
38 * type of input data being validated (e.g. Integer or Double).
39 * \endenglish
40 */
42{
43 /**
44 * \chinese
45 * 验证输入值是否有效。
46 *
47 * @param value 需要验证的值
48 * @return 如果值有效则返回 <code>true</code>
49 * \endchinese
50 * \english
51 * Validates whether the input value is valid.
52 *
53 * @param value to be validated.
54 * @return <code>true</code> if value is valid.
55 * \endenglish
56 */
57 virtual bool isValid(std::string value) = 0;
58
59 /**
60 * \chinese
61 * 当值无效时返回有意义的提示信息。
62 *
63 * @param value 无效的值,如果合理可包含在消息中
64 * @return 提示消息
65 * \endchinese
66 * \english
67 * Returns a meaningful message in case the value is not valid.
68 *
69 * @param value the invalid value. Can be included in the message if it
70 * makes sense.
71 * @return message.
72 * \endenglish
73 */
74 virtual std::string getMessage(std::string value) = 0;
75
76 /**
77 * Returns the persistent tip displayed by the virtual keyboard.
78 *
79 * @return persistent tip message.
80 */
81 virtual std::string getMsgTip() = 0;
82};
83
85{
86 IntegerRangeValidator(int min_value, int max_value);
87
88 IntegerRangeValidator(std::function<std::pair<int, int>()> range_func);
89
90 bool isValid(std::string value) override;
91
92 std::string getMessage(std::string value) override;
93
94 std::string getMsgTip() override;
95
96private:
98
99private:
100 int min_value_{ INT_MIN };
101 int max_value_{ INT_MAX };
102
103 std::function<std::pair<int, int>()> range_func_{ nullptr };
104};
105
107{
108 UIntegerRangeValidator(uint32_t min_value, uint32_t max_value);
109
111 std::function<std::pair<uint32_t, uint32_t>()> range_func);
112
113 bool isValid(std::string value) override;
114
115 std::string getMessage(std::string value) override;
116
117 std::string getMsgTip() override;
118
119private:
121
122private:
123 uint32_t min_value_{ 0 };
124 uint32_t max_value_{ UINT_MAX };
125
126 std::function<std::pair<uint32_t, uint32_t>()> range_func_{ nullptr };
127};
128
130{
131 DoubleRangeValidator(double minValue, double maxValue,
132 bool is_min_inclusive = true,
133 bool is_max_inclusive = true);
134
135 DoubleRangeValidator(std::function<std::pair<double, double>()> range_func);
136
138 std::function<std::tuple<double, double, bool, bool>()> range_func);
139
140 bool isValid(std::string value) override;
141
142 std::string getMessage(std::string value) override;
143
144 std::string getMsgTip() override;
145
146private:
148
149private:
150 double min_value_{ DBL_MIN };
151 double max_value_{ DBL_MAX };
152 std::function<std::pair<double, double>()> range_func_{ nullptr };
153 std::function<std::tuple<double, double, bool, bool>()>
155 bool is_min_inclusive_{ true }; // 最小值是否闭区间
156 bool is_max_inclusive_{ true }; // 最大值是否闭区间
157};
158
160{
161 StringLengthValidator(size_t min_length, size_t max_length);
162
164 std::function<std::pair<size_t, size_t>()> range_func);
165
166 bool isValid(std::string value) override;
167
168 std::string getMessage(std::string value) override;
169
170 std::string getMsgTip() override;
171
172private:
174
175private:
176 size_t min_length_{ 0 };
177 size_t max_length_{ ULONG_MAX };
178 std::function<std::pair<size_t, size_t>()> range_func_{ nullptr };
179};
180
181} // namespace aubo_scope
182} // namespace arcs
183
184#endif
std::function< std::tuple< double, double, bool, bool >()> range_func_with_flags_
std::string getMessage(std::string value) override
Returns a meaningful message in case the value is not valid.
std::function< std::pair< double, double >()> range_func_
DoubleRangeValidator(double minValue, double maxValue, bool is_min_inclusive=true, bool is_max_inclusive=true)
DoubleRangeValidator(std::function< std::pair< double, double >()> range_func)
std::string getMsgTip() override
Returns the persistent tip displayed by the virtual keyboard.
bool isValid(std::string value) override
Validates whether the input value is valid.
DoubleRangeValidator(std::function< std::tuple< double, double, bool, bool >()> range_func)
InputValidator Interface representing the input validators created by InputValidationFactory.
virtual bool isValid(std::string value)=0
Validates whether the input value is valid.
virtual std::string getMsgTip()=0
Returns the persistent tip displayed by the virtual keyboard.
virtual std::string getMessage(std::string value)=0
Returns a meaningful message in case the value is not valid.
std::string getMessage(std::string value) override
Returns a meaningful message in case the value is not valid.
IntegerRangeValidator(int min_value, int max_value)
IntegerRangeValidator(std::function< std::pair< int, int >()> range_func)
std::string getMsgTip() override
Returns the persistent tip displayed by the virtual keyboard.
bool isValid(std::string value) override
Validates whether the input value is valid.
std::function< std::pair< int, int >()> range_func_
std::function< std::pair< size_t, size_t >()> range_func_
StringLengthValidator(size_t min_length, size_t max_length)
bool isValid(std::string value) override
Validates whether the input value is valid.
std::string getMessage(std::string value) override
Returns a meaningful message in case the value is not valid.
std::string getMsgTip() override
Returns the persistent tip displayed by the virtual keyboard.
StringLengthValidator(std::function< std::pair< size_t, size_t >()> range_func)
std::string getMsgTip() override
Returns the persistent tip displayed by the virtual keyboard.
std::string getMessage(std::string value) override
Returns a meaningful message in case the value is not valid.
UIntegerRangeValidator(uint32_t min_value, uint32_t max_value)
UIntegerRangeValidator(std::function< std::pair< uint32_t, uint32_t >()> range_func)
std::function< std::pair< uint32_t, uint32_t >()> range_func_
bool isValid(std::string value) override
Validates whether the input value is valid.