variant_associative_view.h Source File - 0.9.6 |RTTR
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 
220  const_iterator find(argument key);
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 
324  ~const_iterator();
325 
329  const_iterator(const const_iterator& other);
330 
334  const_iterator& operator=(const_iterator other);
335 
342  const std::pair<variant, variant> operator*() const;
343 
350  const variant get_key() const;
351 
358  const variant get_value() const;
359 
367  const_iterator &operator++();
368 
373  const_iterator operator++(int);
374 
382  const_iterator &operator--();
383 
388  const_iterator operator--(int);
389 
393  const_iterator &operator+=(int i);
394 
398  const_iterator &operator-=(int i);
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_
Definition: access_levels.h:33
The type class holds the type information for any arbitrary object.
Definition: type.h:170
constexpr bool operator==(basic_string_view< CharT, Traits > lhs, basic_string_view< CharT, Traits > rhs) noexcept
Compares the two views lhs and rhs.
The variant_associative_view describes a class that refers to an associative container (e...
Definition: variant_associative_view.h:92
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...
constexpr bool operator!=(basic_string_view< CharT, Traits > lhs, basic_string_view< CharT, Traits > rhs) noexcept
Compares the two views lhs and rhs.
The argument class is used for forwarding arguments to properties or methods.
Definition: argument.h:51
The variant_associative_view::const_iterator allows iteration over an associative container in a vari...
Definition: variant_associative_view.h:315
The variant class allows to store data of any type and convert between these types transparently...
Definition: variant.h:197
std::basic_string< CharT, Traits > operator+(basic_string_view< CharT, Traits > lhs, const std::basic_string< CharT, Traits > &rhs)