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