MySQL 8.0.39
Source Code Documentation
multi_map_base.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 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 DD_CACHE__MULTI_MAP_BASE_INCLUDED
25#define DD_CACHE__MULTI_MAP_BASE_INCLUDED
26
27#include <stdio.h>
28
29#include "element_map.h" // Element_map
34#include "sql/dd/types/event.h"
37#include "sql/dd/types/schema.h"
40
41namespace dd {
42namespace cache {
43
44template <typename T>
45class Cache_element;
46
47/**
48 Implementation of a set of maps for a given object type.
49
50 The class declares a set of maps, each of which maps from a key type
51 to an element type. The element type wraps the template object type
52 parameter into a wrapper instance.
53
54 The implementation is intended to be used as a base to be extended for
55 usage in a specific context. There is support for adding and removing
56 elements in all maps with one operation (but not necessarily atomically),
57 and for retrieving a single map. There is no support for tracking object
58 usage, free list management, thread synchronization, etc.
59
60 @tparam T Dictionary object type.
61*/
62
63template <typename T>
65 private:
67
69 m_id_map; // Id map instance.
71 m_name_map; // Name map instance.
73 m_aux_map; // Aux map instance.
74
75 template <typename K>
76 struct Type_selector {}; // Dummy type to use for
77 // selecting map instance.
78
79 /**
80 Overloaded functions to use for selecting an element list instance
81 based on a key type. Const and non-const variants.
82 */
83
85 return &m_rev_map;
86 }
87
90 return &m_rev_map;
91 }
92
95 return &m_id_map;
96 }
97
100 return &m_id_map;
101 }
102
105 return &m_name_map;
106 }
107
110 return &m_name_map;
111 }
112
115 return &m_aux_map;
116 }
117
120 return &m_aux_map;
121 }
122
123 public:
124 // Iterate based on the reverse map where all elements must be present.
127
129
130 protected:
131 /**
132 Template function to get an element map.
133
134 To support generic code, the element map instances are available
135 through template function instances. This allows looking up the
136 appropriate instance based on the key type. We must use overloading
137 to accomplish this (see above). Const and non-const variants.
138
139 @tparam K Key type.
140
141 @return The element map handling keys of type K.
142 */
143
144 template <typename K>
146 return m_map(Type_selector<K>());
147 }
148
149 template <typename K>
151 return m_map(Type_selector<K>());
152 }
153
154 /**
155 Helper function to remove the mapping of a single element, without
156 deleting the element itself. This function assumes that checking for
157 key and element presence has already been done.
158
159 @param element Element to be removed and deleted.
160 */
161
163
164 /**
165 Helper function to add a single element.
166
167 This function assumes that checking for key and element presence
168 has already been done, that the object has been assigned, and that the
169 keys have been generated.
170
171 @param element Element to be added.
172 */
173
175
176 /**
177 Debug dump of the multi map base to stderr.
178 */
179
180 /* purecov: begin inspected */
181 void dump() const {
182#ifndef NDEBUG
183 fprintf(stderr, " Reverse element map:\n");
184 m_map<const T *>()->dump();
185 fprintf(stderr, " Id map:\n");
186 m_map<typename T::Id_key>()->dump();
187 fprintf(stderr, " Name map:\n");
188 m_map<typename T::Name_key>()->dump();
189 fprintf(stderr, " Aux map:\n");
190 m_map<typename T::Aux_key>()->dump();
191#endif
192 }
193 /* purecov: end */
194};
195
196} // namespace cache
197} // namespace dd
198
199#endif // DD_CACHE__MULTI_MAP_BASE_INCLUDED
Implementation of a dictionary client.
Definition: cache_element.h:69
Implementation of a map between a key type and an element type.
Definition: element_map.h:72
Implementation of a set of maps for a given object type.
Definition: multi_map_base.h:64
const Element_map< const T *, Cache_element< T > > * m_map(Type_selector< const T * >) const
Definition: multi_map_base.h:88
Element_map< typename T::Aux_key, Cache_element< T > > m_aux_map
Definition: multi_map_base.h:73
Element_map< constT *, Cache_element< T > >::Iterator Iterator
Definition: multi_map_base.h:128
Element_map< const T *, Cache_element< T > > m_rev_map
Definition: multi_map_base.h:66
const Element_map< typename T::Aux_key, Cache_element< T > > * m_map(Type_selector< typename T::Aux_key >) const
Definition: multi_map_base.h:118
Element_map< typename T::Id_key, Cache_element< T > > * m_map(Type_selector< typename T::Id_key >)
Definition: multi_map_base.h:93
Element_map< K, Cache_element< T > > * m_map()
Template function to get an element map.
Definition: multi_map_base.h:145
const Element_map< typename T::Id_key, Cache_element< T > > * m_map(Type_selector< typename T::Id_key >) const
Definition: multi_map_base.h:98
Element_map< typename T::Name_key, Cache_element< T > > m_name_map
Definition: multi_map_base.h:71
Element_map< const T *, Cache_element< T > > * m_map(Type_selector< const T * >)
Overloaded functions to use for selecting an element list instance based on a key type.
Definition: multi_map_base.h:84
const Element_map< K, Cache_element< T > > * m_map() const
Definition: multi_map_base.h:150
Element_map< constT *, Cache_element< T > >::Const_iterator Const_iterator
Definition: multi_map_base.h:126
Element_map< typename T::Name_key, Cache_element< T > > * m_map(Type_selector< typename T::Name_key >)
Definition: multi_map_base.h:103
void dump() const
Debug dump of the multi map base to stderr.
Definition: multi_map_base.h:181
Element_map< typename T::Aux_key, Cache_element< T > > * m_map(Type_selector< typename T::Aux_key >)
Definition: multi_map_base.h:113
void add_single_element(Cache_element< T > *element)
Helper function to add a single element.
Definition: multi_map_base.cc:59
Element_map< typename T::Id_key, Cache_element< T > > m_id_map
Definition: multi_map_base.h:69
void remove_single_element(Cache_element< T > *element)
Helper function to remove the mapping of a single element, without deleting the element itself.
Definition: multi_map_base.cc:45
const Element_map< typename T::Name_key, Cache_element< T > > * m_map(Type_selector< typename T::Name_key >) const
Definition: multi_map_base.h:108
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
Definition: multi_map_base.h:76