MySQL 9.1.0
Source Code Documentation
tag_plain.h
Go to the documentation of this file.
1// Copyright (c) 2023, 2024, 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_GTID_TAG_PLAIN_H
25#define MYSQL_GTID_TAG_PLAIN_H
26
27#include <array>
28#include <cstring>
29#include <memory>
30#include <string>
31
32#include "mysql/gtid/gtid_constants.h" // tag_max_length
33
34/// @addtogroup GroupLibsMysqlGtid
35/// @{
36
37namespace mysql::gtid {
38
39class Tag;
40
41/// @brief Tag representation so that:
42/// - Tag_plain is trivial
43/// - Tag_plain is standard layout
44/// Therefore, a Tag_plain object is not empty by default! Use clear() or
45/// brace-enclosed initializer list to create an empty tag.
46/// Tag_plain must be a POD because it is used in Gtid_specification
47struct Tag_plain {
48 /// @brief Default ctor
49 Tag_plain() = default;
50 /// @brief Construct from tag object
51 /// @param tag tag to copy
52 explicit Tag_plain(const Tag &tag);
53
54 /// @brief Clear this tag
55 void clear();
56
57 /// @brief Checks whether tag is defined
58 /// @retval true Tag is defined
59 /// @retval false Tag is empty
60 bool is_defined() const;
61
62 /// @brief Obtains tag length
63 /// @return tag length
64 std::size_t length() const;
65
66 /// @brief Copies internal tag into a given buffer
67 /// @param[in,out] buf Buffer, needs to be pre-allocated
68 /// @return Number of bytes written into the buffer
69 std::size_t to_string(char *buf) const;
70
71 /// @brief Sets internal data to match a given pattern
72 /// @param[in] tag Pattern to copy from
73 void set(const Tag &tag);
74
75 /// @brief Internal data accessor (for encoding)
76 const unsigned char *data() const;
77
78 private:
79 /// null terminated tag representation
80 unsigned char m_data[tag_max_length + 1];
81};
82
83static_assert(std::is_trivial_v<Tag_plain>);
84static_assert(std::is_standard_layout_v<Tag_plain>);
85
86} // namespace mysql::gtid
87
88/// @}
89
90#endif // MYSQL_GTID_TAG_PLAIN_H
Representation of the GTID tag.
Definition: tag.h:50
Definition: buf0block_hint.cc:30
Definition: global.h:35
constexpr std::size_t tag_max_length
Maximal number of characters in a tag.
Definition: gtid_constants.h:44
Tag representation so that:
Definition: tag_plain.h:47
Tag_plain()=default
Default ctor.
bool is_defined() const
Checks whether tag is defined.
Definition: tag_plain.cpp:40
std::size_t length() const
Obtains tag length.
Definition: tag_plain.cpp:42
unsigned char m_data[tag_max_length+1]
null terminated tag representation
Definition: tag_plain.h:80
void set(const Tag &tag)
Sets internal data to match a given pattern.
Definition: tag_plain.cpp:48
const unsigned char * data() const
Internal data accessor (for encoding)
Definition: tag_plain.cpp:57
std::size_t to_string(char *buf) const
Copies internal tag into a given buffer.
Definition: tag_plain.cpp:32
void clear()
Clear this tag.
Definition: tag_plain.cpp:38