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