MySQL  8.0.19
Source Code Documentation
designator.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
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  */
44 class 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 
93  long ver_major;
94  long ver_minor;
95  long ver_patch;
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 
107 class 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 */
Designator::NOT_EQUAL
@ NOT_EQUAL
Definition: designator.h:115
Designator::cur_
std::string::const_iterator cur_
Definition: designator.h:152
Version::operator<=
friend bool operator<=(const Version &lhs, const Version &rhs)
Definition: designator.h:66
Designator::Constraint
Definition: designator.h:121
Designator::constraint
Constraint constraint
Definition: designator.h:134
Version::ver_patch
long ver_patch
Definition: designator.h:95
Version::operator>=
friend bool operator>=(const Version &lhs, const Version &rhs)
Definition: designator.h:74
Version::operator==
friend bool operator==(const Version &lhs, const Version &rhs)
Definition: designator.h:57
Version::operator<<
friend std::ostream & operator<<(std::ostream &out, const Version &ver)
Definition: designator.h:46
Version
Class representing a version.
Definition: designator.h:44
Version::ver_minor
long ver_minor
Definition: designator.h:94
Designator::LESS_THEN
@ LESS_THEN
Definition: designator.h:112
Designator::LESS_EQUAL
@ LESS_EQUAL
Definition: designator.h:113
Version::operator<
friend bool operator<(const Version &lhs, const Version &rhs)
Definition: designator.h:51
Version::Version
Version(unsigned long ver)
Definition: designator.h:82
Version::Version
Version()
Definition: designator.h:80
Vt100::value_type
uint16_t value_type
Definition: vt100.h:182
Designator
Designator grammar.
Definition: designator.h:107
Version::Version
Version(int x, int y, int z=0)
Definition: designator.h:78
Designator::Constraint::operator<<
friend std::ostream & operator<<(std::ostream &out, const Constraint &con)
Definition: designator.h:122
name
const string name("\"Name\"")
ut::ostringstream
std::basic_ostringstream< char, std::char_traits< char >, ut_allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut_allocator.
Definition: ut0new.h:1275
ut::vector
std::vector< T, ut_allocator< T > > vector
Specialization of vector which uses ut_allocator.
Definition: ut0new.h:1279
Version::operator!=
friend bool operator!=(const Version &lhs, const Version &rhs)
Definition: designator.h:62
Designator::input_
const std::string & input_
Definition: designator.h:151
Designator::Relation
Relation
Definition: designator.h:111
Version::str
std::string str() const
Definition: designator.h:87
Designator::EQUAL
@ EQUAL
Definition: designator.h:114
where
static char * where
Definition: mysqldump.cc:132
Designator::plugin
std::string plugin
Definition: designator.h:133
buffer
char buffer[STRING_BUFFER]
Definition: test_sql_9_sessions.cc:57
Version::operator>
friend bool operator>(const Version &lhs, const Version &rhs)
Definition: designator.h:70
Version::ver_major
long ver_major
Definition: designator.h:93
Designator::GREATER_EQUAL
@ GREATER_EQUAL
Definition: designator.h:116