From: eap Date: Tue, 10 Apr 2007 13:57:20 +0000 (+0000) Subject: PLA13330( When mesh generation does not success, trace where ) X-Git-Tag: V3_2_6pre4~36 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c03258aaf6bb57a20f1005ad03fe78f0e5616e6e;p=modules%2Fsmesh.git PLA13330( When mesh generation does not success, trace where ) add templates of map iterators --- diff --git a/src/SMDS/SMDS_SetIterator.hxx b/src/SMDS/SMDS_SetIterator.hxx index 05fa6c046..9272b979e 100644 --- a/src/SMDS/SMDS_SetIterator.hxx +++ b/src/SMDS/SMDS_SetIterator.hxx @@ -32,13 +32,37 @@ #include "SMDS_Iterator.hxx" /////////////////////////////////////////////////////////////////////////////// -/// specific SMDS_Iterator iterating over abstract set of values like STL containers +/// Accessors to value pointed by iterator +/////////////////////////////////////////////////////////////////////////////// + +namespace SMDS { + + template + struct SimpleAccessor { + static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) *it; } + }; + + template + struct KeyAccessor { + static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->first; } + }; + + template + struct ValueAccessor { + static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->second; } + }; +} + +/////////////////////////////////////////////////////////////////////////////// +/// SMDS_Iterator iterating over abstract set of values like STL containers /// /// BE CAREFUL: iterator pointed value is static_cast'ed to VALUE /// /////////////////////////////////////////////////////////////////////////////// -template +template > class SMDS_SetIterator : public SMDS_Iterator { protected: @@ -57,11 +81,67 @@ public: virtual bool more() { return _beg != _end; } /// Return the current object and step to the next one - virtual VALUE next() { return static_cast( *_beg++ ); } + virtual VALUE next() { return ACCESOR::value( _beg++ ); } +}; +/////////////////////////////////////////////////////////////////////////////// +/// map iterators +/////////////////////////////////////////////////////////////////////////////// + +#include +/*! + * \brief iterator on values of a map + */ +template +struct SMDS_mapIterator : public SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator, + SMDS::ValueAccessor > { + typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator, + SMDS::ValueAccessor > parent_type; + SMDS_mapIterator(const M& m):parent_type(m.begin(),m.end()) {} +}; +/*! + * \brief reverse iterator on values of a map + */ +template +struct SMDS_mapReverseIterator : public SMDS_SetIterator< typename M::mapped_type, + typename M::const_reverse_iterator, + SMDS::ValueAccessor > { + typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_reverse_iterator, + SMDS::ValueAccessor > parent_type; + SMDS_mapReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {} +}; +/*! + * \brief iterator on keys of a map + */ +template +struct SMDS_mapKeyIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator, + SMDS::KeyAccessor > { + typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator, + SMDS::KeyAccessor > parent_type; + SMDS_mapKeyIterator(const M& m):parent_type(m.begin(),m.end()) {} +}; +/*! + * \brief reverse iterator on keys of a map + */ +template +struct SMDS_mapKeyReverseIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator, + SMDS::KeyAccessor > { + typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator, + SMDS::KeyAccessor > parent_type; + SMDS_mapKeyReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {} }; +/////////////////////////////////////////////////////////////////////////////// // useful specifications +/////////////////////////////////////////////////////////////////////////////// #include