ponder 3.2
C++ reflection library
ArrayMapper Class Reference

Template providing a mapping between C++ arrays and Ponder ArrayProperty. More...

#include <arraymapper.hpp>

Detailed Description

Template providing a mapping between C++ arrays and Ponder ArrayProperty.

ArrayMapper<T> must define the following members in order to make T fully compliant with the system:

  • ElementType: type of the elements stored in the array
  • dynamic(): tells if the array is dynamic (i.e. supports insert and remove)
  • size(): retrieve the size of the array
  • get(): get the value of an element
  • set(): set the value of an element
  • insert(): insert a new element
  • remove(): remove an element

ValueMapper is specialized for every supported type, and can be specialized for any of your own array types in order to extend the system.

By default, ValueMapper supports the following types of array:

  • T[]
  • std::vector & std::vector<bool>
  • std::list

Here is an example of mapping for the std::vector class:

template <typename T>
struct ArrayMapper<std::vector<T> >
{
static constexpr bool isArray = true;
typedef T ElementType;
static bool dynamic()
{
return true;
}
static size_t size(const std::vector<T>& arr)
{
return arr.size();
}
static const T& get(const std::vector<T>& arr, size_t index)
{
return arr[index];
}
static void set(std::vector<T>& arr, size_t index, const T& value)
{
arr[index] = value;
}
static void insert(std::vector<T>& arr, size_t before, const T& value)
{
arr.insert(arr.begin() + before, value);
}
static void remove(std::vector<T>& arr, size_t index)
{
arr.erase(arr.begin() + index);
}
};

The documentation for this class was generated from the following file:
ArrayMapper
Template providing a mapping between C++ arrays and Ponder ArrayProperty.