• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

graph_iter_base.hh

00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_UTIL_INTERNAL_GRAPH_ITER_BASE_HH
00027 # define MLN_UTIL_INTERNAL_GRAPH_ITER_BASE_HH
00028 
00035 
00036 # include <mln/core/concept/iterator.hh>
00037 # include <mln/core/concept/proxy.hh>
00038 
00039 
00040 namespace mln
00041 {
00042 
00043   namespace internal
00044   {
00045 
00046     template <typename G, typename Elt, typename E>
00047     class graph_iter_base
00048       : public Proxy< E >,
00049         public internal::proxy_impl< const Elt&, E >
00050     {
00051       public:
00055         bool is_valid() const;
00057         void invalidate();
00058 
00060         void start();
00061 
00063         void next();
00064 
00066         typename Elt::id_t id() const;
00067 
00069         operator typename Elt::id_t() const;
00070 
00073         operator typename Elt::id_value_t() const;
00074 
00076         operator const Elt&() const;
00078 
00080         const Elt& subj_();
00081 
00083         const Elt& p_hook_() const;
00084 
00085       protected:
00086         graph_iter_base(const G& g);
00087 
00088         Elt p_;
00089     };
00090 
00091 
00092 
00093 # ifndef MLN_INCLUDE_ONLY
00094 
00095     template <typename G, typename Elt, typename E>
00096     inline
00097     graph_iter_base<G, Elt, E>::graph_iter_base(const G& g)
00098       : p_(Elt(g))
00099     {
00100       invalidate();
00101     }
00102 
00103     template <typename G, typename Elt, typename E>
00104     inline
00105     bool
00106     graph_iter_base<G, Elt, E>::is_valid() const
00107     {
00108       return p_.is_valid();
00109     }
00110 
00111     template <typename G, typename Elt, typename E>
00112     inline
00113     void
00114     graph_iter_base<G, Elt, E>::invalidate()
00115     {
00116       p_.invalidate();
00117       mln_postcondition(! is_valid());
00118     }
00119 
00120     template <typename G, typename Elt, typename E>
00121     inline
00122     void
00123     graph_iter_base<G, Elt, E>::start()
00124     {
00125       p_.update_id(exact(this)->start_id_());
00126     }
00127 
00128     template <typename G, typename Elt, typename E>
00129     inline
00130     void
00131     graph_iter_base<G, Elt, E>::next()
00132     {
00133       mln_precondition(is_valid());
00134       p_.update_id(exact(this)->next_id_());
00135     }
00136 
00137     template <typename G, typename Elt, typename E>
00138     inline
00139     typename Elt::id_t
00140     graph_iter_base<G, Elt, E>::id() const
00141     {
00142       return p_.id();
00143     }
00144 
00145     template <typename G, typename Elt, typename E>
00146     inline
00147     graph_iter_base<G, Elt, E>::operator typename Elt::id_t() const
00148     {
00149       return p_.id();
00150     }
00151 
00152     template <typename G, typename Elt, typename E>
00153     inline
00154     graph_iter_base<G, Elt, E>::operator typename Elt::id_value_t() const
00155     {
00156       return p_.id();
00157     }
00158 
00159     template <typename G, typename Elt, typename E>
00160     inline
00161     graph_iter_base<G, Elt, E>::operator const Elt&() const
00162     {
00163       return p_;
00164     }
00165 
00166     template <typename G, typename Elt, typename E>
00167     inline
00168     const Elt&
00169     graph_iter_base<G, Elt, E>::subj_()
00170     {
00171       return p_;
00172     }
00173 
00174     template <typename G, typename Elt, typename E>
00175     inline
00176     const Elt&
00177     graph_iter_base<G, Elt, E>::p_hook_() const
00178     {
00179       return p_;
00180     }
00181 
00182 # endif // ! MLN_INCLUDE_ONLY
00183 
00184   } // end of namespace mln::internal
00185 
00186 } // end of namespace mln
00187 
00188 #endif // ! MLN_UTIL_INTERNAL_GRAPH_ITER_BASE_HH

Generated on Tue Oct 4 2011 15:23:50 for Milena (Olena) by  doxygen 1.7.1