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