Boost logo

Boost-Commit :

From: hervebronnimann_at_[hidden]
Date: 2007-07-16 00:50:38


Author: hervebronnimann
Date: 2007-07-16 00:50:37 EDT (Mon, 16 Jul 2007)
New Revision: 7444
URL: http://svn.boost.org/trac/boost/changeset/7444

Log:
Skeleton for facet_selectors testing.
Added value() to container_gen.

Text files modified:
   sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/container_selectors.hpp | 39 +++++++++
   sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/facet_selectors.hpp | 76 +++++++++++++++--
   sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/facet_selectors.t.cpp | 163 ++++++++++++---------------------------
   3 files changed, 154 insertions(+), 124 deletions(-)

Modified: sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/container_selectors.hpp
==============================================================================
--- sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/container_selectors.hpp (original)
+++ sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/container_selectors.hpp 2007-07-16 00:50:37 EDT (Mon, 16 Jul 2007)
@@ -143,6 +143,9 @@
 namespace boost {
 namespace hdstl {
 
+ // ===================
+ // container selectors
+ // ===================
 
 /*
 struct hashS {
@@ -175,6 +178,10 @@
 };
 
 
+ // ===================
+ // class container_gen
+ // ===================
+
 template <typename Selector, typename ValueType>
 struct container_gen {
     // This 'struct', properly specialized for the specified 'Selector', gives
@@ -260,8 +267,17 @@
     {
         return /* not known */;
     }
+
+ static ValueType& value(descriptor x, type& container)
+ // This utility returns the value associated with the specified
+ // descriptor 'x' of the specified 'container'.
+ {
+ (void)container; // avoid unused variable warning
+ return *x;
+ }
 };
 #endif
+
 template <typename ValueType>
 struct container_gen<listS, ValueType> {
     // This specialization of 'container_gen' selects the 'std::list'
@@ -318,6 +334,14 @@
     {
         return container.end();
     }
+
+ static ValueType& value(descriptor x, type& container)
+ // This utility returns the value associated with the specified
+ // descriptor 'x' of the specified 'container'.
+ {
+ (void)container; // avoid unused variable warning
+ return *x;
+ }
 };
 
 template <typename ValueType>
@@ -376,6 +400,14 @@
     {
         return container.end();
     }
+
+ static ValueType& value(descriptor x, type& container)
+ // This utility returns the value associated with the specified
+ // descriptor 'x' of the specified 'container'.
+ {
+ (void)container; // avoid unused variable warning
+ return *x;
+ }
 };
 
 template <typename ValueType>
@@ -436,6 +468,13 @@
     {
         return iterator(&container, container.end());
     }
+
+ static ValueType& value(descriptor x, type& container)
+ // This utility returns the value associated with the specified
+ // descriptor 'x' of the specified 'container'.
+ {
+ return container[x];
+ }
 };
 
 } // namespace hdstl

Modified: sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/facet_selectors.hpp
==============================================================================
--- sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/facet_selectors.hpp (original)
+++ sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/facet_selectors.hpp 2007-07-16 00:50:37 EDT (Mon, 16 Jul 2007)
@@ -186,30 +186,71 @@
 template <typename Base,
           bool HasFacetLink = false,
           typename HalfedgeDescriptor = int>
-struct stored_facet : public Base {
- // This 'struct' implements a stored facet, deriving from the
- // parameterized 'Base', and adding a facet link if 'HasFacetLink' is
+struct stored_facet {
+ // This 'struct' implements a stored facet, from the
+ // parameterized 'Base' (if not void), and adding a facet link if 'HasFacetLink' is
     // true.
 
     // DATA
     HalfedgeDescriptor m_facetLink;
+ Base m_base;
 
     // CREATORS
- stored_facet(Base const& base, HalfedgeDescriptor facetLink)
- : Base(base)
- , m_facetLink(facetLink) {}
+ stored_facet(Base const& base, HalfedgeDescriptor facetLink = 0)
+ : m_facetLink(facetLink)
+ , m_base(base) {}
+
+ // MANIPULATORS
+ Base& base() { return m_base; }
+
+ // ACCESSORS
+ const Base& base() const { return m_base; }
 };
 
 template <typename Base, typename HalfedgeDescriptor>
-struct stored_facet<Base, false, HalfedgeDescriptor> : public Base {
+struct stored_facet<Base, false, HalfedgeDescriptor> {
     // This partial specialization implements a stored facet, deriving from the
     // parameterized 'Base', but without storing a facet link although its
     // constructor accepts a null facet link for uniformity of the
     // interface with the general definition.
 
+ // DATA
+ Base m_base;
+
     // CREATORS
     stored_facet(Base const& base, HalfedgeDescriptor = 0)
- : Base(base) {}
+ : m_base(base) {}
+
+ // MANIPULATORS
+ Base& base() { return m_base; }
+
+ // ACCESSORS
+ const Base& base() const { return m_base; }
+};
+
+template <bool HasFacetLink,
+ typename HalfedgeDescriptor>
+struct stored_facet<void, HasFacetLink, HalfedgeDescriptor> {
+ // This 'struct' implements a stored facet, with a 'void' base, adding a
+ // facet link if 'HasFacetLink' is true.
+
+ // DATA
+ HalfedgeDescriptor m_facetLink;
+
+ // CREATORS
+ stored_facet(HalfedgeDescriptor facetLink)
+ : m_facetLink(facetLink) {}
+};
+
+template <typename HalfedgeDescriptor>
+struct stored_facet<void, false, HalfedgeDescriptor> {
+ // This partial specialization implements a stored facet, deriving from the
+ // parameterized 'Base', but without storing a facet link although its
+ // constructor accepts a null facet link for uniformity of the
+ // interface with the general definition.
+
+ // CREATORS
+ stored_facet(HalfedgeDescriptor = 0) {}
 };
 
                  // ===============
@@ -232,20 +273,23 @@
     // the functionality of the 'halfedge_ds' related to the facets.
 
     // TYPES
+ typedef facetS<ContainerS,HasFacetLink> facet_selector;
+ // The facet selector.
+
     typedef stored_facet<FacetBase, HasFacetLink, HalfedgeDescriptor>
                                                 facet_type;
         // The stored facet type for this facet generator.
     
- typedef container_gen<ContainerS, facet_type> ContainerGen;
+ typedef container_gen<ContainerS, facet_type> ContainerGen;
         // The container generator for this facet generator.
 
- typedef typename ContainerGen::type container_type;
+ typedef typename ContainerGen::type container_type;
         // The facet container type for this facet generator.
 
- typedef typename ContainerGen::descriptor facet_descriptor;
+ typedef typename ContainerGen::descriptor facet_descriptor;
         // The facet descriptor type for this facet generator.
 
- typedef typename ContainerGen::iterator facet_iterator;
+ typedef typename ContainerGen::iterator facet_iterator;
         // The facet iterator type for this facet generator.
 
     // DATA
@@ -278,6 +322,14 @@
     return hds.m_container.size();
 }
 
+template <typename FacetS, typename HalfedgeDescriptor, typename FacetBase>
+HalfedgeDescriptor
+halfedge(typename facet_gen<FacetS, HalfedgeDescriptor, FacetBase>::facet_descriptor const& f,
+ facet_gen<FacetS, HalfedgeDescriptor, FacetBase> const& hds) {
+ return facet_gen<FacetS, HalfedgeDescriptor, FacetBase>
+ ::ContainerGen::value(f, hds.m_container).m_facetLink;
+}
+
 } // namespace hdstl
 } // namespace boost
 

Modified: sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/facet_selectors.t.cpp
==============================================================================
--- sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/facet_selectors.t.cpp (original)
+++ sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/facet_selectors.t.cpp 2007-07-16 00:50:37 EDT (Mon, 16 Jul 2007)
@@ -50,131 +50,59 @@
 // ===========================================================================
 
 template <typename FacetGen>
-bool facet_gen_requirements() {
+bool facet_gen_requirements_void() {
     
     // Types must exist.
+ typedef typename FacetGen::facet_selector facet_selector;
+ typedef typename FacetGen::facet_descriptor facet_descriptor;
+ typedef typename FacetGen::facet_iterator facet_iterator;
+ typedef typename FacetGen::facet_type facet_type;
+ typedef typename FacetGen::container_type container_type;
+
+ facet_type fa(1);
+ facet_type fb(2);
+ facet_type fc(3);
+ facet_type fd(4);
+ facet_type array[] = { fa, fb, fc, fd }; (void) array;
+
+ // Contruct a facet_gen object whose container contains array.
+ // Verify that halfedges_begin(), halfedges_end(), and num_facets() work.
+ // Access the facets and, if the has_facet_links is set, check that the
+ // halfedge() works.
+ // ... TODO
+
+ return true;
+}
+
+template <typename FacetGen, typename Base>
+bool facet_gen_requirements() {
+
+ typedef typename FacetGen::facet_selector facet_selector;
     typedef typename FacetGen::facet_descriptor facet_descriptor;
     typedef typename FacetGen::facet_iterator facet_iterator;
- typedef typename FacetGen::facet_type facet_type;
+ typedef typename FacetGen::facet_type facet_type;
     typedef typename FacetGen::container_type container_type;
 
- facet_type array[] = { 0, 1, 2, 3 };
- container_type container(array, array + 4);
+ facet_type fa(1, Base(1));
+ facet_type fb(2, Base(2));
+ facet_type fc(3, Base(3));
+ facet_type fd(4, Base(4));
+ facet_type array[] = { fa, fb, fc, fd }; (void) array;
     
- // Value type of iterator must be a descriptor.
- facet_iterator begin = ContainerGen.container_begin(container);
- facet_descriptor theBegin = *begin;
+ // Same checks as before:
+ BOOST_CHECK(( facet_gen_requirements_void<FacetGen>() ));
+
+ // Plus: get the base back from the facets and making sure it matches.
+ // ... TODO
 
     return true;
 }
+
 // ===========================================================================
 // USAGE EXAMPLE
 // ===========================================================================
 
-///Usage
-///-----
-// Suppose we want a data structure 'ElementCollection' containing instances of
-// a custom 'Element' type, stored in a container chosen by a selector given as
-// template parameter. To make this picture more concrete, let us pick an
-// implementation:
-//..
- struct Element {
- int userId;
- std::string familyName;
- int securityLevel;
- Element(int uId, std::string name, int level)
- : userId(uId), familyName(name), securityLevel(level) {}
- };
- bool operator<(const Element& lhs, const Element& rhs) {
- return lhs.userId < rhs.userId;
- }
-//..
-// We can implement 'ElementCollection' using the 'container_gen' facility as
-// follows. We purposely keep the de
-//..
- template <typename FacetS>
- class ElementCollection {
- // This class stores and gives access to a collection of 'Element'
- // objects, using the container selected by the specified 'FacetS'
- // selector.
-
- public:
- // TYPES
- typedef container_gen<FacetS, Element> container_generator;
- typedef typename container_generator::type container_type;
- typedef typename container_generator::descriptor descriptor;
- typedef typename container_generator::iterator iterator;
-
- private:
- // DATA
- container_type m_collection;
-
- public:
- // CREATORS
- ElementCollection() {}
- // Create an empty collection of 'Element' objects.
-
- template <typename Iterator>
- ElementCollection(Iterator elementBegin, Iterator elementEnd)
- // Create a collection of 'Element' objects initially containing
- // the objects in the specified range '[elementBegin, elementEnd)'.
- : m_collection(elementBegin, elementEnd) {}
-
- // MANIPULATORS
- iterator begin() { return container_generator::container_begin(m_collection); }
- // Return an iterator pointing to the beginning of this collection.
-
- iterator end() { return container_generator::container_end(m_collection); }
- // Return an iterator pointing past the end of this collection.
-
- container_type& theContainer() { return m_collection; }
- // Return the modifiable container underlying this collection.
-
- // ACCESSORS
- const container_type& theContainer() const { return m_collection; }
- // Return the non-modifiable container underlying this collection.
- };
-//..
-// We can now use the collection as follows. First let us create the
-// individual elements:
-//..
- bool usageExample() {
-
-
- Element george(632, "Harrison", +78);
- Element john (834, "Lennon", +255);
- Element paul (932, "McCartney", +126);
- Element ringo (1432, "Starr", +123);
- Element theBeatles[] = { george, john, paul, ringo };
-//..
-// We can use a collection as a searchable set:
-//..
- ElementCollection<setS> setCollection(theBeatles, theBeatles + 4);
- Element unknown(843, "Unkown", +0);
- BOOST_CHECK(( setCollection.theContainer().find(unknown) == setCollection.end() ));
- BOOST_CHECK(( setCollection.theContainer().find(john)->familyName == "Lennon" ));
-//..
-// and access the iterators of the collection (here identical to the
-// iterators of the container):
-//..
- BOOST_CHECK(( setCollection.begin()->familyName == "Harrison" ));
- BOOST_CHECK(( (--setCollection.end())->familyName == "Starr" ));
-//..
-// or we can use the collection as an indexed array:
-//..
- ElementCollection<vecS> vectorCollection(theBeatles, theBeatles + 4);
- BOOST_CHECK(( vectorCollection.theContainer()[1].familyName == "Lennon" ));
- BOOST_CHECK(( vectorCollection.theContainer()[3].familyName == "Starr" ));
-//..
-// and access the iterators of the collection (whose value type here is the
-// descriptor, not the same as the iterators of the container):
-//..
- BOOST_CHECK( *vectorCollection.begin() == 0 );
- BOOST_CHECK( *vectorCollection.end() == 4 );
-
- return true;
- }
-//..
+// The usage example is the component itself.
 
 // ===========================================================================
 // BOOST TEST APPARATUS
@@ -185,10 +113,21 @@
     BOOST_CHECK(( selection_requirements(noFacetS()) ));
     BOOST_CHECK(( selection_requirements(facetS<listS,true>()) ));
     BOOST_CHECK(( selection_requirements(facetS<listS,false>()) ));
+ BOOST_CHECK(( facet_gen_requirements_void<facet_gen<facetS<listS,false>, int, void> >() ));
+ BOOST_CHECK(( facet_gen_requirements<facet_gen<facetS<listS,false>, int, int>, int >() ));
+ // BOOST_CHECK(( facet_gen_requirements<facet_gen<facetS<listS,false>, int, custom_facet_base> >() ));
+ BOOST_CHECK(( facet_gen_requirements_void<facet_gen<facetS<listS,true>, int, void> >() ));
+ BOOST_CHECK(( facet_gen_requirements<facet_gen<facetS<listS,true>, int, int>, int >() ));
+ // BOOST_CHECK(( facet_gen_requirements<facet_gen<facetS<listS,true>, int, custom_facet_base> >() ));
     
     BOOST_CHECK(( selection_requirements(facetS<vecS,true>()) ));
     BOOST_CHECK(( selection_requirements(facetS<vecS,false>()) ));
- //BOOST_CHECK(( facet_gen_requirements<facet_gen<facetS<vecS,false>, int, void> >() ));
+ BOOST_CHECK(( facet_gen_requirements_void<facet_gen<facetS<vecS,false>, int, void> >() ));
+ BOOST_CHECK(( facet_gen_requirements<facet_gen<facetS<vecS,false>, int, int>, int >() ));
+ // BOOST_CHECK(( facet_gen_requirements<facet_gen<facetS<vecS,false>, int, custom_facet_base> >() ));
+ BOOST_CHECK(( facet_gen_requirements_void<facet_gen<facetS<vecS,true>, int, void> >() ));
+ BOOST_CHECK(( facet_gen_requirements<facet_gen<facetS<vecS,true>, int, int>, int >() ));
+ // BOOST_CHECK(( facet_gen_requirements<facet_gen<facetS<vecS,true>, int, custom_facet_base> >() ));
    
     //BOOST_CHECK(( usageExample() ));
     


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk