Commit aaf4fcc6 authored by Paul's avatar Paul
Browse files

Remove the any_type

parent 83b91229
......@@ -89,13 +89,27 @@ struct raw_data : raw_data_base
assert(self->single());
return self->template at<T>();
}
template<class T>
using is_data_ptr = bool_c<(std::is_void<T>{} or std::is_same<char, std::remove_cv_t<T>>{} or std::is_same<unsigned char, std::remove_cv_t<T>>{})>;
template<class T>
using get_data_type = std::conditional_t<is_data_ptr<T>{},
float,
T
>;
template<class T>
bool matches() const
{
return is_data_ptr<T>{} || self->get_shape().type() == rtg::shape::get_type<get_data_type<T>>{};
}
template <class T>
operator T*()
{
using type = std::remove_cv_t<T>;
assert((std::is_void<T>{} or std::is_same<char, type>{} or
std::is_same<unsigned char, type>{} or
self->get_shape().type() == rtg::shape::get_type<T>{}));
assert(matches<T>());
return reinterpret_cast<type*>(self->data());
}
};
......
......@@ -10,10 +10,13 @@ struct and_ : std::is_same<and_<Bs...>, and_<(Bs || true)...>> // NOLINT
{
};
template<bool B>
using bool_c = std::integral_constant<bool, B>;
#ifdef CPPCHECK
#define RTG_REQUIRES(...) class = void
#else
#define RTG_REQUIRES(...) class = typename std::enable_if<and_<__VA_ARGS__, true>{}>::type
#define RTG_REQUIRES(...) bool PrivateRequires ## __LINE__ = true, class = typename std::enable_if<and_<__VA_ARGS__, PrivateRequires ## __LINE__>{}>::type
#endif
} // namespace rtg
......
......@@ -31,15 +31,12 @@ struct shape
#define RTG_SHAPE_ENUM_TYPES(x, t) x,
enum type_t
{
any_type,
RTG_SHAPE_VISIT_TYPES(RTG_SHAPE_ENUM_TYPES)
};
#undef RTG_SHAPE_ENUM_TYPES
template <class T, class = void>
struct get_type : std::integral_constant<type_t, any_type>
{
};
struct get_type;
#define RTG_SHAPE_GET_TYPE(x, t) \
template <class T> \
struct get_type<t, T> : std::integral_constant<type_t, x> \
......@@ -125,7 +122,6 @@ struct shape
{
switch(this->m_type)
{
case any_type: RTG_THROW("Cannot visit the any_type");
#define RTG_SHAPE_VISITOR_CASE(x, t) \
case x: v(as<t>()); return;
RTG_SHAPE_VISIT_TYPES(RTG_SHAPE_VISITOR_CASE)
......
......@@ -109,7 +109,6 @@ std::string shape::type_string() const
{
switch(this->m_type)
{
case any_type: return "any";
#define RTG_SHAPE_TYPE_STRING_CASE(x, t) \
case x: return #x;
RTG_SHAPE_VISIT_TYPES(RTG_SHAPE_TYPE_STRING_CASE)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment