variant_associative_view.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_VARIANT_ASSOCIATIVE_VIEW_H_
29 #define RTTR_VARIANT_ASSOCIATIVE_VIEW_H_
30 
31 #include "rttr/detail/base/core_prerequisites.h"
32 #include "rttr/detail/misc/misc_type_traits.h"
33 #include "rttr/variant.h"
34 #include "rttr/detail/variant_associative_view/variant_associative_view_private.h"
35 
36 #include <cstddef>
37 #include <vector>
38 #include <memory>
39 
40 namespace rttr
41 {
42  class type;
43  class instance;
44  class argument;
45 
93 {
94  public:
95  class const_iterator;
96 
103 
108 
114  ~variant_associative_view() RTTR_NOEXCEPT;
115 
121  variant_associative_view& operator=(const variant_associative_view& other) RTTR_NOEXCEPT;
122 
129  bool is_valid() const RTTR_NOEXCEPT;
130 
138  explicit operator bool() const RTTR_NOEXCEPT;
139 
143  void swap(variant_associative_view& other) RTTR_NOEXCEPT;
144 
145 
153  type get_type() const RTTR_NOEXCEPT;
154 
162  type get_key_type() const RTTR_NOEXCEPT;
163 
171  type get_value_type() const RTTR_NOEXCEPT;
172 
183  bool is_key_only_type() const RTTR_NOEXCEPT;
184 
190  bool is_empty() const RTTR_NOEXCEPT;
191 
197  std::size_t get_size() const RTTR_NOEXCEPT;
198 
205  std::pair<const_iterator, bool> insert(argument key);
206 
213  std::pair<const_iterator, bool> insert(argument key, argument value);
214 
221 
227  std::size_t erase(argument key);
228 
234  void clear();
235 
270  std::pair<const_iterator, const_iterator> equal_range(argument key);
271 
279  const_iterator begin() const;
280 
288  const_iterator end() const;
289 
315  class RTTR_API const_iterator
316  {
317  public:
320 
325 
330 
335 
342  const std::pair<variant, variant> operator*() const;
343 
350  const variant get_key() const;
351 
358  const variant get_value() const;
359 
368 
374 
383 
389 
394 
399 
403  const_iterator operator+(int i) const;
404 
408  const_iterator operator-(int i) const;
409 
416  bool operator==(const const_iterator& other) const;
417 
424  bool operator!=(const const_iterator& other) const;
425 
426  private:
427  const_iterator(const detail::variant_associative_view_private* view) RTTR_NOEXCEPT;
428  void swap(const_iterator& other);
429 
431 
432  const detail::variant_associative_view_private* m_view;
433  detail::iterator_data m_itr;
434  };
435  private:
436  friend class variant;
437  friend class argument;
438 
439  detail::variant_associative_view_private m_view;
440 };
441 
442 } // end namespace rttr
443 
444 #endif // RTTR_VARIANT_ASSOCIATIVE_VIEW_H_
The argument class is used for forwarding arguments to properties or methods.
Definition: argument.h:52
The type class holds the type information for any arbitrary object.
Definition: type.h:171
The variant_associative_view::const_iterator allows iteration over an associative container in a vari...
Definition: variant_associative_view.h:316
const_iterator & operator--()
Pre-decrement operator makes the preceding item current and returns an iterator to the new current it...
const_iterator operator-(int i) const
Returns an iterator to the item at i positions backward from this iterator.
const_iterator operator+(int i) const
Returns an iterator to the item at i positions forward from this iterator.
const variant get_key() const
Returns the current key, stored inside a std::reference_wrapper<T> and copied to a variant.
~const_iterator()
Destroys the variant_associative_view::const_iterator.
const_iterator(const const_iterator &other)
Creates a copy of other.
const_iterator & operator-=(int i)
Returns an iterator to the item at i positions backward from this iterator.
bool operator==(const const_iterator &other) const
Returns true if other points to the same item as this iterator; otherwise returns false.
const_iterator & operator++()
Pre-increment operator advances the iterator to the next item in the container and returns an iterato...
const_iterator & operator+=(int i)
Advances the iterator by i items.
const std::pair< variant, variant > operator*() const
Returns the underlying key and value stored in a std::pair<key, value>.
const_iterator & operator=(const_iterator other)
Assigns other to this.
const variant get_value() const
Returns the current value, stored inside a std::reference_wrapper<T> and copied to a variant.
const_iterator operator++(int)
Post-increment operator advances the iterator to the next item in the container and returns an iterat...
const_iterator operator--(int)
Post-decrement operator makes the preceding item current and returns an iterator to the previously cu...
bool operator!=(const const_iterator &other) const
Returns true if other points to a different item than this iterator; otherwise returns false.
The variant_associative_view describes a class that refers to an associative container (e....
Definition: variant_associative_view.h:93
variant_associative_view()
Constructs an invalid variant_associative_view object.
variant_associative_view(const variant_associative_view &other)
Constructs a copy of the given variant_associative_view other.
~variant_associative_view() noexcept
Destroys the variant_associative_view.
The variant class allows to store data of any type and convert between these types transparently.
Definition: variant.h:198
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...