MySQL 9.6.0
Source Code Documentation
nested_set_text_format.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_SETS_STRCONV_NESTED_SET_TEXT_FORMAT_H
25#define MYSQL_SETS_STRCONV_NESTED_SET_TEXT_FORMAT_H
26
27/// @file
28/// Experimental API header
29
30#include <string_view> // string_view
31#include "mysql/meta/is_specialization.h" // Is_specialization
32#include "mysql/sets/nested_set_meta.h" // Is_nested_set
33#include "mysql/strconv/formats/format.h" // Format_base
34#include "mysql/strconv/formats/text_format.h" // Text_format
35
36/// @addtogroup GroupLibsMysqlSets
37/// @{
38
39namespace mysql::strconv {
40
41/// Tag to identify the formatting algorithm for nested sets, using the given
42/// format tags for the key type and the mapped type, respectively. Also holds
43/// the separator strings used between key and mapped object, and between one
44/// key-mapped pair and another key-mapped pair.
45template <class Key_format_tp, class Mapped_format_tp>
47 using Key_format_t = Key_format_tp;
48 using Mapped_format_t = Mapped_format_tp;
50 const Key_format_t &key_format = Key_format_t{},
51 const Mapped_format_t &mapped_format = Mapped_format_t{},
52 std::string_view item_separator = ",",
53 std::string_view key_mapped_separator = ":")
54 : m_key_format(key_format),
55 m_mapped_format(mapped_format),
56 m_item_separator(item_separator),
57 m_key_mapped_separator(key_mapped_separator) {}
62 std::string_view m_item_separator;
63 std::string_view m_key_mapped_separator;
64 [[nodiscard]] constexpr auto parent() const { return Text_format{}; }
65};
66
67template <class Test>
70
71/// Make `mysql::strconv::encode_text` (and `encode(Text_format{}, ...)` use
72/// `Nested_set_text_format` when the object to format is a Nested set.
74 const mysql::sets::Is_nested_set auto &) {
76}
77
78} // namespace mysql::strconv
79
80// addtogroup GroupLibsMysqlSets
81/// @}
82
83#endif // ifndef MYSQL_SETS_STRCONV_NESTED_SET_TEXT_FORMAT_H
Concept used to determine at compile time whether a given type Test is a template specialization of t...
Definition: is_specialization.h:68
True if Test is a nested set.
Definition: nested_set_meta.h:110
Definition: nested_set_text_format.h:68
Experimental API header.
Experimental API header.
Definition: gtid_binary_format.h:41
auto get_default_format(const Binary_format &, const Object_t &)
Definition: gtid_binary_format.h:114
Experimental API header.
Top of the hierarchy.
Definition: format.h:38
Tag to identify the formatting algorithm for nested sets, using the given format tags for the key typ...
Definition: nested_set_text_format.h:46
Mapped_format_tp Mapped_format_t
Definition: nested_set_text_format.h:48
Nested_set_text_format(const Key_format_t &key_format=Key_format_t{}, const Mapped_format_t &mapped_format=Mapped_format_t{}, std::string_view item_separator=",", std::string_view key_mapped_separator=":")
Definition: nested_set_text_format.h:49
constexpr auto parent() const
Definition: nested_set_text_format.h:64
const Mapped_format_t m_mapped_format
Definition: nested_set_text_format.h:61
std::string_view m_item_separator
Definition: nested_set_text_format.h:62
Key_format_tp Key_format_t
Definition: nested_set_text_format.h:47
Nested_set_text_format(const Text_format &)
Definition: nested_set_text_format.h:58
const Key_format_t m_key_format
Definition: nested_set_text_format.h:60
std::string_view m_key_mapped_separator
Definition: nested_set_text_format.h:63
Format tag to identify text format.
Definition: text_format.h:38
Experimental API header.