MySQL 9.6.0
Source Code Documentation
string_target.h
Go to the documentation of this file.
1// Copyright (c) 2024, 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_ENCODE_STRING_TARGET_H
25#define MYSQL_STRCONV_ENCODE_STRING_TARGET_H
26
27/// @file
28/// Experimental API header
29
30#include <concepts> // derived_from
31#include "mysql/strconv/encode/concat_object.h" // Concat_object
32#include "mysql/strconv/formats/resolve_format.h" // resolve_format
33
34/// @addtogroup GroupLibsMysqlStrconv
35/// @{
36
37namespace mysql::strconv {
38// Forward declarations
39class String_counter;
40class String_writer;
41} // namespace mysql::strconv
42
43namespace mysql::strconv::detail {
44
45/// Top of the hierarchy.
47
48/// True if `encode_impl` can be invoked with the given format type and
49/// object type.
50template <class Format_t, class Object_t>
52 requires(Format_t format, String_counter counter, String_writer writer,
53 Object_t obj) {
56 };
57
58/// CRTP base class providing common helpers needed by `String_writer` and
59/// `String_counter`, namely, the function to resolve the format.
60template <class Self_tp>
62 private:
63 using Self_t = Self_tp;
64
65 /// Helper type predicate used by detail::resolve_format. It has the static
66 /// constexpr bool member variable `value` which is true if encode_impl has
67 /// been defined for the given Format and Object.
68 ///
69 /// @tparam Format_t Format to test.
70 ///
71 /// @tparam Object_t Object type to test.
72 template <class Format_t, class Object_t>
74 : public std::bool_constant<Can_invoke_encode_impl<Format_t, Object_t>> {
75 };
76
77 public:
78 /// Depending on the subclass, write or compute the size of multiple objects
79 /// to this String_target.
80 template <class... Args_t>
81 void concat(const Is_format auto &format, const Args_t &...args) {
82 self().write(format, Concat_object<Args_t...>(args...));
83 }
84
85 protected:
86 /// Resolve the format, using the rules to deduce format based on default
87 /// format and parent format, and write the given object using the resolved
88 /// format.
89 template <class Object_t>
91 const Object_t &object) {
94 self(), object);
95 }
96
97 private:
98 [[nodiscard]] Self_t &self() { return static_cast<Self_t &>(*this); }
99}; // class String_target_interface
100
101} // namespace mysql::strconv::detail
102
103namespace mysql::strconv {
104
105// The type of string target.
106// NOLINTNEXTLINE(performance-enum-size): silence clang-tidy's pointless hint
107enum class Target_type { counter, writer };
108
109/// Concept that holds for String_counter and String_writer.
110template <class Test>
111concept Is_string_target = std::derived_from<Test, detail::String_target_base>;
112
113} // namespace mysql::strconv
114
115// addtogroup GroupLibsMysqlStrconv
116/// @}
117
118#endif // ifndef MYSQL_STRCONV_ENCODE_STRING_TARGET_H
Top of the hierarchy.
Definition: string_target.h:46
CRTP base class providing common helpers needed by String_writer and String_counter,...
Definition: string_target.h:61
void resolve_format_and_write(const Is_format auto &format, const Object_t &object)
Resolve the format, using the rules to deduce format based on default format and parent format,...
Definition: string_target.h:90
Self_tp Self_t
Definition: string_target.h:63
void concat(const Is_format auto &format, const Args_t &...args)
Depending on the subclass, write or compute the size of multiple objects to this String_target.
Definition: string_target.h:81
Experimental API header.
True if Test is a format.
Definition: format.h:42
Concept that holds for String_counter and String_writer.
Definition: string_target.h:111
True if encode_impl can be invoked with the given format type and object type.
Definition: string_target.h:51
uint counter
Definition: mysqlimport.cc:58
std::string format(const routing_guidelines::Session_info &session_info, bool extended_session_info)
Definition: dest_metadata_cache.cc:170
Definition: gtid_binary_format_conv.h:252
constexpr auto resolve_format(const Format_t &format, const Object_t &object)
Return the format to pass to the implementation function, given the format and object type passed by ...
Definition: resolve_format.h:165
Definition: gtid_binary_format.h:41
Target_type
Definition: string_target.h:107
void encode_impl(const Gtid_binary_format &format, Is_string_target auto &target, const mysql::gtids::Is_tag auto &tag)
Definition: gtid_binary_format_conv.h:48
Experimental API header.
Helper type that wraps the varargs of concat in a struct containing a tuple.
Definition: concat_object.h:40
Helper type predicate used by detail::resolve_format.
Definition: string_target.h:74