00001 #ifndef GRAL_BASE_GB_FACET_ITERATOR_H
00002 #define GRAL_BASE_GB_FACET_ITERATOR_H
00003
00004
00005
00006
00007 #include "Gral/Base/common-grid-basics.h"
00008
00013
00014
00027
00028
00029 template<class FacOnCellIt>
00030 class FacetIterator {
00031 public:
00032 typedef typename FacOnCellIt::grid_type grid_type;
00033 typedef grid_types<grid_type> gt;
00034 typedef FacOnCellIt local_it;
00035 typedef typename gt::CellIterator global_it;
00036
00037 typedef typename gt::Facet Facet;
00038 private:
00039
00040 global_it c;
00041 local_it fc;
00042
00043
00044 typedef FacetIterator<FacOnCellIt> self;
00045 public:
00046 typedef grid_type anchor_type;
00047 typedef Facet value_type;
00048
00049
00050
00051 FacetIterator() {}
00052 FacetIterator(grid_type const& g) { init(g.FirstCell()); }
00053 FacetIterator(const global_it& cc) { init(cc) ;}
00054
00055 private:
00056 void init(const global_it& cc)
00057 {
00058 c = cc;
00059 if(!c.IsDone())
00060 fc = (*c).FirstFacet();
00061 while(! IsDone() && ! is_new_facet())
00062 advance();
00063 }
00064
00065 public:
00066
00067
00068 inline self& operator++() {
00069 advance();
00070 while( ! IsDone() && ! is_new_facet())
00071 advance();
00072 return *this;
00073 }
00074
00075 Facet operator*() const {return (*fc);}
00076 bool IsDone() const {return (c.IsDone());}
00077
00078 const grid_type& TheGrid() {return (c.TheGrid());}
00079
00080 friend bool operator==(const self& ls, const self& rs) {
00081
00082
00083
00084
00085
00086 return ( (ls.IsDone() && rs.IsDone())
00087 || ((ls.c == rs.c) && (ls.fc == rs.fc)));
00088 }
00089 friend bool operator!=(const self& ls, const self& rs) { return !(ls == rs);}
00090 friend bool operator<(const self& ls, const self& rs) {
00091 return ((ls.c < rs.c) || ((ls.c == rs.c) && (ls.fc < rs.fc )));
00092 }
00093
00094 private:
00095
00096
00097 inline void advance();
00098
00099
00100
00101 bool is_new_facet() {
00102 return ( TheGrid().IsOnBoundary(fc)
00103 || (fc.other_cell() < c.handle()));
00104 }
00105
00106 };
00107
00108
00109 template<class FacOnCellIt>
00110 inline void
00111 FacetIterator<FacOnCellIt>::advance()
00112 {
00113 ++fc;
00114 if(fc.IsDone()) {
00115 ++c;
00116 if(! c.IsDone()){
00117 fc = (*c).FirstFacet();
00118 }
00119 }
00120 }
00121
00122
00123
00124
00125 #endif
00126