rotgen/include/rotgen/container/ref/generalize.hpp
Jules Pénuchot e151e136d6 Resolve "[API-#2] Pseudo-privatization of rotgen entity member functions"
Closes #18

Co-authored-by: Jules Pénuchot <jules@penuchot.com>

See merge request oss/rotgen!50
2025-12-17 20:48:00 +01:00

83 lines
2.2 KiB
C++

//==============================================================================
/*
ROTGEN - Runtime Overlay for Eigen
Copyright : CODE RECKONS
SPDX-License-Identifier: BSL-1.0
*/
//==============================================================================
#pragma once
#include <rotgen/concepts.hpp>
#include <rotgen/config.hpp>
#include <rotgen/container/matrix.hpp>
#include <rotgen/container/ref.hpp>
#include <type_traits>
namespace rotgen
{
template<typename Scalar, int Options = AutoAlign> class quaternion;
//----------------------------------------------------------------------------
// Convert entity/eigen types to a proper ref so we can write less function
// overloads
template<typename T> struct generalize;
template<typename T>
requires(std::is_arithmetic_v<std::remove_cvref_t<T>>)
struct generalize<T>
{
using type = std::remove_cvref_t<T>;
};
template<typename T> using generalize_t = typename generalize<T>::type;
template<concepts::entity T> struct generalize<T>
{
static constexpr bool is_const =
std::is_const_v<std::remove_reference_t<T>>;
using base = matrix<typename std::remove_cvref_t<T>::value_type,
std::remove_cvref_t<T>::RowsAtCompileTime,
std::remove_cvref_t<T>::ColsAtCompileTime,
std::remove_cvref_t<T>::storage_order>;
using type = std::conditional_t<is_const, ref<base const>, ref<base>>;
};
template<typename T, int O, typename S> struct generalize<ref<T, O, S>>
{
using type = ref<T, O, S>;
};
template<typename T, int O, typename S> struct generalize<ref<T, O, S> const>
{
using type = ref<T, O, S>;
};
template<typename T> struct generalize<quaternion<T>>
{
using type = quaternion<T>;
};
template<typename T> struct generalize<quaternion<T> const>
{
using type = quaternion<T>;
};
template<concepts::entity T> typename T::parent& base_of(T& a)
{
return a.base();
}
template<concepts::entity T> typename T::parent const& base_of(T const& a)
{
return a.base();
}
template<typename T>
T base_of(T a)
requires(std::is_arithmetic_v<T>)
{
return a;
}
}