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
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
78{
79 IntegerRangeValidator(int min_value, int max_value);
80
81 IntegerRangeValidator(std::function<std::pair<int, int>()> range_func);
82
83 bool isValid(std::string value) override;
84
85 std::string getMessage(std::string value) override;
86
87private:
89
90private:
91 int min_value_{ INT_MIN };
92 int max_value_{ INT_MAX };
93
94 std::function<std::pair<int, int>()> range_func_{ nullptr };
95};
96
98{
99 UIntegerRangeValidator(uint32_t min_value, uint32_t max_value);
100
102 std::function<std::pair<uint32_t, uint32_t>()> range_func);
103
104 bool isValid(std::string value) override;
105
106 std::string getMessage(std::string value) override;
107
108private:
110
111private:
112 uint32_t min_value_{ 0 };
113 uint32_t max_value_{ UINT_MAX };
114
115 std::function<std::pair<uint32_t, uint32_t>()> range_func_{ nullptr };
116};
117
119{
120 DoubleRangeValidator(double minValue, double maxValue,
121 bool is_min_inclusive = true,
122 bool is_max_inclusive = true);
123
124 DoubleRangeValidator(std::function<std::pair<double, double>()> range_func);
125
127 std::function<std::tuple<double, double, bool, bool>()> range_func);
128
129 bool isValid(std::string value) override;
130
131 std::string getMessage(std::string value) override;
132
133private:
135
136private:
137 double min_value_{ DBL_MIN };
138 double max_value_{ DBL_MAX };
139 std::function<std::pair<double, double>()> range_func_{ nullptr };
140 std::function<std::tuple<double, double, bool, bool>()>
142 bool is_min_inclusive_{ true }; // 最小值是否闭区间
143 bool is_max_inclusive_{ true }; // 最大值是否闭区间
144};
145
147{
148 StringLengthValidator(size_t min_length, size_t max_length);
149
151 std::function<std::pair<size_t, size_t>()> range_func);
152
153 bool isValid(std::string value) override;
154
155 std::string getMessage(std::string value) override;
156
157private:
159
160private:
161 size_t min_length_{ 0 };
162 size_t max_length_{ ULONG_MAX };
163 std::function<std::pair<size_t, size_t>()> range_func_{ nullptr };
164};
165
166} // namespace aubo_scope
167} // namespace arcs
168
169#endif
std::function< std::tuple< double, double, bool, bool >()> range_func_with_flags_
std::string getMessage(std::string value) override
\chinese 当值无效时返回有意义的提示信息。
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)
bool isValid(std::string value) override
\chinese 验证输入值是否有效。
DoubleRangeValidator(std::function< std::tuple< double, double, bool, bool >()> range_func)
\chinese 输入验证器 表示由 InputValidationFactory 创建的输入验证器接口。该工厂提供一组标准 输入验证器,可用于验证用户使用虚拟键盘/小键盘输入的内容。
virtual bool isValid(std::string value)=0
\chinese 验证输入值是否有效。
virtual std::string getMessage(std::string value)=0
\chinese 当值无效时返回有意义的提示信息。
std::string getMessage(std::string value) override
\chinese 当值无效时返回有意义的提示信息。
IntegerRangeValidator(int min_value, int max_value)
IntegerRangeValidator(std::function< std::pair< int, int >()> range_func)
bool isValid(std::string value) override
\chinese 验证输入值是否有效。
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
\chinese 验证输入值是否有效。
std::string getMessage(std::string value) override
\chinese 当值无效时返回有意义的提示信息。
StringLengthValidator(std::function< std::pair< size_t, size_t >()> range_func)
std::string getMessage(std::string value) override
\chinese 当值无效时返回有意义的提示信息。
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
\chinese 验证输入值是否有效。