MySQL 9.1.0
Source Code Documentation
serializable_type_traits.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_SERIALIZABLE_TYPE_TRAITS_H
25#define MYSQL_SERIALIZATION_SERIALIZABLE_TYPE_TRAITS_H
26
27#include <list>
28#include <map>
29#include <set>
30#include <string>
31#include <unordered_map>
32#include <unordered_set>
33#include <vector>
34
37
38/// @file
39/// Experimental API header
40
41/// @addtogroup GroupLibsMysqlSerialization
42/// @{
43
44namespace mysql::serialization {
45
46/// @brief This function checks whether given type is enum type
47/// @tparam T tested type
48/// @return Answer to question: is enum type ?
49template <class T>
50static constexpr bool is_enum_type() {
51 return std::is_enum<std::decay_t<T>>::value;
52}
53
54/// @brief This function checks whether given type is serializable
55/// @tparam T tested type
56/// @return Answer to question: is serializable ?
57template <class T>
58static constexpr bool is_serializable_type() {
59 return std::is_base_of<Serializable<std::decay_t<T>>, std::decay_t<T>>::value;
60}
61
62/// @brief This function checks whether given type is STL list or vector
63/// @tparam T tested type
64/// @return Answer to question: is list or vector ?
65template <class T>
66static constexpr bool is_vector_list_type() {
69}
70
71/// @brief This function checks whether given type is STL map or unordered map
72/// @tparam T tested type
73/// @return Answer to question: is map or unordered_map ?
74template <class T>
75static constexpr bool is_map_type() {
78}
79
80template <class T>
81struct is_std_array : std::false_type {};
82
83template <class T, std::size_t N>
84struct is_std_array<std::array<T, N>> : std::true_type {};
85
86/// @brief This function checks whether given type is STL array
87/// @tparam T tested type
88/// @return Answer to question: is STL array ?
89template <class T>
90static constexpr bool is_array_type_v() {
91 return is_std_array<std::decay_t<T>>::value ||
92 std::is_array<std::remove_const_t<T>>::value;
93}
94
95/// @brief This function checks whether given type is STL set or unordered set
96/// @tparam T tested type
97/// @return Answer to question: is set or unordered_set ?
98template <class T>
99static constexpr bool is_set_type() {
102}
103
104/// @brief This function checks whether given type is simple serializable type
105/// @tparam T tested type
106/// @return Answer to question: is simple serializable type?
107template <typename T>
108static constexpr bool is_simple_type() {
109 return (is_vector_list_type<T>() == false && is_map_type<T>() == false &&
110 is_set_type<T>() == false && is_serializable_type<T>() == false &&
111 is_enum_type<T>() == false && is_array_type_v<T>() == false);
112}
113
114/// @brief This function checks whether given type (set) is bounded
115/// @tparam T tested type
116/// @return Answer to question: is bounded size type?
117template <typename T>
118static constexpr bool is_bounded_size_type() {
119 return (is_vector_list_type<T>() == false && is_map_type<T>() == false &&
120 is_set_type<T>() == false && is_serializable_type<T>() == false &&
121 is_enum_type<T>() == false);
122}
123
124/// @brief This function checks whether given type is std::string
125/// @tparam T tested type
126/// @return Answer to question: is std::string ?
127template <class T>
128static constexpr bool is_string_type() {
129 return std::is_same<std::decay_t<T>, std::string>::value;
130}
131
132/// @brief This function checks whether given type is integer type
133/// @tparam T tested type
134/// @return Answer to question: is integer type ?
135template <class T>
136static constexpr bool is_integral_type() {
137 return std::is_integral<std::decay_t<T>>::value;
138}
139
140} // namespace mysql::serialization
141
142/// @}
143
144#endif // MYSQL_SERIALIZATION_SERIALIZABLE_TYPE_TRAITS_H
Experimental API header.
Definition: archive.h:37
static constexpr bool is_integral_type()
This function checks whether given type is integer type.
Definition: serializable_type_traits.h:136
static constexpr bool is_vector_list_type()
This function checks whether given type is STL list or vector.
Definition: serializable_type_traits.h:66
static constexpr bool is_map_type()
This function checks whether given type is STL map or unordered map.
Definition: serializable_type_traits.h:75
static constexpr bool is_set_type()
This function checks whether given type is STL set or unordered set.
Definition: serializable_type_traits.h:99
static constexpr bool is_string_type()
This function checks whether given type is std::string.
Definition: serializable_type_traits.h:128
static constexpr bool is_array_type_v()
This function checks whether given type is STL array.
Definition: serializable_type_traits.h:90
static constexpr bool is_simple_type()
This function checks whether given type is simple serializable type.
Definition: serializable_type_traits.h:108
static constexpr bool is_serializable_type()
This function checks whether given type is serializable.
Definition: serializable_type_traits.h:58
static constexpr bool is_bounded_size_type()
This function checks whether given type (set) is bounded.
Definition: serializable_type_traits.h:118
static constexpr bool is_enum_type()
This function checks whether given type is enum type.
Definition: serializable_type_traits.h:50
Definition: gcs_xcom_synode.h:64
std::unordered_map< Key, Value, Hash, Key_equal, ut::allocator< std::pair< const Key, Value > > > unordered_map
Definition: ut0new.h:2900
std::unordered_set< Key, std::hash< Key >, std::equal_to< Key >, ut::allocator< Key > > unordered_set
Definition: ut0new.h:2889
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2876
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2884
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2894
std::list< T, ut::allocator< T > > list
Specialization of list which uses ut_allocator.
Definition: ut0new.h:2880
Experimental API header.
Definition: serializable_type_traits.h:81
Helper struct used to determine at compile time whether a given type T is a template specialization o...
Definition: is_specialization.h:40