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