#ifndef NAVLIB_TEMPLATES_H_INCLUDED_ #define NAVLIB_TEMPLATES_H_INCLUDED_ /* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (c) 2014-2021 3Dconnexion. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ /** * @file navlib_templates.h * @brief templates used in the 3dconnexion interface. */ #if (defined _MSC_VER && _MSC_VER < 1900) #define CONSTEXPR const #else #define CONSTEXPR constexpr #define has_constexpr #endif _NAVLIB_BEGIN template struct property_type_v { static CONSTEXPR propertyType_t type = unknown_type; #ifdef has_constexpr static constexpr char const *name = "unknown_type"; #else static const char *name; #endif }; #ifndef has_constexpr template const char *property_type_v::name = "unknown_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = voidptr_type; #ifdef has_constexpr static constexpr char const *name = "voidptr_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "voidptr_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = bool_type; #ifdef has_constexpr static constexpr char const *name = "bool_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "bool_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = long_type; #ifdef has_constexpr static constexpr char const *name = "long_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "long_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = float_type; #ifdef has_constexpr static constexpr char const *name = "float_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "float_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = double_type; #ifdef has_constexpr static constexpr char const *name = "double_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "double_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = point_type; #ifdef has_constexpr static constexpr char const *name = "point_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "point_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = vector_type; #ifdef has_constexpr static constexpr char const *name = "vector_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "vector_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = plane_type; #ifdef has_constexpr static constexpr char const *name = "plane_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "plane_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = box_type; #ifdef has_constexpr static constexpr char const *name = "box_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "box_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = frustum_type; #ifdef has_constexpr static constexpr char const *name = "frustum_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "frustum_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = matrix_type; #ifdef has_constexpr static constexpr char const *name = "matrix_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "matrix_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = actionnodeexptr_type; #ifdef has_constexpr static constexpr char const *name = "actionnodeexptr_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "actionnodeexptr_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = string_type; #ifdef has_constexpr static constexpr char const *name = "string_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "string_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = cstr_type; #ifdef has_constexpr static constexpr char const *name = "cstr_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "cstr_type"; #endif template <> struct property_type_v { static CONSTEXPR propertyType_t type = imagearray_type; #ifdef has_constexpr static constexpr char const *name = "imagearray_type"; #else static const char *name; #endif }; #ifndef has_constexpr __declspec(selectany) const char *property_type_v::name = "imagearray_type"; #endif template struct remove_cvref { typedef typename std::remove_cv::type>::type type; }; // navlib property type from variable type template struct property_type : property_type_v::type> { typedef property_type_v::type> base_type; typedef propertyType_t value_type; CONSTEXPR value_type operator()() const { return base_type::value; } #ifdef has_constexpr constexpr operator value_type() const { return base_type::value; } constexpr operator char *() const { return base_type::name; } #else operator const value_type() const { return base_type::value; } operator const char *() const { return base_type::name; } #endif }; template struct value_member {}; // primary template // specialization for void* template struct value_member { T operator()(V &v) { return v.p; } }; // specialization for void** template struct value_member { T operator()(V &v) { return &v.p; } }; // specialization for bool template struct value_member { T operator()(V &v) { return v.b != 0; } }; // specialization for bool_t template struct value_member { T operator()(V &v) { return v.b; } }; // specialization for bool_t* template struct value_member { T operator()(V &v) { return &v.b; } }; // specialization for int template struct value_member { T operator()(V &v) { return v.l; } }; // specialization for long template struct value_member { T operator()(V &v) { return v.l; } }; // specialization for long* template struct value_member { T operator()(V &v) { return &v.l; } }; // specialization for float template struct value_member { T operator()(V &v) { return v.f; } }; // specialization for float* template struct value_member { T operator()(V &v) { return &v.f; } }; // specialization for double template struct value_member { T operator()(V &v) { return v.d; } }; // specialization for double* template struct value_member { T operator()(V &v) { return &v.d; } }; // specialization for point_t template struct value_member { T operator()(V &v) { return v.point; } }; // specialization for point_t* template struct value_member { T operator()(V &v) { return &v.point; } }; // specialization for vector_t template struct value_member { T operator()(V &v) { return v.vector; } }; // specialization for vector_t* template struct value_member { T operator()(V &v) { return &v.vector; } }; // specialization for plane_t template struct value_member { T operator()(V &v) { return v.plane; } }; // specialization for plane_t* template struct value_member { T operator()(V &v) { return &v.plane; } }; // specialization for box_t template struct value_member { T operator()(V &v) { return v.box; } }; // specialization for box_t* template struct value_member { T operator()(V &v) { return &v.box; } }; // specialization for frustum_t template struct value_member { T operator()(V &v) { return v.frustum; } }; // specialization for frustum_t* template struct value_member { T operator()(V &v) { return &v.frustum; } }; // specialization for matrix_t template struct value_member { T operator()(V &v) { return v.matrix; } }; // specialization for matrix_t* template struct value_member { T operator()(V &v) { return &v.matrix; } }; // specialization for SiActionNodeEx_t* template struct value_member { T operator()(V &v) { return v.pnode; } }; // specialization for SiActionNodeEx_t** template struct value_member { T operator()(V &v) { return &v.pnode; } }; // specialization for string_t template struct value_member { T operator()(V &v) { return v.string; } }; // specialization for string_t* template struct value_member { T operator()(V &v) { return &v.string; } }; // specialization for cstr_t template struct value_member { T operator()(V &v) { return v.cstr_; } }; // specialization for cstr_t* template struct value_member { T operator()(V &v) { return &v.cstr_; } }; // specialization for imagearray_t template struct value_member { T operator()(V &v) { return v.imagearray; } }; // specialization for imagearray_t* template struct value_member { T operator()(V &v) { return &v.imagearray; } }; template struct cast_value { T operator()(V &value) { switch (value.type) { case bool_type: return static_cast(value.b); case long_type: return static_cast(value.l); case float_type: return static_cast(value.f); case double_type: return static_cast(value.d); default: return static_cast(0); } } }; // Specialization for bool template struct cast_value { bool operator()(V &value) { switch (value.type) { case bool_type: return value.b != 0; case long_type: return value.l != 0; case float_type: return value.f != 0.0f; case double_type: return value.d != 0.0; default: return false; } } }; _NAVLIB_END // namespace navlib #endif /* NAVLIB_TEMPLATES_H_INCLUDED_ */