MySQL 8.0.40
Source Code Documentation
abstract_options_provider.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 ABSTRACT_OPTIONS_PROVIDER_INCLUDED
27#define ABSTRACT_OPTIONS_PROVIDER_INCLUDED
28
29#include <map>
30#include <optional>
31#include <string>
32
44#include "my_inttypes.h"
45
46namespace Mysql {
47namespace Tools {
48namespace Base {
49namespace Options {
50
51/**
52 Common abstract class for options providers.
53 Provides common functionalities.
54 */
56 public:
57 /**
58 Creates and attach new simple option.
59 @param name Name of option. It is used in command-line option name as
60 --name.
61 @param description Description of option to be printed in --help.
62 */
63 Simple_option *create_new_option(std::string name, std::string description);
64 /**
65 Creates and attach new disabled option. This option is to mark existence
66 of options inavailable due to distribution configuration.
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 */
72 std::string description);
73 /**
74 Creates and attach new string option stored in char* type object.
75 @param value Pointer to char* object to receive option value.
76 @param name Name of option. It is used in command line option name as
77 --name.
78 @param description Description of option to be printed in --help.
79 */
80 Char_array_option *create_new_option(char **value, std::string name,
81 std::string description);
82 /**
83 Creates and attach new password option. It removes password from
84 command-line on UNIX systems to prevent password to be seen when listing
85 processes.
86 @param value Pointer to std::optional<string> object to receive option
87 value.
88 @param name Name of option. It is used in command line option name as
89 --name.
90 @param description Description of option to be printed in --help.
91 */
92 Password_option *create_new_password_option(std::optional<std::string> *value,
93 std::string name,
94 std::string description);
95 /**
96 Creates and attach new string option.
97 @param value Pointer to std::optional<string> object to receive option
98 value.
99 @param name Name of option. It is used in command line option name as
100 --name.
101 @param description Description of option to be printed in --help.
102 */
103 String_option *create_new_option(std::optional<std::string> *value,
104 std::string name, std::string description);
105 /**
106 Creates and attach new 32-bit signed number option.
107 @param value Pointer to int32 object to receive option value.
108 @param name Name of option. It is used in command line option name as
109 --name.
110 @param description Description of option to be printed in --help.
111 */
113 std::string description);
114 /**
115 Creates and attach new 32-bit unsigned number option.
116 @param value Pointer to uint32 object to receive option value.
117 @param name Name of option. It is used in command line option name as
118 --name.
119 @param description Description of option to be printed in --help.
120 */
122 std::string description);
123 /**
124 Creates and attach new 64-bit signed number option.
125 @param value Pointer to int64 object to receive option value.
126 @param name Name of option. It is used in command line option name as
127 --name.
128 @param description Description of option to be printed in --help.
129 */
131 std::string description);
132 /**
133 Creates and attach new 64-bit unsigned number option.
134 @param value Pointer to uint64 object to receive option value.
135 @param name Name of option. It is used in command line option name as
136 --name.
137 @param description Description of option to be printed in --help.
138 */
140 std::string description);
141 /**
142 Creates and attach new floating-point number option.
143 @param value Pointer to double object to receive option value.
144 @param name Name of option. It is used in command line option name as
145 --name.
146 @param description Description of option to be printed in --help.
147 */
148 Number_option<double> *create_new_option(double *value, std::string name,
149 std::string description);
150 /**
151 Creates and attach new boolean option with value received from argument.
152 @param value Pointer to double object to receive option value.
153 @param name Name of option. It is used in command line option name as
154 --name.
155 @param description Description of option to be printed in --help.
156 */
157 Bool_option *create_new_option(bool *value, std::string name,
158 std::string description);
159
160 template <typename T_type, typename T_typelib>
162 T_type *value, const T_typelib *type, std::string name,
163 std::string description) {
164 return this->attach_new_option<Enum_option<T_type, T_typelib>>(
165 new Enum_option<T_type, T_typelib>(value, type, name, description));
166 }
167
168 /**
169 Creates all options that will be provided.
170 */
171 virtual void create_options() = 0;
172
173 /**
174 Creates list of options provided by this provider.
175 Part of I_options_provider interface implementation.
176 @returns list of my_getopt internal option data structures.
177 */
178 std::vector<my_option> generate_options() override;
179 /**
180 Callback to be called when command-line options parsing have finished.
181 Part of I_options_provider interface implementation.
182 */
183 void options_parsed() override;
184
185 protected:
188
189 /**
190 Sets optional option changes listener to which all changes in all options
191 contained in this provider should be reported. This is used when this
192 provider is attached to another.
193 Part of I_options_provider interface implementation.
194 */
196 I_option_changed_listener *listener) override;
197
198 private:
199 /**
200 Makes sure this provider will be able to watch name and optid usage.
201 */
202 template <typename T_type>
203 T_type *attach_new_option(T_type *option) {
204 // Make this option reporting all name and optid changes to us.
205 option->set_option_changed_listener(this);
206
207 // Add to list of our own options.
208 this->m_options_created.push_back(option);
209
210 // Check for name and optid collision.
211 this->notify_option_name_changed(option, "");
212 this->notify_option_optid_changed(option, 0);
213
214 return option;
215 }
216
217 /**
218 Called after specified option has name changed.
219 It is also called when new option is added, old_name is empty string in
220 that case.
221 Part of I_option_changed_listener interface implementation.
222 */
224 std::string old_name) override;
225 /**
226 Called after specified option has option ID changed.
227 It is also called when new option is added, old_optid is 0 in that case.
228 Part of I_option_changed_listener interface implementation.
229 */
230 void notify_option_optid_changed(I_option *source, uint32 old_optid) override;
231
233 std::map<std::string, I_option *> m_name_usage;
234 std::map<uint32, I_option *> m_optid_usage;
236 std::vector<I_option *> m_options_created;
237};
238
239} // namespace Options
240} // namespace Base
241} // namespace Tools
242} // namespace Mysql
243
244#endif
Common abstract class for options providers.
Definition: abstract_options_provider.h:55
Abstract_options_provider()
Definition: abstract_options_provider.cc:127
Enum_option< T_type, T_typelib > * create_new_enum_option(T_type *value, const T_typelib *type, std::string name, std::string description)
Definition: abstract_options_provider.h:161
std::vector< I_option * > m_options_created
Definition: abstract_options_provider.h:236
I_option_changed_listener * m_option_changed_listener
Definition: abstract_options_provider.h:235
~Abstract_options_provider() override
Definition: abstract_options_provider.cc:130
void set_option_changed_listener(I_option_changed_listener *listener) override
Sets optional option changes listener to which all changes in all options contained in this provider ...
Definition: abstract_options_provider.cc:137
T_type * attach_new_option(T_type *option)
Makes sure this provider will be able to watch name and optid usage.
Definition: abstract_options_provider.h:203
void notify_option_optid_changed(I_option *source, uint32 old_optid) override
Called after specified option has option ID changed.
Definition: abstract_options_provider.cc:175
void notify_option_name_changed(I_option *source, std::string old_name) override
Called after specified option has name changed.
Definition: abstract_options_provider.cc:143
void options_parsed() override
Callback to be called when command-line options parsing have finished.
Definition: abstract_options_provider.cc:125
virtual void create_options()=0
Creates all options that will be provided.
Simple_option * create_new_option(std::string name, std::string description)
Creates and attach new simple option.
Definition: abstract_options_provider.cc:43
std::map< std::string, I_option * > m_name_usage
Definition: abstract_options_provider.h:233
Password_option * create_new_password_option(std::optional< std::string > *value, std::string name, std::string description)
Creates and attach new password option.
Definition: abstract_options_provider.cc:61
std::vector< my_option > generate_options() override
Creates list of options provided by this provider.
Definition: abstract_options_provider.cc:110
Disabled_option * create_new_disabled_option(std::string name, std::string description)
Creates and attach new disabled option.
Definition: abstract_options_provider.cc:49
std::map< uint32, I_option * > m_optid_usage
Definition: abstract_options_provider.h:234
bool m_are_options_created
Definition: abstract_options_provider.h:232
Boolean option with value specified as argument.
Definition: bool_option.h:42
Option class to get string parameter value and set to char* type object.
Definition: char_array_option.h:39
Disabled option.
Definition: disabled_option.h:41
Enum value option.
Definition: enum_option.h:42
Interface for listeners on some of option changes.
Definition: i_option_changed_listener.h:41
Common interface for all program option objects.
Definition: i_option.h:45
Interface for basic options providers functionality.
Definition: i_options_provider.h:42
Double precision floating-point number option.
Definition: number_option.h:138
32-bit signed number option.
Definition: number_option.h:62
64-bit signed number option.
Definition: number_option.h:100
32-bit unsigned number option.
Definition: number_option.h:81
64-bit unsigned number option.
Definition: number_option.h:119
String value option to handle passwords.
Definition: password_option.h:44
Simple boolean option.
Definition: simple_option.h:42
String value option.
Definition: string_option.h:43
Some integer typedefs for easier portability.
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
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42
required string type
Definition: replication_group_member_actions.proto:34
case opt name
Definition: sslopt-case.h:33