MySQL 8.3.0
Source Code Documentation
tag_plain.h
Go to the documentation of this file.
1// Copyright (c) 2023, 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 also distributed 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 included with MySQL.
13//
14// This program is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License, version 2.0, for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with this program; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
23#ifndef MYSQL_GTID_TAG_PLAIN_H
24#define MYSQL_GTID_TAG_PLAIN_H
25
26#include <array>
27#include <cstring>
28#include <memory>
29#include <string>
30
32#include "mysql/gtid/tag.h"
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:29
Definition: global.h:34
constexpr std::size_t tag_max_length
Maximal number of characters in a tag.
Definition: gtid_constants.h:43
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:38
std::size_t length() const
Obtains tag length.
Definition: tag_plain.cpp:40
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:46
const unsigned char * data() const
Internal data accessor (for encoding)
Definition: tag_plain.cpp:55
std::size_t to_string(char *buf) const
Copies internal tag into a given buffer.
Definition: tag_plain.cpp:30
void clear()
Clear this tag.
Definition: tag_plain.cpp:36