diff --git a/Combinatorial_map/include/CGAL/Cell_attribute.h b/Combinatorial_map/include/CGAL/Cell_attribute.h index c5cc9875eed..da22eb1e72d 100644 --- a/Combinatorial_map/include/CGAL/Cell_attribute.h +++ b/Combinatorial_map/include/CGAL/Cell_attribute.h @@ -119,6 +119,12 @@ namespace CGAL { bool is_valid() const { return true; } + bool operator==(const Cell_attribute_without_info&) const + { return true; } + + bool operator!=(const Cell_attribute_without_info& other) const + { return !operator==(other); } + protected: /// Contructor without parameter. Cell_attribute_without_info(): mrefcounting(0) @@ -221,6 +227,12 @@ namespace CGAL { bool is_valid() const { return mdart!=NULL; } + bool operator==(const Cell_attribute_without_info&) const + { return true; } + + bool operator!=(const Cell_attribute_without_info& other) const + { return !operator==(other); } + protected: /// Contructor without parameter. Cell_attribute_without_info() : mdart(NULL), @@ -326,6 +338,13 @@ namespace CGAL { typedef OnSplit On_split; typedef Info_ Info; + bool operator==(const Self& other) const + { return this->info()==other.info(); } + + bool operator!=(const Self& other) const + { return !operator==(other); } + + protected: /// Default contructor. Cell_attribute() diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h index 761c2eb53a9..a5458b8b207 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h @@ -191,12 +191,11 @@ struct Cast_converter_cmap_attributes (const Map1& map1, Map2& map2, typename Map1::Dart_const_handle dh1, typename Map2::Dart_handle dh2) const { + typename Map2::template Attribute_handle::type + res = map2.template create_attribute(); if ( dh1->template attribute()!=NULL ) - return map2.template create_attribute - ((typename Map2::template Attribute_type::type::Info) - dh1->template attribute()->info()); - - return map2.template create_attribute(); + res->info() = dh1->template attribute()->info(); + return res; } }; // **************************************************************************** diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h index 171c558fb28..3269b231ac5 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -22,6 +22,8 @@ #include #include +#include +#include #include /* Definition of functors used internally to manage attributes (we need @@ -457,7 +459,7 @@ struct Is_same_info // Case of two non void type template -struct Is_same_attribute_functor +struct Is_same_attribute_info_functor { static bool run(typename Map1::Dart_const_handle dh1, typename Map2::Dart_const_handle dh2) @@ -478,33 +480,177 @@ struct Is_same_attribute_functor // Case T1==void template -struct Is_same_attribute_functor + typename T2, int i> +struct Is_same_attribute_info_functor { static bool run(typename Map1::Dart_const_handle, typename Map2::Dart_const_handle dh2) - { return dh2->template attribute()==NULL; } + { + return dh2->template attribute()==NULL || + Is_same_info:: + run(0, *(dh2->template attribute())); + } }; // Case T2==void template -struct Is_same_attribute_functor +struct Is_same_attribute_info_functor { static bool run(typename Map1::Dart_const_handle dh1, typename Map2::Dart_const_handle) - { return dh1->template attribute()==NULL; } + { + return dh1->template attribute()==NULL || + Is_same_info:: + run(*(dh1->template attribute()), 0); + } }; // Case T1==T2==void template -struct Is_same_attribute_functor +struct Is_same_attribute_info_functor { static bool run(typename Map1::Dart_const_handle, typename Map2::Dart_const_handle) { return true; } }; +// **************************************************************************** +// Functor allowing to test if two points are the same or not. +// Here we know both attributes have points. +template< typename Attr1, typename Attr2, + typename Point1=typename Attr1::Point, + typename Point2=typename Attr2::Point, + typename T1=typename Ambient_dimension::type > +struct Is_same_point +{ + static bool run(const Attr1&, const Attr2&) + { return false; } +}; + +template< typename Attr1, typename Attr2, typename Point> +struct Is_same_point > +{ + static bool run(const Attr1& a1, const Attr2& a2) + { return typename Kernel_traits::Kernel::Equal_2() + (a1.point(),a2.point()); } +}; + +template< typename Attr1, typename Attr2, typename Point> +struct Is_same_point > +{ + static bool run(const Attr1& a1, const Attr2& a2) + { return typename Kernel_traits::Kernel::Equal_3() + (a1.point(),a2.point()); } +}; + +template< typename Attr1, typename Attr2, typename Point> +struct Is_same_point +{ + static bool run(const Attr1& a1, const Attr2& a2) + { return typename Kernel_traits::Kernel::Equal_d() + (a1.point(),a2.point()); } +}; + +// Case of two non void type, with two points +template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle dh1, + typename Map2::Dart_const_handle dh2) + { + CGAL_static_assertion( Withpoint1==true && Withpoint2==true ); + if (dh1->template attribute()==NULL && + dh2->template attribute()==NULL) + return true; + + if (dh1->template attribute()==NULL || + dh2->template attribute()==NULL) + return false; + + return + Is_same_point::run(*(dh1->template attribute()), + *(dh2->template attribute())); + } +}; + +// Case of two non void type, first without point +template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle, + typename Map2::Dart_const_handle) + { return false; } +}; + +// Case of two non void type, second without point +template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle, + typename Map2::Dart_const_handle) + { return false; } +}; + +// Case of two non void type, both without point +template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle, + typename Map2::Dart_const_handle) + { return true; } +}; + +// Case T1==void +/*template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle, + typename Map2::Dart_const_handle dh2) + { + return dh2->template attribute()==NULL || + Withpoint2==false; + } +}; + +// Case T2==void +template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle dh1, + typename Map2::Dart_const_handle) + { + return dh1->template attribute()==NULL || + Withpoint1==false; + } +}; + +// Case T1==T2==void +template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle, + typename Map2::Dart_const_handle) + { return true; } +};*/ + +struct twochar{ char dummy[2]; }; + +template +static char has_point(typename T::Point*){} + +template +static twochar has_point(...){} + /// Test if the two darts are associated with the same attribute. template struct Test_is_same_attribute_functor @@ -514,11 +660,23 @@ struct Test_is_same_attribute_functor typename Map2::Dart_const_handle dh2 ) { if (value) - value = Is_same_attribute_functor + { + value = Is_same_attribute_info_functor ::type, - typename Map2::Helper::template Attribute_type::type, + typename Map1::template Attribute_type::type, + typename Map2::template Attribute_type::type, i>::run(dh1, dh2); + } + if (value) + { + value = Is_same_attribute_point_functor + ::type, + typename Map2::template Attribute_type::type, + sizeof(has_point::type>(NULL))==sizeof(char), + sizeof(has_point::type>(NULL))==sizeof(char), + i>::run(dh1, dh2); + } } static bool value; }; diff --git a/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h b/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h index 11a8b21af6d..0c91de8f00b 100644 --- a/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h +++ b/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h @@ -88,6 +88,12 @@ namespace CGAL { using Base1::info; + bool operator==(const Self& other) const + { return Base1::operator==(other) && this->point()==other.point(); } + + bool operator!=(const Self& other) const + { return !operator==(other); } + protected: /// Default contructor. Cell_attribute_with_point() @@ -132,6 +138,16 @@ namespace CGAL { typedef Functor_on_merge_ Functor_on_merge; typedef Functor_on_split_ Functor_on_split; + bool operator==(const Cell_attribute_with_point& other) const + { return Base1::operator==(other) && this->point()==other.point(); } + + bool operator!=(const Cell_attribute_with_point& other) const + { return !operator==(other); } + + template + bool operator==(const Cellattr& other) const + { return false; } + protected: /// Default contructor. Cell_attribute_with_point() diff --git a/Linear_cell_complex/include/CGAL/internal/Linear_cell_complex_copy_functors.h b/Linear_cell_complex/include/CGAL/internal/Linear_cell_complex_copy_functors.h index baa6aa0a859..2ac33a76ceb 100644 --- a/Linear_cell_complex/include/CGAL/internal/Linear_cell_complex_copy_functors.h +++ b/Linear_cell_complex/include/CGAL/internal/Linear_cell_complex_copy_functors.h @@ -91,8 +91,7 @@ struct Set_point_if_possible::run(p1, p2); + Set_point_d_if_same::run(p1, p2); } }; @@ -123,15 +122,13 @@ struct Set_point_if_exist }; // **************************************************************************** #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES -template > +template struct Modify_tuple_of_converter_for_vertex_attribute; -// empty tuple and empty res: res is a tuple with only -// Point_converter_lcc_vertex_attributes +// empty tuple template struct Modify_tuple_of_converter_for_vertex_attribute - , CGAL::cpp11::tuple<> > + > { typedef CGAL::cpp11::tuple -struct Modify_tuple_of_converter_for_vertex_attribute - , CGAL::cpp11::tuple > -{ - typedef CGAL::cpp11::tuple type; - - static type run(const CGAL::cpp11::tuple<>&) - { CGAL_assertion(false); return type(); } -}; - -// empty res but non empty empty tuple, Firsttype is vertex attribute. +// non empty empty tuple, Firsttype is vertex attribute. template < typename LCC1, typename LCC2, class Firsttype, class ... Tuple > struct Modify_tuple_of_converter_for_vertex_attribute - , CGAL::cpp11::tuple<> > + > { - typedef typename Modify_tuple_of_converter_for_vertex_attribute - , - CGAL::cpp11::tuple - >:: - type type; + typedef typename CGAL::cpp11::tuple + , + Tuple...> type; static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + Tuple... >(t.get_head(),t.get_tail()); } }; - -// non empty res, non empty tuple, we copy -template < typename LCC1, typename LCC2, class Firsttype, - class ... Tuple, class ... Res > -struct Modify_tuple_of_converter_for_vertex_attribute - , - CGAL::cpp11::tuple > -{ - typedef typename Modify_tuple_of_converter_for_vertex_attribute - , - CGAL::cpp11::tuple >::type type; - - static type run(const CGAL::cpp11::tuple<>&) - { CGAL_assertion(false); return type; } -}; #else // CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES template struct Modify_tuple_of_converter_for_vertex_attribute; @@ -200,9 +168,10 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple<>&) { CGAL::Default_converter_cmap_attributes tmp; - return type(Modify_attribute_converter_lcc_vertex_attributes - , LCC1, LCC2> - (tmp)); + return CGAL::cpp11::tuple + , LCC1, LCC2> > + (tmp); } }; @@ -214,10 +183,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple<> >(t.get_head(),t.get_tail()); } }; @@ -229,10 +197,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -245,10 +212,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -261,10 +227,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -278,10 +243,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -295,10 +259,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -312,10 +275,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -329,10 +291,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -346,10 +307,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; #endif diff --git a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp index 8e27dee37c3..0c18c542a80 100644 --- a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp +++ b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp @@ -17,7 +17,7 @@ struct Map_2_dart_items typedef CGAL::Dart< 2, Refs > Dart; typedef CGAL::Cell_attribute< Refs, int > Int_attrib; - typedef CGAL::Cell_attribute< Refs, int > Double_attrib; + typedef CGAL::Cell_attribute< Refs, double > Double_attrib; typedef CGAL::Cell_attribute_with_point< Refs, double > Double_attrib_wp; typedef CGAL::cpp11::tuple Attributes; @@ -562,19 +562,65 @@ bool testCopy() map2a.number_of_attributes<2>()==0 && map2a.number_of_attributes<3>()==0 ); assert( map2a.is_isomorphic_to(map2)==map2.is_isomorphic_to(map2a) ); - //map2.display_characteristics(std::cout)<()==map2.number_of_attributes<0>() && map5a.number_of_attributes<2>()==0 ); - //map5.display_characteristics(std::cout)<()>=map9.number_of_attributes<0>() && + map9a.number_of_attributes<2>()>=map9.number_of_attributes<2>() && + map9a.number_of_attributes<3>()==0 ); + assert( map9a.is_isomorphic_to(map9)==map9.is_isomorphic_to(map9a) ); + + CGAL::Cast_converter_cmap_attributes c0; + CGAL::Default_converter_cmap_attributes c1; + CGAL::Default_converter_cmap_attributes c2; + CGAL::Cast_converter_cmap_attributes c3; + + CGAL::cpp11::tuple, + CGAL::Default_converter_cmap_attributes, + CGAL::Default_converter_cmap_attributes, + CGAL::Cast_converter_cmap_attributes > myconverters + (c0, c1, c2, c3); + + Map5 map9b(map9, myconverters); assert(map9a.is_valid()); + if ( map9b.is_isomorphic_to(map9) ) { assert(false); return false; } + assert( map9b.number_of_attributes<0>()>=map9.number_of_attributes<0>() && + map9b.number_of_attributes<2>()>=map9.number_of_attributes<2>() && + map9b.number_of_attributes<3>()>=map9.number_of_attributes<3>() ); + assert( map9b.is_isomorphic_to(map9)==map9.is_isomorphic_to(map9b) ); + + CGAL::Cast_converter_cmap_attributes cb0; + CGAL::Default_converter_cmap_attributes cb1; + CGAL::Default_converter_cmap_attributes cb2; + CGAL::Cast_converter_cmap_attributes cb3; + + CGAL::cpp11::tuple, + CGAL::Default_converter_cmap_attributes, + CGAL::Default_converter_cmap_attributes, + CGAL::Cast_converter_cmap_attributes > myconverters2 + (cb0, cb1, cb2, cb3); + + Map9 map5b(map5, myconverters2); assert(map5b.is_valid()); + if ( map5b.is_isomorphic_to(map5) ) { assert(false); return false; } + if ( !map5b.is_isomorphic_to(map5, false) ) { assert(false); return false; } + assert( map5b.number_of_attributes<0>()==map5.number_of_attributes<0>() && + map5b.number_of_attributes<2>()==map5.number_of_attributes<2>() && + map5b.number_of_attributes<3>()==map5.number_of_attributes<3>() ); + assert( map5b.is_isomorphic_to(map5)==map5.is_isomorphic_to(map5b) ); } - // displayAllAttribs2D(mapXX, "mapXX******************\n"); - // displayAllAttribs2D(mapYY, "mapYY******************\n"); + /*map2.display_characteristics(std::cout)<