variant_sequential_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_SEQUENTIAL_VIEW_H_
29#define RTTR_VARIANT_SEQUENTIAL_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_sequential_view/variant_sequential_view_private.h"
35
36#include <cstddef>
37#include <vector>
38#include <memory>
39
40namespace rttr
41{
42 class type;
43 class instance;
44 class argument;
45
96{
97 public:
98 class const_iterator;
99
106
111
118
124 variant_sequential_view& operator=(const variant_sequential_view& other) RTTR_NOEXCEPT;
125
132 bool is_valid() const RTTR_NOEXCEPT;
133
141 explicit operator bool() const RTTR_NOEXCEPT;
142
146 void swap(variant_sequential_view& other) RTTR_NOEXCEPT;
147
148
156 type get_type() const RTTR_NOEXCEPT;
157
165 type get_value_type() const RTTR_NOEXCEPT;
166
172 bool is_empty() const RTTR_NOEXCEPT;
173
183 bool is_dynamic() const RTTR_NOEXCEPT;
184
196 std::size_t get_rank() const RTTR_NOEXCEPT;
197
209 type get_rank_type(std::size_t index) const RTTR_NOEXCEPT;
210
216 std::size_t get_size() const RTTR_NOEXCEPT;
217
225 bool set_size(std::size_t size) const RTTR_NOEXCEPT;
226
233
240
246 void clear();
247
254 bool set_value(std::size_t index, argument arg);
255
266 variant get_value(std::size_t index) const;
267
276
285
310 class RTTR_API const_iterator
311 {
312 public:
315
320
325
330
340 const variant operator*() const;
341
348 const variant get_data() const;
349
358
364
373
379
384
389
394
399
406 bool operator==(const const_iterator& other) const;
407
414 bool operator!=(const const_iterator& other) const;
415
416 private:
417 const_iterator(const detail::variant_sequential_view_private* view) RTTR_NOEXCEPT;
418 void swap(const_iterator& other);
419
421
422 const detail::variant_sequential_view_private* m_view;
423 detail::iterator_data m_itr;
424 };
425 private:
426 friend class variant;
427 friend class argument;
428
429 detail::variant_sequential_view_private m_view;
430};
431
432} // end namespace rttr
433
434#endif // RTTR_VARIANT_SEQUENTIAL_VIEW_H_
The argument class is used for forwarding arguments to properties or methods.
Definition argument.h:52
The instance class is used for forwarding the instance of an object to invoke a property or method.
Definition instance.h:48
The type class holds the type information for any arbitrary object.
Definition type.h:171
The variant_sequential_view::const_iterator allows iteration over an sequential container in a varian...
Definition variant_sequential_view.h:311
const_iterator & operator-=(int i)
Returns an iterator to the item at i positions backward from this iterator.
const_iterator self_type
Definition variant_sequential_view.h:313
const_iterator operator-(int i) const
Returns an iterator to the item at i positions backward from this iterator.
const_iterator & operator+=(int i)
Advances the iterator by i items.
const_iterator operator--(int)
Post-decrement operator makes the preceding item current and returns an iterator to the previously cu...
const_iterator & operator++()
Pre-increment operator advances the iterator to the next item in the container and returns an iterato...
const variant get_data() const
Returns the current value, stored inside a std::reference_wrapper<T> and copied to a variant.
const variant operator*() const
Returns the underlying value in a variant stored in a std::reference_wrapper<T>.
const_iterator(const const_iterator &other)
Creates a copy of other.
~const_iterator()
Destroys the variant_sequential_view::const_iterator.
const_iterator & operator=(const_iterator other)
Assigns other to this.
const_iterator operator+(int i) const
Returns an iterator to the item at i positions forward 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.
friend class variant_sequential_view
Definition variant_sequential_view.h:420
variant value_type
Definition variant_sequential_view.h:314
const_iterator & operator--()
Pre-decrement operator makes the preceding item current and returns an iterator to the new current it...
const_iterator operator++(int)
Post-increment operator advances the iterator to the next item in the container and returns an iterat...
bool operator!=(const const_iterator &other) const
Returns true if other points to a different item than this iterator; otherwise returns false.
type get_type() const noexcept
Returns the type object of this sequential container.
type get_rank_type(std::size_t index) const noexcept
Gets the type of the given rank index.
std::size_t get_size() const noexcept
Returns the number of elements in the sequential container.
bool is_dynamic() const noexcept
Returns true if this sequential view is dynamic, otherwise false.
bool set_value(std::size_t index, argument arg)
Set the content of the the argument arg at the specified index index into the underlying sequential c...
type get_value_type() const noexcept
Returns the type object from the value of this sequential container.
~variant_sequential_view() noexcept
Destroys the variant_sequential_view.
const_iterator insert(const const_iterator &pos, argument value)
Insert a value into the container.
const_iterator erase(const const_iterator &pos)
Removes the element (if one exists) at the position pos.
bool is_empty() const noexcept
Checks if the container has no elements.
variant_sequential_view()
Constructs an invalid variant_sequential_view object.
const_iterator end() const
Returns an iterator to the element following the last element of the container.
variant_sequential_view(const variant_sequential_view &other)
Constructs a copy of the given variant_sequential_view other.
std::size_t get_rank() const noexcept
Gets the rank (number of dimensions) of this sequential container.
void swap(variant_sequential_view &other) noexcept
Swaps this variant_sequential_view with the other variant_sequential_view.
const_iterator begin() const
Returns an iterator to the first element of the container.
void clear()
Removes all elements from the container.
friend class variant
Definition variant_sequential_view.h:426
bool set_size(std::size_t size) const noexcept
Sets the size of the sequential container.
friend class argument
Definition variant_sequential_view.h:427
variant get_value(std::size_t index) const
Returns the current value at index index.
bool is_valid() const noexcept
Returns true if this variant_sequential_view is valid, that means the object is holding some data.
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...