sequential_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_SEQUENTIAL_MAPPER_H_
29#define RTTR_SEQUENTIAL_MAPPER_H_
30
31#include "rttr/detail/base/core_prerequisites.h"
32
33namespace rttr
34{
35
187template<typename T>
189{
190#ifndef DOXYGEN
191 using is_valid = std::false_type;
192 using container_t = T;
193 using value_t = detail::invalid_type;
194#else
195 using container_t = T;
196 using key_t = typename T::key_type;
197 using value_t = typename T::mapped_type;
200 using itr_t = typename T::iterator;
201 using const_itr_t = typename T::const_iterator;
202
204
208 static const key_t& get_key(const const_itr_t& itr)
209 {
210 return itr->first;
211 }
212
214
219 {
220 return itr->second;
221 }
222
226 static const value_t& get_value(const const_itr_t& itr)
227 {
228 return itr->second;
229 }
230
232
237 {
238 return container.begin();
239 }
240
245 {
246 return container.begin();
247 }
248
250
255 {
256 return container.end();
257 }
258
263 {
264 return container.end();
265 }
266
268
273 {
274 return container.find(key);
275 }
276
281 {
282 return container.find(key);
283 }
284
286
292 static std::pair<itr_t, itr_t> equal_range(container_t& container, const key_t& key)
293 {
294 return container.equal_range(key);
295 }
296
302 static std::pair<const_itr_t, const_itr_t> equal_range(const container_t& container, const key_t& key)
303 {
304 return container.equal_range(key);
305 }
306
308
313 {
314 container.clear();
315 }
316
320 static bool is_empty(const container_t& container)
321 {
322 return container.empty();
323 }
324
328 static std::size_t get_size(const container_t& container)
329 {
330 return container.size();
331 }
332
336 static std::size_t erase(container_t& container, const key_t& key)
337 {
338 return container.erase(key);
339 }
340
346 static std::pair<itr_t, bool> insert_key(container_t& container, const key_t& key)
347 {
348 return { container.end(), false };
349 }
350
356 static std::pair<itr_t, bool> insert_key_value(container_t& container, const key_t& key, const value_t& value)
357 {
358 return container.insert(std::make_pair(key, value));
359 }
360#endif
361};
362
363} // end namespace rttr
364
365#include "rttr/detail/impl/sequential_mapper_impl.h"
366
367#endif // RTTR_SEQUENTIAL_MAPPER_H_
The array_range class provides a view into an underlying data structure with lower and upper limits.
Definition array_range.h:64
const_iterator end()
Returns an iterator to the element following the last element of the range.
bool empty() const
Checks if the range has no elements, i.e.
const_iterator begin()
Returns an iterator to the first element of the range.
size_t size() const
Returns the number of elements in the range.
Definition access_levels.h:34
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...
The sequential_container_mapper class is a class template to access an associative container via one ...
Definition sequential_mapper.h:189
typename T::key_type key_t
An alias to the key type.
Definition sequential_mapper.h:196
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 sequential_mapper.h:356
static itr_t end(container_t &container)
Returns an iterator to the element following the last element of the container.
Definition sequential_mapper.h:254
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 sequential_mapper.h:302
static itr_t begin(container_t &container)
Returns an iterator to the first element of the container.
Definition sequential_mapper.h:236
static void clear(container_t &container)
Removes all elements from the container.
Definition sequential_mapper.h:312
static std::pair< itr_t, bool > insert_key(container_t &container, const key_t &key)
Inserts a key into the container.
Definition sequential_mapper.h:346
static const key_t & get_key(const const_itr_t &itr)
Returns the current iterator's key as a const reference.
Definition sequential_mapper.h:208
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 sequential_mapper.h:280
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 sequential_mapper.h:292
static const value_t & get_value(const const_itr_t &itr)
Returns the current iterator's value as const reference.
Definition sequential_mapper.h:226
typename T::const_iterator const_itr_t
An alias delcaration to the const iterator.
Definition sequential_mapper.h:201
typename T::mapped_type value_t
Definition sequential_mapper.h:197
typename T::iterator itr_t
An alias delcaration to the iterator.
Definition sequential_mapper.h:200
static std::size_t get_size(const container_t &container)
Returns the number of elements in the container.
Definition sequential_mapper.h:328
static itr_t find(container_t &container, const key_t &key)
Finds an element with key equivalent to key and returns its iterator.
Definition sequential_mapper.h:272
static const_itr_t end(const container_t &container)
Returns an iterator to the element following the last element of the container.
Definition sequential_mapper.h:262
static bool is_empty(const container_t &container)
Returns the number of elements in the container.
Definition sequential_mapper.h:320
static value_t & get_value(itr_t &itr)
Returns the current iterator's value as reference.
Definition sequential_mapper.h:218
static const_itr_t begin(const container_t &container)
Returns an iterator to the first element of the container.
Definition sequential_mapper.h:244
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 sequential_mapper.h:336