From 867a8733cf470227e97af9c2827a609bad60cfe8 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 7 Oct 2011 14:15:06 +0000 Subject: [PATCH 2/5] * replace some assertion by static_assertion * refactoring of Combinatorial_map_utility.h => move all novariadic struct in Combinatorial_map_utility_novariadic. The file can now be read easier. --- .gitattributes | 1 + .../internal/Combinatorial_map_functors.h | 16 +- .../CGAL/internal/Combinatorial_map_utility.h | 1804 ++++------------- .../Combinatorial_map_utility_novariadic.h | 1641 +++++++++++++++ 4 files changed, 1991 insertions(+), 1471 deletions(-) create mode 100644 Combinatorial_map/include/CGAL/internal/Combinatorial_map_utility_novariadic.h diff --git a/.gitattributes b/.gitattributes index c0ef5aa9cc1..c38d0b4c5c1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1394,6 +1394,7 @@ Combinatorial_map/include/CGAL/Dart_const_iterators.h -text Combinatorial_map/include/CGAL/Dart_iterators.h -text Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h -text Combinatorial_map/include/CGAL/internal/Combinatorial_map_utility.h -text +Combinatorial_map/include/CGAL/internal/Combinatorial_map_utility_novariadic.h -text Combinatorial_map/package_info/Combinatorial_map/description.txt -text Combinatorial_map/package_info/Combinatorial_map/long_description.txt -text Combinatorial_map/package_info/Combinatorial_map/maintainer -text diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h index f7fed3e586d..a2479370ca0 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h @@ -51,7 +51,7 @@ namespace CGAL { typename Map::Dart_const_handle adart1, typename Map::Dart_const_handle adart2) { - CGAL_assertion(2<=i && i<=Map::dimension); + CGAL_static_assertion(2<=i && i<=Map::dimension); CGAL_assertion(adart1!=NULL && adart2!=NULL); if ( !adart1->is_free(i) || !adart2->is_free(i) || adart1==adart2 ) @@ -144,7 +144,7 @@ namespace CGAL { static void run(Map& amap,typename Map::Dart_handle adart1, typename Map::Dart_handle adart2) { - CGAL_assertion(2<=i && i<=Map::dimension); + CGAL_static_assertion(2<=i && i<=Map::dimension); CGAL_assertion( (is_sewable_functor::run(amap,adart1,adart2)) ); CMap_dart_iterator_of_involution I1(amap, adart1); @@ -205,7 +205,7 @@ namespace CGAL { static void run(Map& amap,typename Map::Dart_handle adart1, typename Map::Dart_handle adart2) { - CGAL_assertion(2<=i && i<=Map::dimension); + CGAL_static_assertion(2<=i && i<=Map::dimension); CGAL_assertion( (is_sewable_functor::run(amap,adart1,adart2)) ); CMap_dart_iterator_of_involution I1(amap, adart1); @@ -312,7 +312,7 @@ namespace CGAL { static void run(Map& amap,typename Map::Dart_handle adart) { CGAL_assertion( adart!=NULL && !adart->is_free(i) ); - CGAL_assertion(2<=i && i<=Map::dimension); + CGAL_static_assertion(2<=i && i<=Map::dimension); CMap_dart_iterator_of_involution it(amap, adart); while ( it.cont() ) @@ -372,7 +372,7 @@ namespace CGAL { struct unsew_functor{ static void run(Map& amap,typename Map::Dart_handle adart) { - CGAL_assertion(2<=i && i<=Map::dimension); + CGAL_static_assertion(2<=i && i<=Map::dimension); CGAL_assertion( adart!=NULL && !adart->is_free(i) ); std::stack > todegroup; @@ -478,7 +478,7 @@ namespace CGAL { typename Map::Dart_handle adart2) { CGAL_assertion(adart1 != NULL && adart2 != NULL && adart1!=adart2); - CGAL_assertion( i>=2 && i<=Map::dimension ); + CGAL_static_assertion( i>=2 && i<=Map::dimension ); adart1->basic_link_beta(adart2, i); adart2->basic_link_beta(adart1, i); } @@ -514,7 +514,7 @@ namespace CGAL { static void run(Map&,typename Map::Dart_handle adart) { CGAL_assertion(adart != NULL && !adart->is_free(i)); - CGAL_assertion(2<=i && i<=Map::dimension); + CGAL_static_assertion(2<=i && i<=Map::dimension); adart->beta(i)->unlink_beta(i); adart->unlink_beta(i); } @@ -889,7 +889,7 @@ namespace CGAL { typename CMap::Dart_handle adart2) { CGAL_assertion(adart1 != NULL && adart2 != NULL && adart1!=adart2 ); - CGAL_assertion( 2<=i && i<=CMap::dimension ); + CGAL_static_assertion( 2<=i && i<=CMap::dimension ); adart1->basic_link_beta(adart2, i); adart2->basic_link_beta(adart1, i); CMap::Helper::template Foreach_enabled_attributes diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_utility.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_utility.h index 1a4eae9c65c..0ad3d6a80ea 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_utility.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_utility.h @@ -23,1439 +23,299 @@ #include #include #include -#include - -#ifdef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES -#include -#include -#endif - namespace CGAL { - // struct Disabled {}; // If we want to use CGAL::Disabled for disabled attributes - // typedef CGAL::Void Disabled; - // typedef void Disabled; // If we wand to use void, does not compile on windows - namespace internal { - // There is a problem on windows to handle tuple containing void. To solve this, we - // transform such a tuple in tuple containing Disabled. - template - struct Convert_void - { typedef T type; }; - - template<> - struct Convert_void - { typedef CGAL::Void type; }; - - #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES - template - struct Convert_tuple_with_void; + // There is a problem on windows to handle tuple containing void. + // To solve this, we transform such a tuple in tuple containing Disabled. + template + struct Convert_void + { typedef T type; }; - template - struct Convert_tuple_with_void > - { - typedef CGAL::cpp0x::tuple::type... > type; - }; - - template - struct My_length; - template - struct My_length > - { - static const int value = My_length >::value + 1; - }; - - template<> - struct My_length > - { - static const int value = 0; - }; - - -#else //CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES - template - struct Convert_tuple_with_void; - - template <> - struct Convert_tuple_with_void > - { - typedef CGAL::cpp0x::tuple<> type; - }; - template - struct Convert_tuple_with_void > - { - typedef CGAL::cpp0x::tuple::type > type; - }; - template - struct Convert_tuple_with_void > - { - typedef CGAL::cpp0x::tuple::type, - typename Convert_void::type> type; - }; - template - struct Convert_tuple_with_void > - { - typedef CGAL::cpp0x::tuple::type, - typename Convert_void::type, - typename Convert_void::type> type; - }; - template - struct Convert_tuple_with_void > - { - typedef CGAL::cpp0x::tuple::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type> type; - }; - template - struct Convert_tuple_with_void > - { - typedef CGAL::cpp0x::tuple::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type> type; - }; - template - struct Convert_tuple_with_void > - { - typedef CGAL::cpp0x::tuple::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type> type; - }; - template - struct Convert_tuple_with_void > - { - typedef CGAL::cpp0x::tuple::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type> type; - }; - template - struct Convert_tuple_with_void > - { - typedef CGAL::cpp0x::tuple::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type> type; - }; - template - struct Convert_tuple_with_void > - { - typedef CGAL::cpp0x::tuple::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type, - typename Convert_void::type> type; - }; - template - struct My_length; - - template <> - struct My_length > - { - static const int value = 0; - }; - template - struct My_length > - { - static const int value = 1; - }; - template - struct My_length > - { - static const int value = 2; - }; - template - struct My_length > - { - static const int value = 3; - }; - template - struct My_length > - { - static const int value = 4; - }; - template - struct My_length > - { - static const int value = 5; - }; - template - struct My_length > - { - static const int value = 6; - }; - template - struct My_length > - { - static const int value = 7; - }; - template - struct My_length > - { - static const int value = 8; - }; - template - struct My_length > - { - static const int value = 9; - }; -#endif //CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES + template<> + struct Convert_void + { typedef CGAL::Void type; }; #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES -//count the number of time a given type is present in a tuple -template -struct Number_of_type_in_tuple; - -template -struct Number_of_type_in_tuple >{ - static const int value=Number_of_type_in_tuple >::value+1; -}; + // Convert a tuple in a same tuple where each void type was replaced into + // CGAL::Void. + template + struct Convert_tuple_with_void; + template + struct Convert_tuple_with_void > + { + typedef CGAL::cpp0x::tuple::type... > type; + }; -template -struct Number_of_type_in_tuple >{ - static const int value=Number_of_type_in_tuple >::value; -}; + // Length of a variadic template + template + struct My_length; + template + struct My_length > + { + static const int value = My_length >::value + 1; + }; + template<> + struct My_length > + { + static const int value = 0; + }; -template -struct Number_of_type_in_tuple >{ - static const int value=0; -}; -#endif //CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES + //count the number of time a given type is present in a tuple + template + struct Number_of_type_in_tuple; + template + struct Number_of_type_in_tuple >{ + static const int value=Number_of_type_in_tuple + >::value+1; + }; + template + struct Number_of_type_in_tuple >{ + static const int value=Number_of_type_in_tuple + >::value; + }; + template + struct Number_of_type_in_tuple >{ + static const int value=0; + }; -//count the number of different types from Type is present in a tuple -#ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES -template -struct Number_of_different_type_in_tuple; - -template -struct Number_of_different_type_in_tuple > -{ - static const int value=Number_of_different_type_in_tuple >::value+1; -}; + //count the number of different types from Type is present in a tuple + template + struct Number_of_different_type_in_tuple; + template + struct Number_of_different_type_in_tuple > + { + static const int value=Number_of_different_type_in_tuple + >::value+1; + }; + template + struct Number_of_different_type_in_tuple > + { + static const int value=Number_of_different_type_in_tuple + >::value; + }; + template + struct Number_of_different_type_in_tuple > + { + static const int value=0; + }; -template -struct Number_of_different_type_in_tuple > -{ - static const int value=Number_of_different_type_in_tuple >::value; -}; + //count the number of time a given type have been found + //within a tuple, until reaching position the k'th type of the tuple. + //dim is the total size of the tuple + template ::value-1> + struct Nb_type_in_tuple_up_to_k; + + template + struct Nb_type_in_tuple_up_to_k,dim> + { + static const int pos= Nb_type_in_tuple_up_to_k + ,dim>::pos - 1; + + static const int value = + ( pos==k ) ? ( boost::is_same::value ? 0:-dim-1 ) + : ( ( pos::value ? 1:0 ) + + Nb_type_in_tuple_up_to_k + ,dim >::value) + :0 + ); + }; + + template + struct Nb_type_in_tuple_up_to_k,dim > + { + static const int pos=dim; + static const int value=(pos==k? + (boost::is_same::value?0:-dim-1) : + 0); + }; -template -struct Number_of_different_type_in_tuple > -{ - static const int value=0; -}; + //count the number of time a type different from Type have been found + //within a tuple, until reaching position the k'th type of the tuple. + //dim is the total size of the tuple + template ::value-1> + struct Nb_type_different_in_tuple_up_to_k; + + template + struct Nb_type_different_in_tuple_up_to_k,dim> + { + static const int pos = Nb_type_different_in_tuple_up_to_k + ,dim >::pos - 1; + + static const int value = + ( pos==k ) ? ( boost::is_same::value ? -dim-1 : 0 ) + : ( ( pos::value ? 0:1 ) + + Nb_type_different_in_tuple_up_to_k + ,dim >::value) + :0 + ); + }; + + template + struct Nb_type_different_in_tuple_up_to_k,dim > + { + static const int pos=dim; + static const int value=(pos==k? + (boost::is_same::value?-dim-1:0) : + 0); + }; + + //Convert a tuple of T... to a tuple of Functor::type... + template