Skip to content

Commit

Permalink
use macro for conversion template definition
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrauch committed May 25, 2024
1 parent dfd7d8e commit bb725b7
Showing 1 changed file with 17 additions and 63 deletions.
80 changes: 17 additions & 63 deletions src/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
#include <libcamera/geometry.h>
#include <string>

#define MAP(T, N) \
template<> \
struct ControlTypeMap<libcamera::details::control_type<T>::value> \
{ \
using type = T; \
}; \
typedef ControlTypeMap<libcamera::ControlType##N>::type CT##N;


namespace std
{
Expand All @@ -17,66 +25,12 @@ to_string(const libcamera::ControlType id);
template<libcamera::ControlType>
struct ControlTypeMap;

template<>
struct ControlTypeMap<libcamera::ControlTypeNone>
{
using type = void;
};

template<>
struct ControlTypeMap<libcamera::ControlTypeBool>
{
using type = bool;
};

template<>
struct ControlTypeMap<libcamera::ControlTypeByte>
{
using type = uint8_t;
};

template<>
struct ControlTypeMap<libcamera::ControlTypeInteger32>
{
using type = int32_t;
};

template<>
struct ControlTypeMap<libcamera::ControlTypeInteger64>
{
using type = int64_t;
};

template<>
struct ControlTypeMap<libcamera::ControlTypeFloat>
{
using type = float;
};

template<>
struct ControlTypeMap<libcamera::ControlTypeString>
{
using type = std::string;
};

template<>
struct ControlTypeMap<libcamera::ControlTypeRectangle>
{
using type = libcamera::Rectangle;
};

template<>
struct ControlTypeMap<libcamera::ControlTypeSize>
{
using type = libcamera::Size;
};

typedef ControlTypeMap<libcamera::ControlTypeNone>::type CTNone;
typedef ControlTypeMap<libcamera::ControlTypeBool>::type CTBool;
typedef ControlTypeMap<libcamera::ControlTypeByte>::type CTByte;
typedef ControlTypeMap<libcamera::ControlTypeInteger32>::type CTInteger32;
typedef ControlTypeMap<libcamera::ControlTypeInteger64>::type CTInteger64;
typedef ControlTypeMap<libcamera::ControlTypeFloat>::type CTFloat;
typedef ControlTypeMap<libcamera::ControlTypeString>::type CTString;
typedef ControlTypeMap<libcamera::ControlTypeRectangle>::type CTRectangle;
typedef ControlTypeMap<libcamera::ControlTypeSize>::type CTSize;
MAP(void, None);
MAP(bool, Bool);
MAP(uint8_t, Byte);
MAP(int32_t, Integer32);
MAP(int64_t, Integer64);
MAP(float, Float);
MAP(std::string, String);
MAP(libcamera::Rectangle, Rectangle);
MAP(libcamera::Size, Size);

0 comments on commit bb725b7

Please sign in to comment.