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 ...@@ -89,13 +89,27 @@ struct raw_data : raw_data_base
assert(self->single()); assert(self->single());
return self->template at<T>(); 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> template <class T>
operator T*() operator T*()
{ {
using type = std::remove_cv_t<T>; using type = std::remove_cv_t<T>;
assert((std::is_void<T>{} or std::is_same<char, type>{} or assert(matches<T>());
std::is_same<unsigned char, type>{} or
self->get_shape().type() == rtg::shape::get_type<T>{}));
return reinterpret_cast<type*>(self->data()); return reinterpret_cast<type*>(self->data());
} }
}; };
......
...@@ -10,10 +10,13 @@ struct and_ : std::is_same<and_<Bs...>, and_<(Bs || true)...>> // NOLINT ...@@ -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 #ifdef CPPCHECK
#define RTG_REQUIRES(...) class = void #define RTG_REQUIRES(...) class = void
#else #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 #endif
} // namespace rtg } // namespace rtg
......
...@@ -31,15 +31,12 @@ struct shape ...@@ -31,15 +31,12 @@ struct shape
#define RTG_SHAPE_ENUM_TYPES(x, t) x, #define RTG_SHAPE_ENUM_TYPES(x, t) x,
enum type_t enum type_t
{ {
any_type,
RTG_SHAPE_VISIT_TYPES(RTG_SHAPE_ENUM_TYPES) RTG_SHAPE_VISIT_TYPES(RTG_SHAPE_ENUM_TYPES)
}; };
#undef RTG_SHAPE_ENUM_TYPES #undef RTG_SHAPE_ENUM_TYPES
template <class T, class = void> 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) \ #define RTG_SHAPE_GET_TYPE(x, t) \
template <class T> \ template <class T> \
struct get_type<t, T> : std::integral_constant<type_t, x> \ struct get_type<t, T> : std::integral_constant<type_t, x> \
...@@ -125,7 +122,6 @@ struct shape ...@@ -125,7 +122,6 @@ struct shape
{ {
switch(this->m_type) switch(this->m_type)
{ {
case any_type: RTG_THROW("Cannot visit the any_type");
#define RTG_SHAPE_VISITOR_CASE(x, t) \ #define RTG_SHAPE_VISITOR_CASE(x, t) \
case x: v(as<t>()); return; case x: v(as<t>()); return;
RTG_SHAPE_VISIT_TYPES(RTG_SHAPE_VISITOR_CASE) RTG_SHAPE_VISIT_TYPES(RTG_SHAPE_VISITOR_CASE)
......
...@@ -109,7 +109,6 @@ std::string shape::type_string() const ...@@ -109,7 +109,6 @@ std::string shape::type_string() const
{ {
switch(this->m_type) switch(this->m_type)
{ {
case any_type: return "any";
#define RTG_SHAPE_TYPE_STRING_CASE(x, t) \ #define RTG_SHAPE_TYPE_STRING_CASE(x, t) \
case x: return #x; case x: return #x;
RTG_SHAPE_VISIT_TYPES(RTG_SHAPE_TYPE_STRING_CASE) 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