More wrapper ugliness

This commit is contained in:
Marc Glisse 2011-05-13 20:23:19 +00:00
parent a873c26099
commit 7a58fd43b4
6 changed files with 124 additions and 6 deletions

View File

@ -2,11 +2,67 @@
#define CGAL_KERNEL_D_CARTESIAN_WRAP_H
#include <CGAL/basic.h>
#include <CGAL/is_iterator.h>
#include <CGAL/Kernel_d/Wrapper/Point_d.h>
#include <CGAL/Kernel_d/Wrapper/Vector_d.h>
#include <CGAL/Kernel_d/Wrapper/Segment_d.h>
#include <boost/mpl/or.hpp>
namespace CGAL {
namespace internal {
BOOST_MPL_HAS_XXX_TRAIT_DEF(Is_wrapper)
template<class T,bool=has_Is_wrapper<T>::value> struct Is_wrapper {
enum { value=false };
typedef Tag_false type;
};
template<class T> struct Is_wrapper<T,true> {
typedef typename T::Is_wrapper type;
enum { value=type::value };
};
template<class T,bool=is_iterator<T>::value> struct Is_wrapper_iterator {
enum { value=false };
typedef Tag_false type;
};
template<class T> struct Is_wrapper_iterator<T,true> :
Is_wrapper<typename std::iterator_traits<T>::value_type>
{ };
struct Forward_rep {
//TODO: make a good C++0X version with perfect forwarding
//#ifdef CGAL_CXX0X
//template <class T,class=typename std::enable_if<!Is_wrapper<typename std::decay<T>::type>::value&&!Is_wrapper_iterator<typename std::decay<T>::type>::value>::type>
//T&& operator()(typename std::remove_reference<T>::type&& t) const {return static_cast<T&&>(t);};
//template <class T,class=typename std::enable_if<!Is_wrapper<typename std::decay<T>::type>::value&&!Is_wrapper_iterator<typename std::decay<T>::type>::value>::type>
//T&& operator()(typename std::remove_reference<T>::type& t) const {return static_cast<T&&>(t);};
//
//template <class T,class=typename std::enable_if<Is_wrapper<typename std::decay<T>::type>::value>::type>
//typename Type_copy_cvref<T,typename std::decay<T>::type::Rep>::type&&
//operator()(T&& t) const {
// return static_cast<typename Type_copy_cvref<T,typename std::decay<T>::type::Rep>::type&&>(t.rep());
//};
//
//template <class T,class=typename std::enable_if<Is_wrapper_iterator<typename std::decay<T>::type>::value>::type>
//transforming_iterator<Forward_rep,typename std::decay<T>::type>
//operator()(T&& t) const {
// return make_transforming_iterator(std::forward<T>(t),Forward_rep());
//};
//#else
template <class T,bool=Is_wrapper<T>::value,bool=Is_wrapper_iterator<T>::value> struct result_;
template <class T> struct result_<T,false,false>{typedef T type;};
template <class T> struct result_<T,true,false>{typedef typename decay<T>::type::Rep type;};
template <class T> struct result_<T,false,true>{typedef transforming_iterator<Forward_rep,typename decay<T>::type> type;};
template<class> struct result;
template<class T> struct result<Forward_rep(T)> : result_<T> {};
template <class T> typename boost::disable_if<boost::mpl::or_<Is_wrapper<T>,Is_wrapper_iterator<T> >,T>::type const& operator()(T const& t) const {return t;}
template <class T> typename boost::enable_if<Is_wrapper<T>,T>::type::Rep const& operator()(T const& t) const {return t.rep();}
template <class T> transforming_iterator<Forward_rep,typename boost::enable_if<Is_wrapper_iterator<T>,T>::type> operator()(T const& t) const {return make_transforming_iterator(t,Forward_rep());}
//#endif
};
}
template < typename Base_ >
struct Cartesian_wrap : public Base_
@ -21,8 +77,6 @@ struct Cartesian_wrap : public Base_
template<bool b> struct map_type<X##_tag,b> { typedef X type; };
#include <CGAL/Kernel_d/interface_macros.h>
//TODO: adapt all functors
//TODO: safely apply .rep() to the arguments (and transforming_iterator)
template<class T,int i=0> struct Construct {
typedef typename Kernel_base::template Construct<T>::type B;
struct type {
@ -30,23 +84,71 @@ struct Cartesian_wrap : public Base_
typedef typename map_kernel_obj<Self,result_tag>::type result_type;
#ifdef CGAL_CXX0X
template<class...U> result_type operator()(U&&...u)const{
return result_type(Eval_functor(),B(),std::forward<U>(u)...);
return result_type(Eval_functor(),B(),internal::Forward_rep()(u)...);
}
#else
#define VAR(Z,N,_) internal::Forward_rep()(u##N)
#define CODE(Z,N,_) template<BOOST_PP_ENUM_PARAMS(N,class U)> result_type \
operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,U,const&u))const{ \
return result_type(Eval_functor(),B(),BOOST_PP_ENUM_PARAMS(N,u)); \
return result_type(Eval_functor(),B(),BOOST_PP_ENUM(N,VAR,)); \
}
BOOST_PP_REPEAT_FROM_TO(1,11,CODE,_)
#undef CODE
#undef VAR
#endif
};
};
//TODO: adapt all functors
//TODO: safely apply .rep() to the arguments (and transforming_iterator)
//FIXME: looks like only those 2 are missing
template<int i> struct Construct<Construct_point_cartesian_const_iterator_tag,i> {
typedef typename Kernel_base::template Construct<Construct_point_cartesian_const_iterator_tag>::type type;
};
template<int i> struct Construct<Construct_vector_cartesian_const_iterator_tag,i> {
typedef typename Kernel_base::template Construct<Construct_vector_cartesian_const_iterator_tag>::type type;
};
template<class T,int i=0> struct Predicate {
typedef typename Kernel_base::template Predicate<T>::type B;
struct type {
typedef typename B::result_type result_type;
#ifdef CGAL_CXX0X
template<class...U> result_type operator()(U&&...u)const{
return B()(internal::Forward_rep()(u)...);
}
#else
#define VAR(Z,N,_) internal::Forward_rep()(u##N)
#define CODE(Z,N,_) template<BOOST_PP_ENUM_PARAMS(N,class U)> result_type \
operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,U,const&u))const{ \
return B()(BOOST_PP_ENUM(N,VAR,)); \
}
BOOST_PP_REPEAT_FROM_TO(1,11,CODE,_)
#undef CODE
#undef VAR
#endif
};
};
template<class T,int i=0> struct Compute {
typedef typename Kernel_base::template Compute<T>::type B;
struct type {
typedef typename B::result_type result_type;
#ifdef CGAL_CXX0X
template<class...U> result_type operator()(U&&...u)const{
return B()(internal::Forward_rep()(u)...);
}
#else
#define VAR(Z,N,_) internal::Forward_rep()(u##N)
#define CODE(Z,N,_) template<BOOST_PP_ENUM_PARAMS(N,class U)> result_type \
operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,U,const&u))const{ \
return B()(BOOST_PP_ENUM(N,VAR,)); \
}
BOOST_PP_REPEAT_FROM_TO(1,11,CODE,_)
#undef CODE
#undef VAR
#endif
};
};
};
} //namespace CGAL

View File

@ -30,6 +30,7 @@ class Point_d : public R_::Kernel_base::Point
public:
typedef Tag_true Is_wrapper;
typedef typename R_::Default_ambient_dimension Ambient_dimension;
typedef Dimension_tag<0> Feature_dimension;

View File

@ -31,6 +31,7 @@ class Segment_d : public R_::Kernel_base::Segment
public:
typedef Tag_true Is_wrapper;
typedef typename R_::Default_ambient_dimension Ambient_dimension;
typedef Dimension_tag<1> Feature_dimension;

View File

@ -30,6 +30,7 @@ class Vector_d : public R_::Kernel_base::Vector
public:
typedef Tag_true Is_wrapper;
typedef typename R_::Default_ambient_dimension Ambient_dimension;
typedef Dimension_tag<0> Feature_dimension;

View File

@ -129,6 +129,19 @@ namespace CGAL {
#else
template<class T> struct decay : boost::remove_cv<typename boost::decay<T>::type> {};
#endif
template<class T,class U> struct Type_copy_ref { typedef U type; };
template<class T,class U> struct Type_copy_ref<T&,U> { typedef U& type; };
#ifdef CGAL_CXX0X
template<class T,class U> struct Type_copy_ref<T&&,U> { typedef U&& type; };
#endif
template<class T,class U> struct Type_copy_cv { typedef U type; };
template<class T,class U> struct Type_copy_cv<T const,U> { typedef U const type; };
template<class T,class U> struct Type_copy_cv<T volatile,U> { typedef U volatile type; };
template<class T,class U> struct Type_copy_cv<T const volatile,U> { typedef U const volatile type; };
template<class T,class U> struct Type_copy_cvref :
Type_copy_ref<T,typename Type_copy_cv<typename boost::remove_reference<T>::type,U>::type> {};
}
#endif

View File

@ -15,12 +15,12 @@ typedef CGAL::Cartesian_base_d<CGAL::Gmpq,CGAL::Dimension_tag<2> > KE;
typedef K0 K2;
#elif 0
typedef CGAL::Cartesian_filter_NT<K0> K2;
#elif 1
#elif 0
typedef CGAL::Cartesian_filter_K<K0,KA,KE> K2;
#elif 1
struct K2: CGAL::Lazy_cartesian<KE,KA,CGAL::CartesianD_converter<KE,KA>,K2>{};
#endif
#if 1
#if 0
typedef K2 K1;
#elif 1
typedef CGAL::Cartesian_wrap<K2> K1;