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