The variant_array class is a specialization of a variant, but for array types. More...
#include <variant_array.h>
Public Member Functions | |
variant_array () | |
Constructs an invalid variant_array object. More... | |
template<typename T > | |
variant_array (const T &value) | |
Constructs a variant_array from the given argument value of type T . More... | |
template<typename T > | |
variant_array (T &&value) | |
Perfect forwarding of a value . More... | |
variant_array (const variant_array &other) | |
Constructs a copy of the given variant_array other . More... | |
variant_array (variant_array &&other) | |
Constructs a new variant_array via move constructor. More... | |
~variant_array () | |
Destroys the variant_array and the contained data. More... | |
std::size_t | get_rank () const |
Gets the rank (number of dimensions) of the array. More... | |
type | get_rank_type (std::size_t index) const |
Gets the type of the given rank index. More... | |
std::size_t | get_size () const |
Returns the size of the first dimension from the array. More... | |
std::size_t | get_size (std::size_t index_1) const |
Returns the size of the array at the second dimension at index index_1 . More... | |
std::size_t | get_size (std::size_t index_1, std::size_t index_2) const |
Returns the size of the array at the third dimension at index index_2 , relative to the first dimension at index index_1 . More... | |
std::size_t | get_size_variadic (const std::vector< std::size_t > &index_list) const |
Returns the size from of the array at the specified indices in list index_list . More... | |
type | get_type () const |
Returns the type object of this array. More... | |
variant | get_value (std::size_t index_1) const |
Returns the value of the array in the first dimension at index index_1 . More... | |
variant | get_value (std::size_t index_1, std::size_t index_2) const |
Returns the value of the array in the second dimension at index index_2 , relative to the first dimension at index index_1 . More... | |
variant | get_value (std::size_t index_1, std::size_t index_2, std::size_t index_3) const |
Returns the value of the array in the third dimension at index index_3 , relative to the first dimension at index index_1 and second dimension at index index_2 . More... | |
variant | get_value_variadic (const std::vector< std::size_t > &index_list) const |
Returns the value of the array relative to to indices given in the list index_list . More... | |
bool | insert_value (std::size_t index_1, detail::argument arg) |
Inserts the given argument arg into the array, in the first dimension at index index_1 . More... | |
bool | insert_value (std::size_t index_1, std::size_t index_2, detail::argument arg) |
Inserts the given argument arg into the array, in the second dimension at index index_2 , relative to the first dimension at index index_1 . More... | |
bool | insert_value (std::size_t index_1, std::size_t index_2, std::size_t index_3, detail::argument arg) |
Inserts the given argument arg into the array, in the third dimension at index index_3 , relative to the first dimension at index index_1 and the second dimension at index index_2 . More... | |
bool | insert_value_variadic (const std::vector< std::size_t > &index_list, detail::argument arg) |
Inserts the given argument arg into the array, relative to to indices given in the list index_list . More... | |
bool | is_dynamic () const |
Returns true if this array is dynamic, that means the size can be changed; otherwise false. More... | |
bool | is_raw_array () const |
Returns true when this array is a raw array i.e. More... | |
bool | is_valid () const |
Returns true if this variant_array is valid, otherwise false. More... | |
template<typename T > | |
variant_array & | operator= (T &&other) |
Assigns the value of the other object to this variant_array. More... | |
variant_array & | operator= (variant_array &&other) |
Assigns the value of the other variant_array to this variant_array. More... | |
variant_array & | operator= (const variant_array &other) |
Assigns the value of the other variant_array to this variant_array. More... | |
bool | remove_value (std::size_t index_1) |
Removes the value at index index_1 in the first dimension of the array. More... | |
bool | remove_value (std::size_t index_1, std::size_t index_2) |
Removes the value at index index_2 in the second dimension of the array relative to the first dimension at index index_1 . More... | |
bool | remove_value (std::size_t index_1, std::size_t index_2, std::size_t index_3) |
Removes the value at index index_3 in the third dimension of the array. More... | |
bool | remove_value_variadic (const std::vector< std::size_t > &index_list) |
Removes the value at index index_1 in the first dimension of the array. More... | |
bool | set_size (std::size_t new_size) |
Sets the size of the array at the first dimension to new_size . More... | |
bool | set_size (std::size_t new_size, std::size_t index_1) |
Sets the size of the array at the second dimension relative to the first dimension at index index_1 to new_size . More... | |
bool | set_size (std::size_t new_size, std::size_t index_1, std::size_t index_2) |
Sets the size of the array at the third dimension relative to the first dimension at index index_1 and the second dimension at index index_2 to new_size . More... | |
bool | set_size_variadic (std::size_t new_size, const std::vector< std::size_t > &index_list) |
Sets the size of the array at the specified indices in list index_list . More... | |
bool | set_value (detail::argument arg) |
Copies the content of the the array arg into the underlying array. More... | |
bool | set_value (std::size_t index_1, detail::argument arg) |
Set the content of the the argument arg into the in the first dimension of the array at index index_1 . More... | |
bool | set_value (std::size_t index_1, std::size_t index_2, detail::argument arg) |
Set the content of the the argument arg into the in the second dimension at index_2 of the array relative to the first dimension at index_1. More... | |
bool | set_value (std::size_t index_1, std::size_t index_2, std::size_t index_3, detail::argument arg) |
Set the content of the the argument arg into the in the third dimension at index_3 of the array relative to the first dimension at index_1 and second dimension at index_2 . More... | |
bool | set_value_variadic (const std::vector< std::size_t > &index_list, detail::argument arg) |
Set the content of the the argument arg into the array in the n-th dimension given in the list index_list . More... | |
void | swap (variant_array &other) |
Swaps this variant_array with the other variant_array. More... | |
The variant_array class is a specialization of a variant, but for array types.
With an instance of that class you can set and get values of an array with any dimension level.
A variant_array can be created directly with an array type or from a variant with variant::to_array(). Use before variant::is_array(), otherwise it might not be possible to create a valid variant_array object.
An array is defined by its rank, it's size and whether he is dynamic or not.
The rank of an array describes the number of dimensions. E.g. int[10]
has a rank of 1
. int[2][10]
has an rank of 2
and so on. RTTR allows you to register types with an arbitrary rank count. For retrieving the size of an array use get_size(). With this function it is also possible to determine the size of the array relative to its rank level and it's index. Take a look at following example:
When the given array type is dynamic you can change the size of the array, therefore set_size() should be used. A value of an array can be accessed with get_value() or set with set_value. These function expect an index for up to rank level 3. The array class has here one interesting feature, you can set and get the value of an array up to its rank count. e.g:
When you have arrays bigger then this rank, use the counterpart functions: get_value_variadic and set_value_variadic which expects a list of indices. When the array is dynamic it is also possible to insert or remove values.
RTTR recognize whether a type is an array or not with the help of an array_mapper
class template. This class does the mapping for the standard access function defined in the array class. At the moment there exist specializations for following types: std::array<T, N>
, std::vector<T>
, std::list<T>
and raw-arrays T[N]
.
When you need to bind an own custom array type, then you have the implement following functions in the class array_mapper
.
Remark the namespaces rttr::detail, otherwise your specialization will not be recognized.
A variant_array object is can be copied and assigned, however each copy will perform a copy of the contained value.
rttr::variant_array::variant_array | ( | ) |
Constructs an invalid variant_array object.
rttr::variant_array::variant_array | ( | const T & | value | ) |
Constructs a variant_array from the given argument value
of type T
.
rttr::variant_array::variant_array | ( | T && | value | ) |
Perfect forwarding of a value
.
rttr::variant_array::variant_array | ( | const variant_array & | other | ) |
Constructs a copy of the given variant_array other
.
rttr::variant_array::variant_array | ( | variant_array && | other | ) |
Constructs a new variant_array via move constructor.
rttr::variant_array::~variant_array | ( | ) |
Destroys the variant_array and the contained data.
std::size_t rttr::variant_array::get_rank | ( | ) | const |
Gets the rank (number of dimensions) of the array.
For example, int[10] returns 1; int[2][10] returns 2, and so on.
type rttr::variant_array::get_rank_type | ( | std::size_t | index | ) | const |
Gets the type of the given rank index.
For example, an array of type int[2][10] returns for get_rank_type(0) => int[2][10] get_rank_type(1) => int[10]; get_rank_type(2) => int
index
. std::size_t rttr::variant_array::get_size | ( | ) | const |
Returns the size of the first dimension from the array.
std::size_t rttr::variant_array::get_size | ( | std::size_t | index_1 | ) | const |
Returns the size of the array at the second dimension at index index_1
.
std::size_t rttr::variant_array::get_size | ( | std::size_t | index_1, |
std::size_t | index_2 | ||
) | const |
Returns the size of the array at the third dimension at index index_2
, relative to the first dimension at index index_1
.
std::size_t rttr::variant_array::get_size_variadic | ( | const std::vector< std::size_t > & | index_list | ) | const |
Returns the size from of the array at the specified indices in list index_list
.
The index count specify the array dimension.
type rttr::variant_array::get_type | ( | ) | const |
variant rttr::variant_array::get_value | ( | std::size_t | index_1 | ) | const |
Returns the value of the array in the first dimension at index index_1
.
variant rttr::variant_array::get_value | ( | std::size_t | index_1, |
std::size_t | index_2 | ||
) | const |
Returns the value of the array in the second dimension at index index_2
, relative to the first dimension at index index_1
.
variant rttr::variant_array::get_value | ( | std::size_t | index_1, |
std::size_t | index_2, | ||
std::size_t | index_3 | ||
) | const |
Returns the value of the array in the third dimension at index index_3
, relative to the first dimension at index index_1
and second dimension at index index_2
.
variant rttr::variant_array::get_value_variadic | ( | const std::vector< std::size_t > & | index_list | ) | const |
Returns the value of the array relative to to indices given in the list index_list
.
bool rttr::variant_array::insert_value | ( | std::size_t | index_1, |
detail::argument | arg | ||
) |
Inserts the given argument arg
into the array, in the first dimension at index index_1
.
arg
could be inserted, otherwise false. bool rttr::variant_array::insert_value | ( | std::size_t | index_1, |
std::size_t | index_2, | ||
detail::argument | arg | ||
) |
Inserts the given argument arg
into the array, in the second dimension at index index_2
, relative to the first dimension at index index_1
.
arg
could be inserted, otherwise false. bool rttr::variant_array::insert_value | ( | std::size_t | index_1, |
std::size_t | index_2, | ||
std::size_t | index_3, | ||
detail::argument | arg | ||
) |
Inserts the given argument arg
into the array, in the third dimension at index index_3
, relative to the first dimension at index index_1
and the second dimension at index index_2
.
arg
could be inserted, otherwise false. bool rttr::variant_array::insert_value_variadic | ( | const std::vector< std::size_t > & | index_list, |
detail::argument | arg | ||
) |
Inserts the given argument arg
into the array, relative to to indices given in the list index_list
.
arg
could be inserted, otherwise false. bool rttr::variant_array::is_dynamic | ( | ) | const |
Returns true if this array is dynamic, that means the size can be changed; otherwise false.
bool rttr::variant_array::is_raw_array | ( | ) | const |
Returns true when this array is a raw array i.e.
int[10].
bool rttr::variant_array::is_valid | ( | ) | const |
Returns true if this variant_array is valid, otherwise false.
variant_array& rttr::variant_array::operator= | ( | T && | other | ) |
Assigns the value of the other
object to this variant_array.
variant_array& rttr::variant_array::operator= | ( | variant_array && | other | ) |
Assigns the value of the other variant_array to this variant_array.
variant_array& rttr::variant_array::operator= | ( | const variant_array & | other | ) |
Assigns the value of the other variant_array to this variant_array.
bool rttr::variant_array::remove_value | ( | std::size_t | index_1 | ) |
Removes the value at index index_1
in the first dimension of the array.
bool rttr::variant_array::remove_value | ( | std::size_t | index_1, |
std::size_t | index_2 | ||
) |
Removes the value at index index_2
in the second dimension of the array relative to the first dimension at index index_1
.
bool rttr::variant_array::remove_value | ( | std::size_t | index_1, |
std::size_t | index_2, | ||
std::size_t | index_3 | ||
) |
Removes the value at index index_3
in the third dimension of the array.
relative to the first dimension at index index_1
and the second dimension at index index_2
.
bool rttr::variant_array::remove_value_variadic | ( | const std::vector< std::size_t > & | index_list | ) |
Removes the value at index index_1
in the first dimension of the array.
bool rttr::variant_array::set_size | ( | std::size_t | new_size | ) |
Sets the size of the array at the first dimension to new_size
.
bool rttr::variant_array::set_size | ( | std::size_t | new_size, |
std::size_t | index_1 | ||
) |
Sets the size of the array at the second dimension relative to the first dimension at index index_1
to new_size
.
bool rttr::variant_array::set_size | ( | std::size_t | new_size, |
std::size_t | index_1, | ||
std::size_t | index_2 | ||
) |
Sets the size of the array at the third dimension relative to the first dimension at index index_1
and the second dimension at index index_2
to new_size
.
bool rttr::variant_array::set_size_variadic | ( | std::size_t | new_size, |
const std::vector< std::size_t > & | index_list | ||
) |
Sets the size of the array at the specified indices in list index_list
.
The index count specify the array dimension.
bool rttr::variant_array::set_value | ( | detail::argument | arg | ) |
Copies the content of the the array arg
into the underlying array.
bool rttr::variant_array::set_value | ( | std::size_t | index_1, |
detail::argument | arg | ||
) |
Set the content of the the argument arg
into the in the first dimension of the array at index index_1
.
bool rttr::variant_array::set_value | ( | std::size_t | index_1, |
std::size_t | index_2, | ||
detail::argument | arg | ||
) |
Set the content of the the argument arg
into the in the second dimension at index_2
of the array relative to the first dimension at index_1.
bool rttr::variant_array::set_value | ( | std::size_t | index_1, |
std::size_t | index_2, | ||
std::size_t | index_3, | ||
detail::argument | arg | ||
) |
Set the content of the the argument arg
into the in the third dimension at index_3
of the array relative to the first dimension at index_1
and second dimension at index_2
.
bool rttr::variant_array::set_value_variadic | ( | const std::vector< std::size_t > & | index_list, |
detail::argument | arg | ||
) |
Set the content of the the argument arg
into the array in the n-th dimension given in the list index_list
.
void rttr::variant_array::swap | ( | variant_array & | other | ) |
Swaps this variant_array with the other variant_array.