MySQL 9.6.0
Source Code Documentation
checker.h
Go to the documentation of this file.
1// Copyright (c) 2025, Oracle and/or its affiliates.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License, version 2.0,
5// as published by the Free Software Foundation.
6//
7// This program is designed to work with certain software (including
8// but not limited to OpenSSL) that is licensed under separate terms,
9// as designated in a particular file or component or in included license
10// documentation. The authors of MySQL hereby grant you an additional
11// permission to link the program and your derivative works with the
12// separately licensed software that they have either included with
13// the program or referenced in the documentation.
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#ifndef MYSQL_STRCONV_DECODE_CHECKER_H
25#define MYSQL_STRCONV_DECODE_CHECKER_H
26
27/// @file
28/// Experimental API header
29
30#include <concepts> // invocable
31#include "mysql/meta/is_specialization.h" // Is_specialization
32
33/// @addtogroup GroupLibsMysqlStrconv
34/// @{
35
36namespace mysql::strconv {
37
38// Forward declaration
39class Parser;
40
41/// True for types that are invocable without arguments.
42///
43/// Checkers should test that a parsed object is valid, and if not, call
44/// `Parser::set_parse_error` in the Parser (which should be
45/// captured).
46template <class Test>
47concept Is_checker_function = std::invocable<Test>;
48
49/// Class holding a checker function, used to check the validity of a parsed
50/// value.
51///
52/// This type only encapsulates an std::invocable object. By using a
53/// distinguished wrapper type rather than using the invocable type directly, we
54/// avoid making the definition of `operator|` for parse options (see
55/// parse_options.h) apply to all invocable types.
56template <Is_checker_function Checker_function_tp>
57class Checker {
58 public:
59 using Checker_function_t = Checker_function_tp;
60
61 /// Can't default-construct a lambda.
62 Checker() = delete;
63
64 /// Construct a Checker from the given checker function.
65 explicit Checker(const Checker_function_t &checker_function)
66 : m_checker_function(checker_function) {}
67
68 /// Invoke the checker function.
69 void check() const { m_checker_function(); }
70
71 private:
72 /// The checker function.
74};
75
76/// True for all Checker specializations.
77template <class Test>
79
80} // namespace mysql::strconv
81
82// addtogroup GroupLibsMysqlStrconv
83/// @}
84
85#endif // ifndef MYSQL_STRCONV_DECODE_CHECKER_H
Class holding a checker function, used to check the validity of a parsed value.
Definition: checker.h:57
Checker()=delete
Can't default-construct a lambda.
Checker(const Checker_function_t &checker_function)
Construct a Checker from the given checker function.
Definition: checker.h:65
void check() const
Invoke the checker function.
Definition: checker.h:69
Checker_function_tp Checker_function_t
Definition: checker.h:59
Checker_function_t m_checker_function
The checker function.
Definition: checker.h:73
Concept used to determine at compile time whether a given type Test is a template specialization of t...
Definition: is_specialization.h:68
True for types that are invocable without arguments.
Definition: checker.h:47
True for all Checker specializations.
Definition: checker.h:78
Experimental API header.
Definition: gtid_binary_format.h:41
Definition: mysqltest.cc:395