MySQL 8.4.2
Source Code Documentation
field_wrapper.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_SERIALIZATION_FIELD_WRAPPER_H
25#define MYSQL_SERIALIZATION_FIELD_WRAPPER_H
26
29
30/// @file
31/// Experimental API header
32
33/// @addtogroup GroupLibsMysqlSerialization
34/// @{
35
36namespace mysql::serialization {
37
38/// @brief Wrapper for fields to hold field reference and
39/// user-defined, compile-time field size
40/// @note This is created in order to pass information about field size
41/// to the Archive
42template <typename Field_type, Field_size defined_field_size>
44 public:
46 static constexpr Field_size value_size = defined_field_size;
48 using Field_ref_wrapper_type = std::reference_wrapper<Field_type>;
49 /// @brief Constructor
50 /// @param field_reference Reference to field
51 Field_wrapper(Field_type &field_reference) : m_ref(field_reference) {}
52
53 /// @brief field bare reference accessor
54 /// @returns Reference to Field_type object
55 Field_ref_type get() { return m_ref.get(); }
56
57 private:
58 Field_ref_wrapper_type m_ref; ///< Internal reference
59};
60
61/// @brief Wrapper for fields to hold field reference and defined by the
62/// user compile time size of the field
63/// @note This is created in order to pass information about field size
64/// to the Archive
65template <typename Field_type, Field_size defined_field_size>
66class Field_wrapper<const Field_type, defined_field_size> {
67 public:
69 static constexpr Field_size value_size = defined_field_size;
70 using Field_ref_type = const Field_type &;
71 using Field_ref_wrapper_type = std::reference_wrapper<const Field_type>;
72 /// @brief Constructor
73 /// @param field_reference Reference to field
74 Field_wrapper(Field_ref_type field_reference) : m_ref(field_reference) {}
75
76 /// @brief field bare reference accessor
77 /// @returns Reference to Field_type object
78 Field_ref_type get() const { return m_ref.get(); }
79
80 private:
81 Field_ref_wrapper_type m_ref; ///< Internal reference
82};
83
84template <typename Field_type>
86 return Field_wrapper<Field_type, 0>(field_reference);
87}
88
89} // namespace mysql::serialization
90
91/// @}
92
93#endif // MYSQL_SERIALIZATION_FIELD_WRAPPER_H
Field_wrapper(Field_ref_type field_reference)
Constructor.
Definition: field_wrapper.h:74
Field_ref_wrapper_type m_ref
Internal reference.
Definition: field_wrapper.h:81
std::reference_wrapper< const Field_type > Field_ref_wrapper_type
Definition: field_wrapper.h:71
Field_ref_type get() const
field bare reference accessor
Definition: field_wrapper.h:78
Wrapper for fields to hold field reference and user-defined, compile-time field size.
Definition: field_wrapper.h:43
Field_wrapper(Field_type &field_reference)
Constructor.
Definition: field_wrapper.h:51
std::reference_wrapper< Field_type > Field_ref_wrapper_type
Definition: field_wrapper.h:48
Field_ref_wrapper_type m_ref
Internal reference.
Definition: field_wrapper.h:58
static constexpr Field_size value_size
Definition: field_wrapper.h:46
Field_ref_type get()
field bare reference accessor
Definition: field_wrapper.h:55
Experimental API header.
Definition: archive.h:37
auto create_varlen_field_wrapper(Field_type &field_reference)
Definition: field_wrapper.h:85
std::size_t Field_size
Definition: serialization_types.h:43
Experimental API header.
Definition: sql_resultset.h:36