dir-iter.hh

00001 // Copyright (C) 2001, 2002, 2003  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
00027 
00028 #ifndef OLENA_TOPO_INTER_PIXEL_INTERNAL_DIR_ITER_HH
00029 # define OLENA_TOPO_INTER_PIXEL_INTERNAL_DIR_ITER_HH
00030 
00031 # include <mlc/objs.hh>
00032 # include <oln/core/abstract/iter1d.hh>
00033 # include <oln/core/abstract/iter2d.hh>
00034 # include <oln/core/abstract/iter3d.hh>
00035 # include <oln/topo/inter-pixel/internal/dir.hh>
00036 
00037 namespace oln {
00038 
00039   namespace topo {
00040     namespace inter_pixel {
00041       namespace internal {
00042 
00043         template<unsigned Dim, class Exact>
00044         class dir_iter_; // fwd_decl
00045 
00046       }
00047     }
00048   }
00049 
00051   template<class Exact>
00052   struct iter_traits<topo::inter_pixel::internal::dir_iter_<1, Exact> >
00053     : public iter_traits<abstract::iter1d<Exact> >
00054   {
00055     typedef abstract::iter1d<Exact> super_type;
00056     typedef point1d point_type;
00057     typedef dpoint1d dpoint_type;
00058   };
00059 
00061   template<class Exact>
00062   struct iter_traits<topo::inter_pixel::internal::dir_iter_<2, Exact> >
00063     : public iter_traits<abstract::iter2d<Exact> >
00064   {
00065     typedef abstract::iter2d<Exact> super_type;
00066     typedef point2d point_type;
00067     typedef dpoint2d dpoint_type;
00068   };
00069 
00071   template<class Exact>
00072   struct iter_traits<topo::inter_pixel::internal::dir_iter_<3, Exact> >
00073     : public iter_traits<abstract::iter3d<Exact> >
00074   {
00075     typedef abstract::iter3d<Exact> super_type;
00076     typedef point3d point_type;
00077     typedef dpoint3d dpoint_type;
00078   };
00079 
00080   namespace topo {
00081 
00082     namespace inter_pixel {
00083 
00084       namespace internal {
00085 
00086         template<unsigned Dim, class Exact>
00087         class dir_iter_ : public iter_traits<dir_iter_<Dim, Exact> >::super_type
00088         {
00089         protected:
00090           typedef typename dir_traits<Dim>::ret dir_type;
00091           typedef typename iter_traits<dir_iter_<Dim, Exact> >::super_type super_type;
00092 
00093           dir_iter_() : super_type(), cur_(this->exact().begin()), cnt_(0) {}
00094           dir_iter_(dir_type i) : super_type(), cur_(i), cnt_(0) {}
00095 
00096         public:
00097           operator dir_type()
00098           {
00099             return cur_;
00100           }
00101 
00102           dir_type
00103           to_dir() const
00104           {
00105             return cur_;
00106           }
00107 
00108           void
00109           operator++()
00110           {
00111             precondition(cnt_ != Dim * 2);
00112             cur_ = this->exact().next();
00113             ++cnt_;
00114           }
00115 
00116           bool
00117           operator==(mlc::end_type) const
00118           {
00119             return cnt_ == Dim * 2;
00120           }
00121           bool
00122           operator!=(mlc::end_type) const
00123           {
00124             return cnt_ != Dim * 2;
00125           }
00126 
00127           mlc::begin_type
00128           operator=(mlc::begin_type b)
00129           {
00130             cur_ = this->exact().begin();
00131             cnt_ = 0;
00132             return b;
00133           }
00134           mlc::end_type
00135           operator=(mlc::end_type e)
00136           {
00137             cur_ = this->exact().begin();
00138             cnt_ = Dim * 2;
00139             return e;
00140           }
00141 
00142         protected:
00143           dir_type cur_;
00144 
00145         private:
00146           unsigned cnt_;
00147         };
00148 
00149       } // end of namespace internal
00150 
00151     } // end of namespace inter_pixel
00152 
00153   } // end of namespace topo
00154 
00155 } // end of namespace oln
00156 
00157 template<unsigned Dim, class Exact>
00158 inline
00159 std::ostream&
00160 operator<<(std::ostream& o, const oln::topo::inter_pixel::internal::dir_iter_<Dim, Exact>& it)
00161 {
00162   return o << it.to_dir();
00163 }
00164 
00165 #endif // ! OLENA_TOPO_INTER_PIXEL_INTERNAL_DIR_ITER_HH

Generated on Thu Apr 15 20:13:08 2004 for Olena by doxygen 1.3.6-20040222