MySQL 8.1.0
Source Code Documentation
number_option.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2014, 2023, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef NUMBER_OPTION_INCLUDED
26#define NUMBER_OPTION_INCLUDED
27
28#include <string>
29
31
33
34namespace Mysql {
35namespace Tools {
36namespace Base {
37namespace Options {
38
39/**
40 Template class for all number options.
41 */
42template <typename T_value>
44 : public Abstract_integer_number_option<Number_option<T_value>, T_value> {
45 private:
46 /**
47 This class cannot be instanced. It is only as template for specialized
48 implementations.
49 */
51};
52
53template <typename T_value>
55
56/**
57 32-bit signed number option.
58 */
59template <>
61 : public Abstract_integer_number_option<Number_option<int32>, int32> {
62 public:
63 /**
64 Constructs new 32-bit signed number option.
65 @param value Pointer to int32 object to receive option value.
66 @param name Name of option. It is used in command line option name as
67 --name.
68 @param description Description of option to be printed in --help.
69 */
70 Number_option(int32 *value, std::string name, std::string description)
72 value, GET_INT32, name, description) {}
73};
74
75/**
76 32-bit unsigned number option.
77 */
78template <>
80 : public Abstract_integer_number_option<Number_option<uint32>, uint32> {
81 public:
82 /**
83 Constructs new 32-bit unsigned number option.
84 @param value Pointer to uint32 object to receive option value.
85 @param name Name of option. It is used in command line option name as
86 --name.
87 @param description Description of option to be printed in --help.
88 */
89 Number_option(uint32 *value, std::string name, std::string description)
91 value, GET_UINT32, name, description) {}
92};
93
94/**
95 64-bit signed number option.
96 */
97template <>
99 : public Abstract_integer_number_option<Number_option<int64>, int64> {
100 public:
101 /**
102 Constructs new 64-bit signed number option.
103 @param value Pointer to int64 object to receive option value.
104 @param name Name of option. It is used in command line option name as
105 --name.
106 @param description Description of option to be printed in --help.
107 */
108 Number_option(int64 *value, std::string name, std::string description)
110 value, GET_LL, name, description) {}
111};
112
113/**
114 64-bit unsigned number option.
115 */
116template <>
118 : public Abstract_integer_number_option<Number_option<uint64>, uint64> {
119 public:
120 /**
121 Constructs new 64-bit unsigned number option.
122 @param value Pointer to uint64 object to receive option value.
123 @param name Name of option. It is used in command line option name as
124 --name.
125 @param description Description of option to be printed in --help.
126 */
127 Number_option(uint64 *value, std::string name, std::string description)
129 value, GET_ULL, name, description) {}
130};
131
132/**
133 Double precision floating-point number option.
134 */
135template <>
136class Number_option<double>
137 : public Abstract_number_option<Number_option<double>, double> {
138 public:
139 /**
140 Constructs new floating-point number option.
141 @param value Pointer to double object to receive option value.
142 @param name Name of option. It is used in command line option name as
143 --name.
144 @param description Description of option to be printed in --help.
145 */
146 Number_option(double *value, std::string name, std::string description)
147 : Abstract_number_option<Number_option<double>, double>(
148 value, GET_DOUBLE, name, description,
149 getopt_double2ulonglong((double)*value)) {}
150
151 /**
152 Sets minimum value boundary for option value. Smaller values passed as
153 option value will be changed to this minimum value.
154 */
155 Number_option<double> *set_minimum_value(double minimum) override {
157 return this;
158 }
159
160 /**
161 Sets maximum value boundary for option value. Greater values passed as
162 option value will be changed to this maximum value.
163 */
164 Number_option<double> *set_maximum_value(double maximum) override {
166 return this;
167 }
168};
169
170} // namespace Options
171} // namespace Base
172} // namespace Tools
173} // namespace Mysql
174
175#endif
Abstract option to handle integer number option values.
Definition: abstract_integer_number_option.h:42
Abstract option to handle numeric option values.
Definition: abstract_number_option.h:41
my_option m_option_structure
Definition: abstract_option.h:95
Double precision floating-point number option.
Definition: number_option.h:137
Number_option< double > * set_minimum_value(double minimum) override
Sets minimum value boundary for option value.
Definition: number_option.h:155
Number_option(double *value, std::string name, std::string description)
Constructs new floating-point number option.
Definition: number_option.h:146
Number_option< double > * set_maximum_value(double maximum) override
Sets maximum value boundary for option value.
Definition: number_option.h:164
Number_option(int32 *value, std::string name, std::string description)
Constructs new 32-bit signed number option.
Definition: number_option.h:70
Number_option(int64 *value, std::string name, std::string description)
Constructs new 64-bit signed number option.
Definition: number_option.h:108
Number_option(uint32 *value, std::string name, std::string description)
Constructs new 32-bit unsigned number option.
Definition: number_option.h:89
Number_option(uint64 *value, std::string name, std::string description)
Constructs new 64-bit unsigned number option.
Definition: number_option.h:127
Template class for all number options.
Definition: number_option.h:44
Number_option()
This class cannot be instanced.
#define GET_LL
Definition: my_getopt.h:49
#define GET_UINT32
Definition: my_getopt.h:62
#define GET_INT32
Definition: my_getopt.h:61
#define GET_DOUBLE
Definition: my_getopt.h:56
#define GET_ULL
Definition: my_getopt.h:50
unsigned long long int ulonglong
Definition: my_inttypes.h:55
int64_t int64
Definition: my_inttypes.h:67
int32_t int32
Definition: my_inttypes.h:65
uint64_t uint64
Definition: my_inttypes.h:68
uint32_t uint32
Definition: my_inttypes.h:66
constexpr pos_type Options
Definition: http_request.h:260
Definition: abstract_connection_program.h:39
ulonglong getopt_double2ulonglong(double v)
Returns an ulonglong value containing a raw representation of the given double value.
Definition: my_getopt.cc:159
case opt name
Definition: sslopt-case.h:32
longlong min_value
Min allowed value (for numbers)
Definition: my_getopt.h:122
ulonglong max_value
Max allowed value (for numbers)
Definition: my_getopt.h:123