MySQL 9.6.0
Source Code Documentation
concat.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_ENCODE_CONCAT_H
25#define MYSQL_STRCONV_ENCODE_CONCAT_H
26
27/// @file
28/// Experimental API header
29
30#include "mysql/strconv/encode/concat_object.h" // Concat_object
31#include "mysql/strconv/encode/encode.h" // encode
32#include "mysql/strconv/encode/string_target.h" // String_target
33#include "mysql/strconv/formats/format.h" // Is_format
34
35/// @addtogroup GroupLibsMysqlStrconv
36/// @{
37
38namespace mysql::strconv {
39
40template <std::size_t index = 0, class... Args_t>
41void encode_impl(const Is_format auto &format, Is_string_target auto &target,
42 const Concat_object<Args_t...> &concat_object) {
43 if constexpr (index < sizeof...(Args_t)) {
44 target.write(format, std::get<index>(concat_object.m_args));
45 encode_impl<index + 1>(format, target, concat_object);
46 }
47}
48
49/// Compute the length of the concatenation of the string representations of the
50/// objects.
51///
52/// @tparam Format_t Type of format.
53///
54/// @tparam Args_t Types of objects.
55///
56/// @param format Format object.
57///
58/// @param args Objects.
59template <Is_format Format_t, class... Args_t>
60auto concat_length(const Format_t &format, const Args_t &...args) noexcept {
62}
63
64/// Concatenate the string representations of the objects into the output
65/// string wrapper.
66///
67/// @tparam Format_t Type of format.
68///
69/// @tparam Out_str_t Type of output string wrapper.
70///
71/// @tparam Args_t Types of objects.
72///
73/// @param format Format object.
74///
75/// @param out Output String Wrapper in which the result will be saved.
76///
77/// @param args Objects.
78///
79/// @return Return_status::ok on success, Return_status::error on out-of-memory.
80template <Is_format Format_t, Is_out_str Out_str_t, class... Args_t>
81auto concat(const Format_t &format, const Out_str_t &out,
82 const Args_t &...args) noexcept {
83 return encode(format, out, Concat_object<Args_t...>(args...));
84}
85
86/// Concatenate the string representations of the objects and return a
87/// std::optional<std::string> object holding the result.
88///
89/// @tparam String_t Output string type. Defaults to std::string.
90///
91/// @tparam Format_t Type of format.
92///
93/// @tparam Args_t Types of objects.
94///
95/// @param format Format object.
96///
97/// @param args Objects.
98///
99/// @return std::optional holding a String_t object on success, or no value on
100/// out-of-memory.
101template <class String_t = std::string, Is_format Format_t, class... Args_t>
102auto concat(const Format_t &format, const Args_t &...args) noexcept {
103 return encode<String_t>(format, Concat_object<Args_t...>(args...));
104}
105
106namespace throwing {
107/// Concatenate the string representations of the objects and return a
108/// std::string object holding the result.
109///
110/// @tparam String_t Output string type. Defaults to std::string.
111///
112/// @tparam Format_t Type of format.
113///
114/// @tparam Args_t Types of objects.
115///
116/// @param format Format object.
117///
118/// @param args Objects.
119///
120/// @return String_t object holding the result.
121///
122/// @throws bad_alloc if an out-of-memory condition occurred.
123template <class String_t = std::string, Is_format Format_t, class... Args_t>
124auto concat(const Format_t &format, const Args_t &...args) {
125 return mysql::strconv::throwing::encode<String_t>(
127}
128} // namespace throwing
129
130} // namespace mysql::strconv
131
132// addtogroup GroupLibsMysqlStrconv
133/// @}
134
135#endif // ifndef MYSQL_STRCONV_ENCODE_CONCAT_H
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
Experimental API header.
std::string format(const routing_guidelines::Session_info &session_info, bool extended_session_info)
Definition: dest_metadata_cache.cc:170
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
auto concat(const Format_t &format, const Args_t &...args)
Concatenate the string representations of the objects and return a std::string object holding the res...
Definition: concat.h:124
Definition: gtid_binary_format.h:41
void encode(const Debug_format &format, Is_string_target auto &target, const Repeat &repeat)
Definition: debug_repeat.h:39
auto concat_length(const Format_t &format, const Args_t &...args) noexcept
Compute the length of the concatenation of the string representations of the objects.
Definition: concat.h:60
auto concat(const Format_t &format, const Out_str_t &out, const Args_t &...args) noexcept
Concatenate the string representations of the objects into the output string wrapper.
Definition: concat.h:81
std::size_t compute_encoded_length(const Is_format auto &format, const auto &object)
Return the string length of the object.
Definition: encode.h:57
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.
Experimental API header.
Helper type that wraps the varargs of concat in a struct containing a tuple.
Definition: concat_object.h:40
Tuple_t m_args
Tuple holding objects to be concatenated.
Definition: concat_object.h:48