From c4090eb218856b5d013a65f64e64e2b3843f026c Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 7 Apr 2022 17:13:06 +0200 Subject: [PATCH] Update --- .../map_3_dynamic_onmerge.cpp | 5 +- .../include/CGAL/Cell_attribute.h | 311 +----------------- .../include/CGAL/Cell_attribute_with_index.h | 304 +++++++++++++++++ .../include/CGAL/Combinatorial_map.h | 3 +- .../Combinatorial_map_internal_functors.h | 5 +- .../internal/Combinatorial_map_utility.h | 11 +- .../include/CGAL/Combinatorial_map_storages.h | 4 +- .../Combinatorial_map_storages_with_index.h | 235 +++++++------ .../CGAL/Compact_container_with_index_2.h | 8 + Combinatorial_map/include/CGAL/Dart.h | 174 +--------- .../include/CGAL/Dart_with_index.h | 206 ++++++++++++ .../include/CGAL/Info_for_cell_attribute.h | 46 +++ 12 files changed, 719 insertions(+), 593 deletions(-) create mode 100644 Combinatorial_map/include/CGAL/Cell_attribute_with_index.h create mode 100644 Combinatorial_map/include/CGAL/Dart_with_index.h create mode 100644 Combinatorial_map/include/CGAL/Info_for_cell_attribute.h diff --git a/Combinatorial_map/examples/Combinatorial_map/map_3_dynamic_onmerge.cpp b/Combinatorial_map/examples/Combinatorial_map/map_3_dynamic_onmerge.cpp index 147653f426b..18ebb1c952e 100644 --- a/Combinatorial_map/examples/Combinatorial_map/map_3_dynamic_onmerge.cpp +++ b/Combinatorial_map/examples/Combinatorial_map/map_3_dynamic_onmerge.cpp @@ -9,13 +9,14 @@ struct Myitem template struct Dart_wrapper { - typedef CGAL::Cell_attribute Face_attribute; // A weight + typedef CGAL::Index::Cell_attribute Face_attribute; // A weight typedef std::tuple Attributes; }; }; // Definition of my combinatorial map. -typedef CGAL::Combinatorial_map<3,Myitem> CMap_3; +//typedef CGAL::Combinatorial_map<3,Myitem> CMap_3; +typedef CGAL::Index::Combinatorial_map<3,Myitem> CMap_3; typedef CMap_3::Dart_handle Dart_handle; typedef CMap_3::Attribute_type<2>::type Face_attribute; diff --git a/Combinatorial_map/include/CGAL/Cell_attribute.h b/Combinatorial_map/include/CGAL/Cell_attribute.h index 46a852ad0fd..2876f9cb4e3 100644 --- a/Combinatorial_map/include/CGAL/Cell_attribute.h +++ b/Combinatorial_map/include/CGAL/Cell_attribute.h @@ -15,6 +15,8 @@ #include #include #include +#include +#include namespace CGAL { @@ -47,32 +49,6 @@ namespace CGAL { * Definition of cell attribute, with or without info. */ - /// Info associated with a cell_attribute. - template - class Info_for_cell_attribute - { - public: - /// Contructor without parameter. - Info_for_cell_attribute() - {} - - /// Contructor with an info in parameter. - Info_for_cell_attribute(const Info& ainfo) : minfo(ainfo) - {} - - /// Get the info associated with the cell_attribute. - Info& info() - { return minfo; } - - /// Get the info associated with the cell_attribute. - const Info& info() const - { return minfo; } - - protected: - /// The info associated with the cell_attribute. - Info minfo; - }; - /// Id associated with a cell attribute template class Add_id @@ -380,57 +356,6 @@ namespace CGAL { template friend class Generalized_map_storage_1; - template - friend class Compact_container; - - public: - typedef Cell_attribute Self; - - typedef Tag_ Supports_cell_dart; - typedef typename Refs::Dart_handle Dart_handle; - typedef typename Refs::Dart_const_handle Dart_const_handle; - typedef typename Refs::Alloc Alloc; - typedef OnMerge On_merge; - 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() - {} - - /// Contructor with an info in parameter. - Cell_attribute(const Info_& ainfo) : - Info_for_cell_attribute(ainfo) - {} - }; - - namespace Index - { - // Versions to use with containers using index - /// Cell_attribute_without_info - template - class Cell_attribute_without_info; - - // Cell_attribute_without_info without dart support. - template - class Cell_attribute_without_info - { - template < unsigned int, class, class, class, class > - friend class Combinatorial_map_base; - - template < unsigned int, class, class, class, class > - friend class Generalized_map_base; - template friend class CMap_linear_cell_complex_storage_1; @@ -438,233 +363,7 @@ namespace CGAL { friend class GMap_linear_cell_complex_storage_1; template - friend class Compact_container_with_index; - - public: - typedef Tag_false Supports_cell_dart; - - typedef typename Refs::Dart_handle Dart_handle; - typedef typename Refs::Dart_const_handle Dart_const_handle; - typedef typename Refs::Alloc Alloc; - - typedef OnMerge On_merge; - typedef OnSplit On_split; - - /// operator = - Cell_attribute_without_info& - operator=(const Cell_attribute_without_info& acell) - { - mrefcounting = acell.mrefcounting; - return *this; - } - - /// Get the dart associated with the cell. - Dart_handle dart() { return Refs::null_handle; } - - /// Get the dart associated with the cell. - Dart_const_handle dart() const { return Refs::null_handle; } - - /// Set the dart associated with the cell. - void set_dart(Dart_handle) {} - - /// Test if the cell is valid. - /// For cell without dart, return always true. - 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) - {} - - /// Copy contructor. - Cell_attribute_without_info - (const Cell_attribute_without_info& acell): - mrefcounting(acell.mrefcounting) - {} - - protected: - /// Increment the reference counting. - void inc_nb_refs() - { ++mrefcounting; } - - /// Decrement the reference counting. - void dec_nb_refs() - { - CGAL_assertion( mrefcounting>0 ); - --mrefcounting; - } - - public: - /// Get the reference counting. - typename Refs::size_type get_nb_refs() const - { return mrefcounting; } - - typename Refs::size_type for_compact_container_with_index() const - { return mrefcounting; } - typename Refs::size_type & for_compact_container_with_index() - { return mrefcounting; } - - private: - /// Reference counting: the number of darts linked to this cell. - typename Refs::size_type mrefcounting; - }; - - /** Definition of cell attribute. - * Cell_attribute defines what is a a cell. This is an object allowing to - * link to a dart of the cell (when T is true). - * The refs class must provide the type of Combinatorial_map used. - */ - template - class Cell_attribute_without_info - { - template < unsigned int, class, class, class, class > - friend class Combinatorial_map_base; - - template < unsigned int, class, class, class, class > - friend class Generalized_map_base; - - template - friend class Compact_container_with_index; - - public: - typedef Tag_true Supports_cell_dart; - - typedef typename Refs::Dart_handle Dart_handle; - typedef typename Refs::Dart_const_handle Dart_const_handle; - typedef typename Refs::Alloc Alloc; - - typedef OnMerge On_merge; - typedef OnSplit On_split; - - /// operator = - Cell_attribute_without_info& - operator=(const Cell_attribute_without_info& acell) - { - mdart = acell.mdart; - mrefcounting = acell.mrefcounting; - return *this; - } - - /// Get the dart associated with the cell. - Dart_handle dart() { return mdart; } - - /// Get the dart associated with the cell. - Dart_const_handle dart() const { return mdart; } - - /// Set the dart associated with the cell. - void set_dart(Dart_handle adart) { mdart = adart; } - - /// Test if the cell is valid. - /// A cell is valid if its dart is not NULL. - bool is_valid() const - { return mdart!=Refs::null_handle; } - - 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(Refs::null_handle), - mrefcounting(0) - {} - - /// Copy contructor. - Cell_attribute_without_info - (const Cell_attribute_without_info& acell): - mdart(acell.mdart), - mrefcounting(acell.mrefcounting) - {} - - protected: - /// Increment the reference counting. - void inc_nb_refs() - { ++mrefcounting; } - - /// Decrement the reference counting. - void dec_nb_refs() - { - CGAL_assertion( mrefcounting>0 ); - --mrefcounting; - } - - public: - /// Get the reference counting. - typename Refs::size_type get_nb_refs() const - { return mrefcounting; } - - typename Refs::size_type for_compact_container_with_index() const - { return mdart.for_compact_container_with_index(); } - typename Refs::size_type & for_compact_container_with_index() - { return mdart.for_compact_container_with_index(); } - - private: - /// Reference counting: the number of darts linked to this cell. - std::size_t mrefcounting; - - /// The dart handle associated with the cell. - Dart_handle mdart; - }; - - /// Cell associated with an attribute, with or without info depending - /// if Info==void. - template - class Cell_attribute; - - /// Specialization when Info==void. - template - class Cell_attribute : - public Cell_attribute_without_info - { - template < unsigned int, class, class, class, class > - friend class Combinatorial_map_base; - - template - friend class Compact_container_with_index; - - public: - typedef Tag_ Supports_cell_dart; - typedef typename Refs::Dart_handle Dart_handle; - typedef typename Refs::Dart_const_handle Dart_const_handle; - typedef typename Refs::Alloc Alloc; - typedef OnMerge On_merge; - typedef OnSplit On_split; - typedef void Info; - - // protected: - /// Default contructor. - Cell_attribute() - {} - }; - - /// Specialization when Info!=void. - template - class Cell_attribute : - public Cell_attribute_without_info, - public Info_for_cell_attribute - { - template < unsigned int, class, class, class, class > - friend class Combinatorial_map_base; - - template - friend class Compact_container_with_index; + friend class Compact_container; template friend class Concurrent_compact_container; @@ -686,7 +385,8 @@ namespace CGAL { bool operator!=(const Self& other) const { return !operator==(other); } - protected: + + // protected: /// Default contructor. Cell_attribute() {} @@ -696,7 +396,6 @@ namespace CGAL { Info_for_cell_attribute(ainfo) {} }; - } // namespace Index } // namespace CGAL diff --git a/Combinatorial_map/include/CGAL/Cell_attribute_with_index.h b/Combinatorial_map/include/CGAL/Cell_attribute_with_index.h new file mode 100644 index 00000000000..3b098c6c4fc --- /dev/null +++ b/Combinatorial_map/include/CGAL/Cell_attribute_with_index.h @@ -0,0 +1,304 @@ +// Copyright (c) 2010-2011 CNRS and LIRIS' Establishments (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Guillaume Damiand +// +#ifndef CGAL_CELL_ATTRIBUTE_WITH_INDEX_H +#define CGAL_CELL_ATTRIBUTE_WITH_INDEX_H 1 + +#include +#include +#include +#include + +namespace CGAL { + + template + class Compact_container_with_index_2; + + template + class Combinatorial_map_storage_2; + + namespace Index + { + // Versions to use with containers using index + /// Cell_attribute_without_info + template + class Cell_attribute_without_info; + + // Cell_attribute_without_info without dart support. + template + class Cell_attribute_without_info + { + template + friend class CGAL::Combinatorial_map_storage_2; + + template + friend class CGAL::Compact_container_with_index_2; + + public: + typedef Tag_false Supports_cell_dart; + + typedef typename Refs::Dart_handle Dart_handle; + typedef typename Refs::Dart_const_handle Dart_const_handle; + typedef typename Refs::Alloc Alloc; + typedef CGAL::Tag_false Has_id; + + typedef OnMerge On_merge; + typedef OnSplit On_split; + + /// operator = + Cell_attribute_without_info& + operator=(const Cell_attribute_without_info& acell) + { + mrefcounting = acell.mrefcounting; + return *this; + } + + /// Get the dart associated with the cell. + Dart_handle dart() { return Refs::null_handle; } + + /// Get the dart associated with the cell. + Dart_const_handle dart() const { return Refs::null_handle; } + + /// Set the dart associated with the cell. + void set_dart(Dart_handle) {} + + /// Test if the cell is valid. + /// For cell without dart, return always true. + 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) + {} + + /// Copy contructor. + Cell_attribute_without_info + (const Cell_attribute_without_info& acell): + mrefcounting(acell.mrefcounting) + {} + + protected: + /// Increment the reference counting. + void inc_nb_refs() + { ++mrefcounting; } + + /// Decrement the reference counting. + void dec_nb_refs() + { + CGAL_assertion( mrefcounting>0 ); + --mrefcounting; + } + + public: + /// Get the reference counting. + typename Refs::size_type get_nb_refs() const + { return mrefcounting; } + + typename Refs::size_type for_compact_container_with_index() const + { return mrefcounting; } + typename Refs::size_type & for_compact_container_with_index() + { return mrefcounting; } + + private: + /// Reference counting: the number of darts linked to this cell. + typename Refs::size_type mrefcounting; + }; + + /** Definition of cell attribute. + * Cell_attribute defines what is a a cell. This is an object allowing to + * link to a dart of the cell (when T is true). + * The refs class must provide the type of Combinatorial_map used. + */ + template + class Cell_attribute_without_info + { + template + friend class CGAL::Combinatorial_map_storage_2; + + template + friend class CGAL::Compact_container_with_index; + + public: + typedef Tag_true Supports_cell_dart; + + typedef typename Refs::Dart_handle Dart_handle; + typedef typename Refs::Dart_const_handle Dart_const_handle; + typedef typename Refs::Alloc Alloc; + typedef CGAL::Tag_false Has_id; + + typedef OnMerge On_merge; + typedef OnSplit On_split; + + /// operator = + Cell_attribute_without_info& + operator=(const Cell_attribute_without_info& acell) + { + mdart = acell.mdart; + mrefcounting = acell.mrefcounting; + return *this; + } + + /// Get the dart associated with the cell. + Dart_handle dart() { return mdart; } + + /// Get the dart associated with the cell. + Dart_const_handle dart() const { return mdart; } + + /// Set the dart associated with the cell. + void set_dart(Dart_handle adart) { mdart = adart; } + + /// Test if the cell is valid. + /// A cell is valid if its dart is not NULL. + bool is_valid() const + { return mdart!=Refs::null_handle; } + + 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(Refs::null_handle), + mrefcounting(0) + {} + + /// Copy contructor. + Cell_attribute_without_info + (const Cell_attribute_without_info& acell): + mdart(acell.mdart), + mrefcounting(acell.mrefcounting) + {} + + protected: + /// Increment the reference counting. + void inc_nb_refs() + { ++mrefcounting; } + + /// Decrement the reference counting. + void dec_nb_refs() + { + CGAL_assertion( mrefcounting>0 ); + --mrefcounting; + } + + public: + /// Get the reference counting. + typename Refs::size_type get_nb_refs() const + { return mrefcounting; } + + typename Refs::size_type for_compact_container_with_index() const + { return mdart.for_compact_container_with_index(); } + typename Refs::size_type & for_compact_container_with_index() + { return mdart.for_compact_container_with_index(); } + + private: + /// Reference counting: the number of darts linked to this cell. + std::size_t mrefcounting; + + /// The dart handle associated with the cell. + Dart_handle mdart; + }; + + /// Cell associated with an attribute, with or without info depending + /// if Info==void. + template + class Cell_attribute; + + /// Specialization when Info==void. + template + class Cell_attribute : + public Cell_attribute_without_info + { + template < unsigned int, class, class, class, class > + friend class CGAL::Combinatorial_map_base; + + template + friend class CGAL::Compact_container_with_index_2; + + public: + typedef Tag_ Supports_cell_dart; + typedef typename Refs::Dart_handle Dart_handle; + typedef typename Refs::Dart_const_handle Dart_const_handle; + typedef typename Refs::Alloc Alloc; + typedef OnMerge On_merge; + typedef OnSplit On_split; + typedef void Info; + + // protected: + /// Default contructor. + Cell_attribute() + {} + }; + + /// Specialization when Info!=void. + template + class Cell_attribute : + public Cell_attribute_without_info, + public CGAL::Info_for_cell_attribute + { + template < unsigned int, class, class, class, class > + friend class CGAL::Combinatorial_map_base; + + template + friend class CGAL::Compact_container_with_index_2; + + public: + typedef Cell_attribute Self; + + typedef Tag_ Supports_cell_dart; + typedef typename Refs::Dart_handle Dart_handle; + typedef typename Refs::Dart_const_handle Dart_const_handle; + typedef typename Refs::Alloc Alloc; + typedef OnMerge On_merge; + 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() + {} + + /// Contructor with an info in parameter. + Cell_attribute(const Info_& ainfo) : + Info_for_cell_attribute(ainfo) + {} + }; + } // namespace Index + +} // namespace CGAL + +#endif // CGAL_CELL_ATTRIBUTE_WITH_INDEX_H // +// EOF // diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index f0bbc880cad..4ad1ac80b43 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -862,7 +863,7 @@ namespace CGAL { Helper::template Foreach_enabled_attributes >::run(*this, adart); - internal::Init_id::run(mdarts, adart); + // TODO internal::Init_id::run(mdarts, adart); } // Initialize a given dart: all beta to null_dart_handle and all // attributes to null, marks are given. diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map/internal/Combinatorial_map_internal_functors.h b/Combinatorial_map/include/CGAL/Combinatorial_map/internal/Combinatorial_map_internal_functors.h index 59dd95a40d9..e607ac02f5a 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map/internal/Combinatorial_map_internal_functors.h @@ -496,7 +496,7 @@ struct Init_attribute_functor { template static void run(CMap& amap, typename CMap::Dart_handle adart) - { amap.template set_dart_attribute(adart, CMap::null_handle); } + { amap.template set_dart_attribute(adart, 0/* TODO CMap::null_handle*/); } }; // **************************************************************************** /// Functor used to set the i-attribute of a given dart. @@ -1039,7 +1039,8 @@ struct Init_id template struct Init_id { - static void run(Container&, typename Container::iterator) + template + static void run(Container&, Index) {} }; // **************************************************************************** diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map/internal/Combinatorial_map_utility.h b/Combinatorial_map/include/CGAL/Combinatorial_map/internal/Combinatorial_map_utility.h index a460ecd9867..23f1a12ad18 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map/internal/Combinatorial_map_utility.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map/internal/Combinatorial_map_utility.h @@ -526,7 +526,8 @@ namespace CGAL { typedef Void type; }; // Helper class allowing to retreive the d-cell-handle attribute - template::type> + template::type, + typename WithIndex=typename CMap::Use_index> struct Attribute_handle { typedef typename std::tuple_element @@ -534,10 +535,14 @@ namespace CGAL }; template - struct Attribute_handle + struct Attribute_handle { typedef CGAL::Void* type; }; - // Helper class allowing to retreive the d-cell-const handle attribute + template + struct Attribute_handle + { typedef typename CMap::Dart_index type; }; + + // Helper class allowing to retreive the d-cell-const handle attribute template::type> struct Attribute_const_handle { diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_storages.h b/Combinatorial_map/include/CGAL/Combinatorial_map_storages.h index 73055a7fe0c..3bb1f7fef5d 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_storages.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_storages.h @@ -42,8 +42,8 @@ namespace CGAL { class Combinatorial_map_storage_1 { public: - typedef Combinatorial_map_storage_1 Self; - typedef CGAL::Tag_false Use_index; + using Self=Combinatorial_map_storage_1; + using Use_index=CGAL::Tag_false; typedef internal::Combinatorial_map_helper Helper; diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_storages_with_index.h b/Combinatorial_map/include/CGAL/Combinatorial_map_storages_with_index.h index 3e5a198f5ea..8b31716b7fb 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_storages_with_index.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_storages_with_index.h @@ -31,6 +31,14 @@ namespace CGAL { template struct Container_type; + + struct Index_hash_function { + typedef std::size_t result_type; + template + std::size_t operator() (const H& h) const { + return h; + } + }; } // Storage with combinatorial maps using index @@ -38,59 +46,25 @@ namespace CGAL { class Combinatorial_map_storage_2 { public: - typedef Combinatorial_map_storage_2 Self; - typedef CGAL::Tag_true Use_index; + using Self=Combinatorial_map_storage_2; + using Use_index=CGAL::Tag_true; using Index_type=Index_type_; typedef internal::Combinatorial_map_helper Helper; typedef typename Items_::template Dart_wrapper Dart_wrapper; - typedef typename Dart_wrapper::Dart Dart; - typedef typename Alloc_::template rebind::other Dart_allocator; - typedef Size_type size_type; // Type used as index. + typedef typename internal::template Get_dart_info::type + Dart_info; + typedef CGAL::Index::Dart Dart; + + typedef std::allocator_traits Allocator_traits; + typedef typename Allocator_traits::template rebind_alloc Dart_allocator; typedef Compact_container_with_index_2, size_type > + Constant_size_policy_for_cc_with_size<1024>, Index_type> Dart_container; - typedef Items_ Items; - typedef Alloc_ Alloc; - - template - struct Container_for_attributes : public - Compact_container_with_index_2::other, - Constant_size_policy_for_cc_with_size<1024>, size_type > - {}; - - /// Typedef for attributes - typedef typename Dart_wrapper::Attributes Attributes; - - template - struct Attribute_type: public Helper::template Attribute_type - {}; - template - struct Attribute_handle: public Helper::template Attribute_handle - {}; - template - struct Attribute_const_handle: - public Helper::template Attribute_const_handle - {}; - template - struct Attribute_range: public Helper::template Attribute_range - {}; - template - struct Attribute_const_range: - public Helper::template Attribute_const_range - {}; - - /// Number of marks - static const size_type NB_MARKS = 32; - - /// The dimension of the combinatorial map. - static const unsigned int dimension = d_; - // typedef unsigned int Dart_index; // typedef MyIndex Dart_index; typedef typename Dart_container::Index Dart_index; @@ -98,12 +72,47 @@ namespace CGAL { // Definition of old types, for backward compatibility. typedef Dart_index Dart_handle; typedef Dart_index Dart_const_handle; + typedef typename Dart_container::size_type size_type; - /// Value of null handle (!= null_dart_handle !!) - typedef size_type Null_handle_type; - static const size_type null_handle; + typedef Dart_index Null_handle_type; + static Null_handle_type null_handle; - typedef Index_hash_function Hash_function; + typedef Items_ Items; + typedef Alloc_ Alloc; + template + struct Container_for_attributes : public + Compact_container_with_index_2::other, + Constant_size_policy_for_cc_with_size<1024>, size_type > + {}; + + /// Typedef for attributes + typedef typename internal::template Get_attributes_tuple::type + Attributes; + + template + struct Attribute_type: public Helper::template Attribute_type + {}; + template + struct Attribute_range + { using type=Container_for_attributes::type>; }; + template + struct Attribute_const_range + { using type=const typename Attribute_range::type; }; + template + struct Attribute_handle + { using type=typename Attribute_range::type::Index; }; + template + struct Attribute_const_handle + { using type=const typename Attribute_range::type::Index; }; + + /// Number of marks + static const size_type NB_MARKS = 32; + + /// The dimension of the combinatorial map. + static const unsigned int dimension = d_; + + typedef internal::Index_hash_function Hash_function; //************************************************************************** // Dart_range @@ -123,6 +132,8 @@ namespace CGAL { { return mmap.mdarts.size()-1; } bool empty() const { return mmap.is_empty(); } + size_type index(const_iterator cit) const + { return cit; } private: Self & mmap; }; @@ -139,11 +150,14 @@ namespace CGAL { void init_storage() { // Allocate a dart for null_dart_handle - null_dart_handle = mdarts.emplace(); + assert(mdarts.empty()); + Dart_index local_null_dart_handle = mdarts.emplace(); + CGAL_USE(local_null_dart_handle); + assert(local_null_dart_handle==0); } void clear_storage() - {} + { mdarts.clear(); } /** Test if the map is empty. * @return true iff the map is empty. @@ -164,12 +178,12 @@ namespace CGAL { bool is_free(Dart_const_handle dh) const { CGAL_assertion(i <= dimension); - return mdarts[dh].mbeta[i]==null_dart_handle; + return mdarts[dh].mf[i]==null_dart_handle; } bool is_free(Dart_const_handle dh, unsigned int i) const { CGAL_assertion(i <= dimension); - return mdarts[dh].mbeta[i]==null_dart_handle; + return mdarts[dh].mf[i]==null_dart_handle; } /// Set simultaneously all the marks of this dart to a given value. @@ -184,19 +198,19 @@ namespace CGAL { return mdarts[ADart].get_marks(); } /// Return the mark value of dart a given mark number. - bool get_dart_mark(Dart_const_handle ADart, int amark) const + bool get_dart_mark(Dart_const_handle ADart, size_type amark) const { return mdarts[ADart].get_mark(amark); } /// Set the mark of a given mark number to a given value. - void set_dart_mark(Dart_const_handle ADart, int amark, bool avalue) const + void set_dart_mark(Dart_const_handle ADart, size_type amark, bool avalue) const { mdarts[ADart].set_mark(amark, avalue); } /// Flip the mark of a given mark number to a given value. - void flip_dart_mark(Dart_const_handle ADart, int amark) const + void flip_dart_mark(Dart_const_handle ADart, size_type amark) const { mdarts[ADart].flip_mark(amark); } @@ -205,24 +219,24 @@ namespace CGAL { Dart_handle get_beta(Dart_handle ADart, int B1) { CGAL_assertion(B1>=0 && B1<=dimension); - return mdarts[ADart].mbeta[B1]; + return mdarts[ADart].mf[B1]; } Dart_const_handle get_beta(Dart_const_handle ADart, int B1) const { CGAL_assertion(B1>=0 && B1<=dimension); - return mdarts[ADart].mbeta[B1]; + return mdarts[ADart].mf[B1]; } template Dart_handle get_beta(Dart_handle ADart) { CGAL_assertion(B1>=0 && B1<=dimension); - return mdarts[ADart].mbeta[B1]; + return mdarts[ADart].mf[B1]; } template Dart_const_handle get_beta(Dart_const_handle ADart) const { CGAL_assertion(B1>=0 && B1<=dimension); - return mdarts[ADart].mbeta[B1]; + return mdarts[ADart].mf[B1]; } // return a handle on the i-attribute @@ -231,7 +245,7 @@ namespace CGAL { { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "attribute called but i-attributes are disabled."); - return CGAL::cpp11::get::value> + return std::get::value> (mdarts[ADart].mattribute_handles); } template @@ -240,16 +254,61 @@ namespace CGAL { { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "attribute called but i-attributes are disabled."); - return CGAL::cpp11::get::value> + return std::get::value> (mdarts[ADart].mattribute_handles); } + // Copy a given attribute + template + typename Attribute_handle::type copy_attribute + (typename Attribute_const_handle::type ah) + { + CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, + "copy_attribute called but i-attributes are disabled."); + typename Attribute_handle::type res= + std::get::value> + (mattribute_containers).emplace(get_attribute(ah)); + this->template init_attribute_ref_counting(res); + return res; + } + + // Test if a given attribute is valid + template + bool is_valid_attribute(typename Attribute_const_handle::type ah) const + { + return get_attribute(ah).is_valid(); + } + + // accessors and modifiers to the attribute ref counting given its handle + template + std::size_t get_attribute_ref_counting + (typename Attribute_const_handle::type ah) const + { + return get_attribute(ah).get_nb_refs(); + } + template + void init_attribute_ref_counting(typename Attribute_handle::type ah) + { + get_attribute(ah).mrefcounting=0; + } + template + void inc_attribute_ref_counting(typename Attribute_handle::type ah) + { + get_attribute(ah).inc_nb_refs(); + } + template + void dec_attribute_ref_counting(typename Attribute_handle::type ah) + { + get_attribute(ah).dec_nb_refs(); + } + + // get the attribute given its index template typename Attribute_type::type& get_attribute(typename Attribute_handle::type ah) { CGAL_assertion( ah!=null_handle ); - return CGAL::cpp11::get::value> + return std::get::value> (mattribute_containers)[ah]; } @@ -258,53 +317,23 @@ namespace CGAL { get_attribute(typename Attribute_const_handle::type ah) const { CGAL_assertion( ah!=null_handle ); - return CGAL::cpp11::get::value> + return std::get::value> (mattribute_containers)[ah]; } - Dart & get_dart(Dart_handle ah) - { - CGAL_assertion( ah!=null_handle ); - return mdarts[ah]; - } - const Dart & get_dart(Dart_const_handle ah) const - { - CGAL_assertion( ah!=null_handle ); - return mdarts[ah]; - } - - // Get the attribute of a dart - template - typename Attribute_type::type& get_attribute_of_dart(Dart_handle adart) - { - CGAL_assertion( adart!=null_handle ); - CGAL_assertion( attribute(adart)!=null_handle ); - return get_attribute(attribute(adart)); - } - template - const typename Attribute_type::type& - get_attribute_of_dart(Dart_const_handle adart) const - { - CGAL_assertion( adart!=null_handle ); - CGAL_assertion( attribute(adart)!=null_handle ); - return get_attribute(attribute(adart)); - } - // Get the dart of the given attribute template Dart_handle dart_of_attribute(typename Attribute_handle::type ah) { CGAL_assertion( ah!=null_handle ); - return CGAL::cpp11::get::value> - (mattribute_containers)[ah].dart(); + return get_attribute(ah).dart(); } template Dart_const_handle dart_of_attribute(typename Attribute_const_handle::type ah) const { CGAL_assertion( ah!=null_handle ); - return CGAL::cpp11::get::value> - (mattribute_containers)[ah].dart(); + return get_attribute(ah).dart(); } // Set the dart of the given attribute @@ -313,8 +342,7 @@ namespace CGAL { Dart_handle adart) { CGAL_assertion( ah!=null_handle ); - CGAL::cpp11::get::value> - (mattribute_containers)[ah].set_dart(adart); + get_attribute(ah).set_dart(adart); } // Get the information associated with a given dart @@ -329,16 +357,14 @@ namespace CGAL { info_of_attribute(typename Attribute_handle::type ah) { CGAL_assertion( ah!=null_handle ); - return CGAL::cpp11::get::value> - (mattribute_containers)[ah].info(); + return get_attribute(ah).info(); } template const typename Attribute_type::type::Info & info_of_attribute(typename Attribute_const_handle::type ah) const { CGAL_assertion( ah!=null_handle ); - return CGAL::cpp11::get::value> - (mattribute_containers)[ah].info(); + return get_attribute(ah).info(); } // Get the info of the i-cell attribute associated with the given dart @@ -388,7 +414,7 @@ namespace CGAL { void basic_set_dart_attribute(Dart_handle ADart, typename Attribute_handle::type ah) { - CGAL::cpp11::get::value> + std::get::value> (mdarts[ADart].mattribute_handles) = ah; } @@ -429,7 +455,7 @@ namespace CGAL { public: /// Void dart. A dart d is i-free if beta_i(d)=null_dart_handle. - static const Dart_index null_dart_handle; //=0; + static Dart_index null_dart_handle; //=0; protected: /// Dart container. @@ -442,12 +468,13 @@ namespace CGAL { /// null_dart_handle template - const typename Combinatorial_map_storage_2::Dart_index + typename Combinatorial_map_storage_2::Dart_index Combinatorial_map_storage_2::null_dart_handle(0); /// null_handle template - const Size_type Combinatorial_map_storage_2::null_handle((std::numeric_limits::max)()/2); + typename Combinatorial_map_storage_2::Null_handle_type + Combinatorial_map_storage_2::null_handle((std::numeric_limits::max)()/2); } // namespace CGAL diff --git a/Combinatorial_map/include/CGAL/Compact_container_with_index_2.h b/Combinatorial_map/include/CGAL/Compact_container_with_index_2.h index c3381589aee..857732a798f 100644 --- a/Combinatorial_map/include/CGAL/Compact_container_with_index_2.h +++ b/Combinatorial_map/include/CGAL/Compact_container_with_index_2.h @@ -105,11 +105,19 @@ public: : Base(idx) {} + Index(const Index& idx): Base(idx) + {} + Index(const const_iterator& it) : Base(it) {} Index(const iterator& it) : Base(it) {} + + // Constructor allowing to transform an index from one container to another + template + Index(const Index2& idx): Base(static_cast(idx)) + {} }; friend class internal::CC_iterator_with_index; friend class internal::CC_iterator_with_index; diff --git a/Combinatorial_map/include/CGAL/Dart.h b/Combinatorial_map/include/CGAL/Dart.h index 0ff820763d3..400728a714f 100644 --- a/Combinatorial_map/include/CGAL/Dart.h +++ b/Combinatorial_map/include/CGAL/Dart.h @@ -17,6 +17,7 @@ #include #include #include +#include namespace CGAL { @@ -70,27 +71,15 @@ namespace CGAL { template friend class Generalized_map_storage_1; - template - friend class Combinatorial_map_storage_2; - template friend class CMap_linear_cell_complex_storage_1; - template - friend class Linear_cell_complex_storage_2; - template friend class GMap_linear_cell_complex_storage_1; template friend class Compact_container; - template - friend class Compact_container_with_index; - - template - friend class Compact_container_with_index_2; - template friend class Concurrent_compact_container; @@ -271,167 +260,6 @@ namespace CGAL { typedef CGAL::Void Info; }; - namespace Index - { - template - struct Dart - { - template - friend class Combinatorial_map_storage_1; - - template - friend class Combinatorial_map_storage_2; - - template - friend class Linear_cell_complex_storage_1; - - template - friend class Linear_cell_complex_storage_2; - - template - friend class Compact_container; - - template - friend class Concurrent_compact_container; - - template - friend class Compact_container_with_index; - - template - friend class Compact_container_with_index_2; - - public: - typedef Dart Self; - typedef typename Refs::Dart_handle Dart_handle; - typedef typename Refs::size_type size_type; - typedef typename Refs::Dart_const_handle Dart_const_handle; - typedef typename Refs::Helper Helper; - /// Typedef for attributes - template - struct Attribute_handle: public Refs::template Attribute_handle - {}; - template - struct Attribute_const_handle: - public Refs::template Attribute_const_handle - {}; - - /// The number of used marks. - static const size_type NB_MARKS = Refs::NB_MARKS; - - /// The dimension of the combinatorial map. - static const unsigned int dimension = d; - - Dart_handle get_f(unsigned int i) const - { - assert(i<=dimension); - return mf[i]; - } - - /// @return a handle on the i-attribute - template - typename Attribute_handle::type attribute() - { - CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, - "attribute called but i-attributes are disabled."); - return CGAL::cpp11::get::value> - (mattribute_handles); - } - template - typename Attribute_const_handle::type attribute() const - { - CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, - "attribute called but i-attributes are disabled."); - return CGAL::cpp11::get::value> - (mattribute_handles); - } - - /// Set the handle on the i th attribute - template - void set_attribute( typename Attribute_handle::type ahandle ) - { - CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, - "set_attribute called but i-attributes are disabled."); - CGAL::cpp11::get::value> - (mattribute_handles) = ahandle; - if (ahandle!=NULL) ahandle->inc_nb_refs(); - } - - /** Return the mark value of a given mark number. - * @param amark the mark number. - * @return the value for this number. - */ - bool get_mark(int amark) const - { - CGAL_assertion(amark>=0 && (size_type)amark=0 && (size_type)amark=0 && (size_type)amark get_marks() const - { return mmarks; } - - /** Set simultaneously all the marks of this dart to a given value. - * @param amarks the value of the marks. - */ - void set_marks(const std::bitset& amarks) const - { mmarks = amarks; } - - protected: - /** Default constructor: no real initialisation, - * because this is done in the combinatorial map class. - */ - Dart() - {} - - /** Copy constructor: - * @param adart a dart. - */ - Dart(const Dart& adart) : mmarks(adart.mmarks), - mattribute_handles(adart.mattribute_handles) - { - for (unsigned int i = 0; i <= dimension; ++i) - mf[i] = adart.mf[i]; - } - - public: - size_type for_compact_container_with_index() const - { return mf[0].for_compact_container_with_index(); } - size_type& for_compact_container_with_index() - { return mf[0].for_compact_container_with_index(); } - - protected: - /// Neighboors for each dimension +1 (from 0 to dimension). - Dart_handle mf[dimension+1]; - - /// Values of Boolean marks. - mutable std::bitset mmarks; - - /// Attributes enabled - typename Helper::Attribute_handles mattribute_handles; - }; - } // namespace Index - } // namespace CGAL #endif // CGAL_DART_H // diff --git a/Combinatorial_map/include/CGAL/Dart_with_index.h b/Combinatorial_map/include/CGAL/Dart_with_index.h new file mode 100644 index 00000000000..e172b417ea9 --- /dev/null +++ b/Combinatorial_map/include/CGAL/Dart_with_index.h @@ -0,0 +1,206 @@ +// Copyright (c) 2010-2011 CNRS and LIRIS' Establishments (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Guillaume Damiand +// +#ifndef CGAL_DART_WITH_INDEX_H +#define CGAL_DART_WITH_INDEX_H 1 + +#include +#include +#include +#include +#include + +namespace CGAL { + + namespace Index + { + template + struct Dart_without_info + { + template + friend class CGAL::Combinatorial_map_storage_2; + + // TODO template + // friend class CGAL::CMap_linear_cell_complex_storage_2; + + template + friend class CGAL::Compact_container_with_index_2; + + typedef Dart_without_info Self; + typedef typename Refs::Dart_handle Dart_handle; + typedef typename Refs::size_type size_type; + typedef typename Refs::Dart_const_handle Dart_const_handle; + typedef typename Refs::Helper Helper; + typedef CGAL::Tag_false Has_id; + + /// Typedef for attributes + template + struct Attribute_handle: public Refs::template Attribute_handle + {}; + template + struct Attribute_const_handle: + public Refs::template Attribute_const_handle + {}; + + /// The number of used marks. + static const size_type NB_MARKS = Refs::NB_MARKS; + + /// The dimension of the combinatorial map. + static const unsigned int dimension = d; + + size_type for_compact_container_with_index() const + { return mf[0].for_compact_container_with_index(); } + size_type& for_compact_container_with_index() + { return mf[0].for_compact_container_with_index(); } + + Dart_handle get_f(unsigned int i) const + { + assert(i<=dimension); + return mf[i]; + } + + protected: + /** Default constructor: no real initialisation, + * because this is done in the combinatorial map class. + */ + Dart_without_info() + {} + + /** Copy constructor: + * @param adart a dart. + */ + Dart_without_info(const Dart_without_info& adart) : mmarks(adart.mmarks), + mattribute_handles(adart.mattribute_handles) + { + for (unsigned int i = 0; i <= dimension; ++i) + mf[i] = adart.mf[i]; + } + + /** Return the mark value of a given mark number. + * @param amark the mark number. + * @return the value for this number. + */ + bool get_mark(size_type amark) const + { + CGAL_assertion(amark>=0 && amark=0 && amark=0 && amark get_marks() const + { return mmarks; } + + /** Set simultaneously all the marks of this dart to a given value. + * @param amarks the value of the marks. + */ + void set_marks(const std::bitset& amarks) const + { mmarks = amarks; } + + /// @return a handle on the i-attribute + template + typename Attribute_handle::type attribute() + { + CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, + "attribute called but i-attributes are disabled."); + return std::get::value> + (mattribute_handles); + } + template + typename Attribute_const_handle::type attribute() const + { + CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, + "attribute called but i-attributes are disabled."); + return std::get::value> + (mattribute_handles); + } + + protected: + /// Neighboors for each dimension +1 (from 0 to dimension). + Dart_handle mf[dimension+1]; + + /// Values of Boolean marks. + mutable std::bitset mmarks; + + /// Attributes enabled + typename Helper::Attribute_handles mattribute_handles; + }; + + // Dart definition with an info; + // (there is a specialization below when Info_==void) + template + struct Dart : public Dart_without_info + { + public: + template + friend class CGAL::Combinatorial_map_storage_2; + + /* TODO template + friend class CMap_linear_cell_complex_storage_2; */ + + template + friend class CGAL::Compact_container_with_index_2; + + typedef Dart Self; + typedef Info_ Info; + + protected: + /** Default constructor: no real initialisation, + * because this is done in the combinatorial or generalized map class. + */ + Dart() + {} + + Dart(const Info_& info) : minfo(info) + {} + + Info_& info() + { return minfo; } + const Info_& info() const + { return minfo; } + + protected: + Info minfo; + }; + + // Specialization of Dart class when info==void + template + struct Dart : public Dart_without_info + { + public: + typedef CGAL::Void Info; + }; + + } // namespace Index + +} // namespace CGAL + +#endif // CGAL_DART_WITH_INDEX_H // +// EOF // diff --git a/Combinatorial_map/include/CGAL/Info_for_cell_attribute.h b/Combinatorial_map/include/CGAL/Info_for_cell_attribute.h new file mode 100644 index 00000000000..188bd5cc5ca --- /dev/null +++ b/Combinatorial_map/include/CGAL/Info_for_cell_attribute.h @@ -0,0 +1,46 @@ +// Copyright (c) 2010-2011 CNRS and LIRIS' Establishments (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Guillaume Damiand +// +#ifndef CGAL_INFO_FOR_CELL_ATTRIBUTE_H +#define CGAL_INFO_FOR_CELL_ATTRIBUTE_H 1 + +namespace CGAL { + + /// Info associated with a cell_attribute. + template + class Info_for_cell_attribute + { + public: + /// Contructor without parameter. + Info_for_cell_attribute() + {} + + /// Contructor with an info in parameter. + Info_for_cell_attribute(const Info& ainfo) : minfo(ainfo) + {} + + /// Get the info associated with the cell_attribute. + Info& info() + { return minfo; } + + /// Get the info associated with the cell_attribute. + const Info& info() const + { return minfo; } + + protected: + /// The info associated with the cell_attribute. + Info minfo; + }; + +} // namespace CGAL + +#endif // CGAL_INFO_FOR_CELL_ATTRIBUTE_H // +// EOF //