MySQL 8.0.40
Source Code Documentation
abstract_program.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_PROGRAM_INCLUDED
27#define ABSTRACT_PROGRAM_INCLUDED
28
29#include <string>
30
36#include "my_alloc.h"
37#include "my_compiler.h"
38#include "my_inttypes.h"
39
40namespace Mysql {
41namespace Tools {
42namespace Base {
43
44/**
45 Base class for all MySQL client tools.
46 */
48 public:
50
51 /**
52 Returns null-terminated string with name of current program.
53 */
54 const std::string get_name();
55
56 /**
57 Returns pointer to array of options for usage in handle_options.
58 Array has empty sentinel at the end, as handle_options expects.
59 */
61
62 /**
63 Does all initialization and exit work, calls execute().
64 */
65 void run(int argc, char **argv);
66
67 /**
68 Returns string describing current version of this program.
69 */
70 virtual std::string get_version() = 0;
71
72 /**
73 Returns year of first release of this program.
74 */
75 virtual int get_first_release_year() = 0;
76
77 /**
78 Returns string describing shortly current program
79 */
80 virtual std::string get_description() = 0;
81
82 /**
83 Handles general errors.
84 */
85 virtual void error(const Message_data &message) = 0;
86
87 /**
88 Runs main program code.
89 */
90 virtual int execute(const std::vector<std::string> &positional_options) = 0;
91
92 /**
93 Prints program invocation message.
94 */
95 virtual void short_usage() = 0;
96 /**
97 Return error code
98 */
99 virtual int get_error_code() = 0;
100
101 protected:
103
104 private:
105 /**
106 Initializes program name.
107 */
108 void init_name(char *name_from_cmd_line);
109 /**
110 Gathers all options from option providers and save in array to be used in
111 my_getopt functionality.
112 */
113 void aggregate_options();
114
115 /**
116 Compares option structures by long name. Keeps --help first.
117 */
118 static bool options_by_name_comparer(const my_option &a, const my_option &b);
119
120 /*
121 Redirects call to option_parsed of main Abstract_program instance.
122 If we have anonymous functions or binding this should be removed.
123 */
124 static bool callback_option_parsed(int optid,
125 const struct my_option *opt
126 [[maybe_unused]],
127 char *argument);
128
131 std::vector<my_option> m_options;
133 std::string m_name;
134
136};
137
138} // namespace Base
139} // namespace Tools
140} // namespace Mysql
141
142#endif
Base class for all programs that use connection to MySQL database server.
Definition: abstract_connection_program.h:46
Base class for all MySQL client tools.
Definition: abstract_program.h:47
virtual void short_usage()=0
Prints program invocation message.
virtual int execute(const std::vector< std::string > &positional_options)=0
Runs main program code.
Abstract_program()
Definition: abstract_program.cc:55
virtual void error(const Message_data &message)=0
Handles general errors.
my_option * get_options_array()
Returns pointer to array of options for usage in handle_options.
Definition: abstract_program.cc:53
virtual int get_first_release_year()=0
Returns year of first release of this program.
MEM_ROOT m_argv_alloc
Definition: abstract_program.h:132
std::string m_name
Definition: abstract_program.h:133
virtual std::string get_description()=0
Returns string describing shortly current program.
const std::string get_name()
Returns null-terminated string with name of current program.
Definition: abstract_program.cc:51
virtual std::string get_version()=0
Returns string describing current version of this program.
void aggregate_options()
Gathers all options from option providers and save in array to be used in my_getopt functionality.
Definition: abstract_program.cc:120
Options::Debug_options m_debug_options
Definition: abstract_program.h:129
void run(int argc, char **argv)
Does all initialization and exit work, calls execute().
Definition: abstract_program.cc:60
static bool options_by_name_comparer(const my_option &a, const my_option &b)
Compares option structures by long name.
Definition: abstract_program.cc:137
std::vector< my_option > m_options
Definition: abstract_program.h:131
virtual int get_error_code()=0
Return error code.
static bool callback_option_parsed(int optid, const struct my_option *opt, char *argument)
Definition: abstract_program.cc:40
void init_name(char *name_from_cmd_line)
Initializes program name.
Definition: abstract_program.cc:96
Options::Help_options m_help_options
Definition: abstract_program.h:130
Structure to represent message from server sent after executing query.
Definition: message_data.h:49
Provider that aggregates options from other providers.
Definition: composite_options_provider.h:41
Options provider providing debugging options.
Definition: debug_options.h:45
Options provider providing –help option and handling usage printing.
Definition: help_options.h:43
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
Header for compiler-dependent features.
Some integer typedefs for easier portability.
Definition: abstract_connection_program.h:38
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: my_getopt.h:93
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:42