MySQL 8.0.39
Source Code Documentation
designator.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2015, 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 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 MYSQL_HARNESS_DESIGNATOR_INCLUDED
27#define MYSQL_HARNESS_DESIGNATOR_INCLUDED
28
29#include <iostream>
30#include <sstream>
31#include <string>
32#include <vector>
33
34#include "harness_export.h"
35
36/**
37 * Class representing a version.
38 *
39 * Versions consist of a three-position dotted pair
40 * `MAJOR.MINOR.PATCH` where MAJOR is the major version number, MINOR
41 * is the minor version number, and PATCH is the patch number. Version
42 * comparison is done lexicographically in the normal manner so that
43 * 1.1.5 < 1.2.1 < 1.2.3.
44 */
45class Version {
46 public:
47 friend std::ostream &operator<<(std::ostream &out, const Version &ver) {
48 out << ver.str();
49 return out;
50 }
51
52 friend bool operator<(const Version &lhs, const Version &rhs) {
53 return (lhs.ver_major < rhs.ver_major) ||
54 (lhs.ver_major == rhs.ver_major && lhs.ver_minor < rhs.ver_minor) ||
55 (lhs.ver_minor == rhs.ver_minor && lhs.ver_patch < rhs.ver_patch);
56 }
57
58 friend bool operator==(const Version &lhs, const Version &rhs) {
59 return (lhs.ver_major == rhs.ver_major) &&
60 (lhs.ver_minor == rhs.ver_minor) && (lhs.ver_patch == rhs.ver_patch);
61 }
62
63 friend bool operator!=(const Version &lhs, const Version &rhs) {
64 return !(lhs == rhs);
65 }
66
67 friend bool operator<=(const Version &lhs, const Version &rhs) {
68 return (lhs < rhs) || (lhs == rhs);
69 }
70
71 friend bool operator>(const Version &lhs, const Version &rhs) {
72 return (rhs < lhs);
73 }
74
75 friend bool operator>=(const Version &lhs, const Version &rhs) {
76 return (lhs > rhs) || (lhs == rhs);
77 }
78
79 Version(int x, int y, int z = 0) : ver_major(x), ver_minor(y), ver_patch(z) {}
80
81 Version() : Version(0, 0, 0) {}
82
83 explicit Version(unsigned long ver)
84 : ver_major((ver >> 24) & 0xFF),
85 ver_minor((ver >> 16) & 0xFF),
86 ver_patch(ver & 0xFFFF) {}
87
88 std::string str() const {
90 buffer << ver_major << "." << ver_minor << "." << ver_patch;
91 return buffer.str();
92 }
93
97};
98
99/**
100 * Designator grammar
101 *
102 * root ::= name
103 * root ::= name "(" op version ( "," op version )* ")"
104 * op ::= "<<" | "<=" | "!=" | "==" | ">>" | ">="
105 * version ::= number "." number "." number
106 */
107
108class HARNESS_EXPORT Designator {
109 public:
110 explicit Designator(const std::string &str);
111
112 enum Relation {
118 GREATER_THEN
119 };
120
121 public:
122 class Constraint : public std::vector<std::pair<Relation, Version>> {
123 friend std::ostream &operator<<(std::ostream &out, const Constraint &con) {
124 static const char *const name[] = {
125 "<<", "<=", "==", "!=", ">=", ">>",
126 };
127 for (auto item : con) out << name[item.first] << item.second;
128 return out;
129 }
130 };
131
132 bool version_good(const Version &ver) const;
133
134 std::string plugin;
136
137 private:
138 void trace(const std::string &where) const;
139
140 [[noreturn]] void parse_error(const std::string &prefix) const;
141 std::string::value_type peek() const;
143
144 Relation parse_relation();
145 Version parse_version();
146 long parse_number();
147 void parse_plugin();
148 void parse_root();
149 void parse_version_list();
150 void skip_space();
151
152 const std::string &input_;
153 std::string::const_iterator cur_;
154};
155
156#endif /* MYSQL_HARNESS_DESIGNATOR_INCLUDED */
Definition: designator.h:122
friend std::ostream & operator<<(std::ostream &out, const Constraint &con)
Definition: designator.h:123
Designator grammar.
Definition: designator.h:108
void trace(const std::string &where) const
const std::string & input_
Definition: designator.h:152
std::string plugin
Definition: designator.h:134
std::string::const_iterator cur_
Definition: designator.h:153
Constraint constraint
Definition: designator.h:135
Relation
Definition: designator.h:112
@ GREATER_EQUAL
Definition: designator.h:117
@ LESS_THEN
Definition: designator.h:113
@ EQUAL
Definition: designator.h:115
@ NOT_EQUAL
Definition: designator.h:116
@ LESS_EQUAL
Definition: designator.h:114
Class representing a version.
Definition: designator.h:45
Version(int x, int y, int z=0)
Definition: designator.h:79
long ver_minor
Definition: designator.h:95
friend bool operator!=(const Version &lhs, const Version &rhs)
Definition: designator.h:63
long ver_major
Definition: designator.h:94
Version(unsigned long ver)
Definition: designator.h:83
std::string str() const
Definition: designator.h:88
long ver_patch
Definition: designator.h:96
friend bool operator>(const Version &lhs, const Version &rhs)
Definition: designator.h:71
friend bool operator>=(const Version &lhs, const Version &rhs)
Definition: designator.h:75
friend bool operator==(const Version &lhs, const Version &rhs)
Definition: designator.h:58
friend bool operator<=(const Version &lhs, const Version &rhs)
Definition: designator.h:67
Version()
Definition: designator.h:81
friend std::ostream & operator<<(std::ostream &out, const Version &ver)
Definition: designator.h:47
friend bool operator<(const Version &lhs, const Version &rhs)
Definition: designator.h:52
static char * where
Definition: mysqldump.cc:140
uint16_t value_type
Definition: vt100.h:184
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1052
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:420
std::basic_ostringstream< char, std::char_traits< char >, ut::allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut::allocator.
Definition: ut0new.h:2870
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2874
case opt name
Definition: sslopt-case.h:33