associative_mapper.h Source File - 0.9.6 |RTTR
associative_mapper.h
Go to the documentation of this file.
1 /************************************************************************************
2 * *
3 * Copyright (c) 2014 - 2018 Axel Menzel <info@rttr.org> *
4 * *
5 * This file is part of RTTR (Run Time Type Reflection) *
6 * License: MIT License *
7 * *
8 * Permission is hereby granted, free of charge, to any person obtaining *
9 * a copy of this software and associated documentation files (the "Software"), *
10 * to deal in the Software without restriction, including without limitation *
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
12 * and/or sell copies of the Software, and to permit persons to whom the *
13 * Software is furnished to do so, subject to the following conditions: *
14 * *
15 * The above copyright notice and this permission notice shall be included in *
16 * all copies or substantial portions of the Software. *
17 * *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
24 * SOFTWARE. *
25 * *
26 *************************************************************************************/
27 
28 #ifndef RTTR_ASSOCIATIVE_MAPPER_H_
29 #define RTTR_ASSOCIATIVE_MAPPER_H_
30 
31 #include "rttr/detail/base/core_prerequisites.h"
32 
33 namespace rttr
34 {
35 
187 template<typename T>
189 {
190 #ifndef DOXYGEN
191  using is_valid = std::false_type;
192 #else
193  using container_t = T;
194  using key_t = typename T::key_type;
195  using value_t = typename T::mapped_type;
196  using itr_t = typename T::iterator;
199  using const_itr_t = typename T::const_iterator;
200 
202 
206  static const key_t& get_key(const const_itr_t& itr)
207  {
208  return itr->first;
209  }
210 
212 
216  static value_t& get_value(itr_t& itr)
217  {
218  return itr->second;
219  }
220 
224  static const value_t& get_value(const const_itr_t& itr)
225  {
226  return itr->second;
227  }
228 
230 
234  static itr_t begin(container_t& container)
235  {
236  return container.begin();
237  }
238 
242  static const_itr_t begin(const container_t& container)
243  {
244  return container.begin();
245  }
246 
248 
252  static itr_t end(container_t& container)
253  {
254  return container.end();
255  }
256 
260  static const_itr_t end(const container_t& container)
261  {
262  return container.end();
263  }
264 
266 
270  static itr_t find(container_t& container, const key_t& key)
271  {
272  return container.find(key);
273  }
274 
278  static const_itr_t find(const container_t& container, const key_t& key)
279  {
280  return container.find(key);
281  }
282 
284 
290  static std::pair<itr_t, itr_t> equal_range(container_t& container, const key_t& key)
291  {
292  return container.equal_range(key);
293  }
294 
300  static std::pair<const_itr_t, const_itr_t> equal_range(const container_t& container, const key_t& key)
301  {
302  return container.equal_range(key);
303  }
304 
306 
310  static void clear(container_t& container)
311  {
312  container.clear();
313  }
314 
318  static bool is_empty(const container_t& container)
319  {
320  return container.empty();
321  }
322 
326  static std::size_t get_size(const container_t& container)
327  {
328  return container.size();
329  }
330 
334  static std::size_t erase(container_t& container, const key_t& key)
335  {
336  return container.erase(key);
337  }
338 
344  static std::pair<itr_t, bool> insert_key(container_t& container, const key_t& key)
345  {
346  return { container.end(), false };
347  }
348 
354  static std::pair<itr_t, bool> insert_key_value(container_t& container, const key_t& key, const value_t& value)
355  {
356  return container.insert(std::make_pair(key, value));
357  }
358 #endif
359 };
360 
361 } // end namespace rttr
362 
363 #include "rttr/detail/impl/associative_mapper_impl.h"
364 
365 #endif // RTTR_ASSOCIATIVE_MAPPER_H_
Definition: access_levels.h:33
static std::pair< const_itr_t, const_itr_t > equal_range(const container_t &container, const key_t &key)
Returns a range containing all elements with the given key in the container.
Definition: associative_mapper.h:300
static const_itr_t begin(const container_t &container)
Returns an iterator to the first element of the container.
Definition: associative_mapper.h:242
static value_t & get_value(itr_t &itr)
Returns the current iterator&#39;s value as reference.
Definition: associative_mapper.h:216
static const key_t & get_key(const const_itr_t &itr)
Returns the current iterator&#39;s key as a const reference.
Definition: associative_mapper.h:206
detail::enum_data< Enum_Type > value(string_view, Enum_Type value)
The value function should be used to add a mapping from enum name to value during the registration pr...
typename T::iterator itr_t
An alias delcaration to the iterator.
Definition: associative_mapper.h:198
static const_itr_t find(const container_t &container, const key_t &key)
Finds an element with key equivalent to key and returns its iterator.
Definition: associative_mapper.h:278
static const_itr_t end(const container_t &container)
Returns an iterator to the element following the last element of the container.
Definition: associative_mapper.h:260
static std::pair< itr_t, bool > insert_key_value(container_t &container, const key_t &key, const value_t &value)
Inserts a key-value into the container.
Definition: associative_mapper.h:354
typename T::mapped_type value_t
Definition: associative_mapper.h:197
static std::pair< itr_t, itr_t > equal_range(container_t &container, const key_t &key)
Returns a range containing all elements with the given key in the container.
Definition: associative_mapper.h:290
static itr_t begin(container_t &container)
Returns an iterator to the first element of the container.
Definition: associative_mapper.h:234
typename T::key_type key_t
An alias to the key type.
Definition: associative_mapper.h:194
typename T::const_iterator const_itr_t
An alias delcaration to the const iterator.
Definition: associative_mapper.h:199
static const value_t & get_value(const const_itr_t &itr)
Returns the current iterator&#39;s value as const reference.
Definition: associative_mapper.h:224
static bool is_empty(const container_t &container)
Returns the number of elements in the container.
Definition: associative_mapper.h:318
static std::size_t get_size(const container_t &container)
Returns the number of elements in the container.
Definition: associative_mapper.h:326
static std::size_t erase(container_t &container, const key_t &key)
Removes the element (if one exists) with the key equivalent to key.
Definition: associative_mapper.h:334
T container_t
An alias declaration to the container type itself.
Definition: associative_mapper.h:193
static itr_t find(container_t &container, const key_t &key)
Finds an element with key equivalent to key and returns its iterator.
Definition: associative_mapper.h:270
static void clear(container_t &container)
Removes all elements from the container.
Definition: associative_mapper.h:310
static itr_t end(container_t &container)
Returns an iterator to the element following the last element of the container.
Definition: associative_mapper.h:252
The associative_container_mapper class is a class template to access an associative container via one...
Definition: associative_mapper.h:188
static std::pair< itr_t, bool > insert_key(container_t &container, const key_t &key)
Inserts a key into the container.
Definition: associative_mapper.h:344