rttr::array_mapper< T > Struct Template - 0.9.5 |RTTR
rttr::array_mapper< T > Struct Template Reference

The array_mapper class is a class template to access different array types via one common interface. More...

#include <array_mapper.h>

Public Types

using array_type = T
 
using raw_type = typename array_mapper< T >::raw_type
 
using sub_type = T
 

Static Public Member Functions

static std::size_t get_size (const array_type &)
 
static const T & get_value (const array_type &arr, std::size_t index)
 
static T & get_value (array_type &arr, std::size_t index)
 
static bool insert_value (array_type &, const T &value, std::size_t,)
 
static bool is_dynamic ()
 
static bool remove_value (array_type &, std::size_t)
 
static bool set_size (array_type &arr, std::size_t new_size)
 

Detailed Description

template<typename T>
struct rttr::array_mapper< T >

The array_mapper class is a class template to access different array types via one common interface.

This class will be only used internally by RTTR via the variant_array_view class to get access to elements of an array. In order to use your own custom array type, you have to provide a specialization of this class.

Out of the box, RTTR has specialization for following array types:

  • T[N], raw arrays
  • std::vector<T>
  • std::array<T, N>
  • std::list<T>

Custom array types

For a specialization of the class array_mapper<T> you have to provide two nested alias templates:

  1. using raw_type = typename array_mapper<T>::raw_type;
  2. using sub_type = T;

and following member functions:

  1. static bool is_dynamic();
  2. static bool set_size(array_type& arr, std::size_t new_size);
  3. static const T& get_value(const array_type& arr, std::size_t index);
  4. static T& get_value(array_type& arr, std::size_t index);
  5. static bool insert_value(array_type& arr, const T& value, std::size_t index);
  6. static bool remove_value(array_type& arr, std::size_t index);

Following code example for std::vector<T> illustrates how to add a specialization:

namespace rttr
{
template <typename T>
struct array_mapper<std::vector<T> >
{
using raw_type = typename array_mapper<T>::raw_type;
using sub_type = T;
static bool is_dynamic()
{
return true;
}
static std::size_t get_size(const std::vector<T>& arr)
{
return arr.size();
}
static bool set_size(std::vector<T>& arr, std::size_t new_size)
{
arr.resize(new_size);
return true;
}
static const T& get_value(const std::vector<T>& arr, std::size_t index)
{
return arr[index];
}
static T& get_value(std::vector<T>& arr, std::size_t index)
{
return arr[index];
}
static bool insert_value(std::vector<T>& arr, const T& value, std::size_t index)
{
arr.insert(arr.begin() + index, value);
return true;
}
static bool remove_value(std::vector<T>& arr, std::size_t index)
{
arr.erase(arr.begin() + index);
return true;
}
};
} // end namespace rttr
Remarks
Make sure you put your specialization inside the namespace rttr. The best place for this code, is below the declaration of your custom array type. When this is not possible, include your specialization code before registering your types to RTTR.

Member Typedef Documentation

template<typename T>
using rttr::array_mapper< T >::array_type = T
template<typename T>
using rttr::array_mapper< T >::raw_type = typename array_mapper<T>::raw_type
template<typename T>
using rttr::array_mapper< T >::sub_type = T

Member Function Documentation

template<typename T>
static std::size_t rttr::array_mapper< T >::get_size ( const array_type )
inlinestatic
template<typename T>
static const T& rttr::array_mapper< T >::get_value ( const array_type arr,
std::size_t  index 
)
inlinestatic
template<typename T>
static T& rttr::array_mapper< T >::get_value ( array_type arr,
std::size_t  index 
)
inlinestatic
template<typename T>
static bool rttr::array_mapper< T >::insert_value ( array_type ,
const T &  value,
std::size_t   
)
inlinestatic
template<typename T>
static bool rttr::array_mapper< T >::is_dynamic ( )
inlinestatic
template<typename T>
static bool rttr::array_mapper< T >::remove_value ( array_type ,
std::size_t   
)
inlinestatic
template<typename T>
static bool rttr::array_mapper< T >::set_size ( array_type arr,
std::size_t  new_size 
)
inlinestatic

The documentation for this struct was generated from the following file: