iterator.hxx

00001 // iterator.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2008 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00016 //
00017 #ifndef VAUCANSON_AUTOMATA_IMPLEMENTATION_BMIG_ITERATOR_HXX
00018 # define VAUCANSON_AUTOMATA_IMPLEMENTATION_BMIG_ITERATOR_HXX
00019 
00020 # include <vaucanson/automata/implementation/bmig_graph_impl.hh>
00021 # include <vaucanson/automata/implementation/bmig/iterator.hh>
00022 
00023 namespace vcsn
00024 {
00025   namespace bmig
00026   {
00027 
00028     // Syntactic sugar
00029 # define BMIG_ITERATOR_TPARAM template <typename Graph, typename Handler, typename I>
00030 # define BMIG_ITERATOR DeltaConstIterator<Graph, Handler, I>
00031 
00032     BMIG_ITERATOR_TPARAM
00033     BMIG_ITERATOR::DeltaConstIterator(const graph_type& g,
00034                                       typename graph_type::hstate_t s)
00035       : graph_(g)
00036     {
00037       range_type        tmp = graph_.deltai(s, iterator_type());
00038       i_ = tmp.first;
00039       end_ = tmp.second;
00040     }
00041 
00042     BMIG_ITERATOR_TPARAM
00043     BMIG_ITERATOR::~DeltaConstIterator()
00044     { }
00045 
00046     BMIG_ITERATOR_TPARAM
00047     void
00048     BMIG_ITERATOR::next()
00049     {
00050       ++i_;
00051     }
00052 
00053     BMIG_ITERATOR_TPARAM
00054     bool
00055     BMIG_ITERATOR::done() const
00056     {
00057       return i_ == end_;
00058     }
00059 
00060     /*
00061     ** Helper for the operator*
00062     ** Used to retrieve the underlying data based on the iterator type
00063     ** without having to specialize the DeltaConstIterator for each type.
00064     */
00065     template <typename IteratorType>
00066     typename IteratorType::data_type
00067     op_get_delta_iterator_value(const IteratorType&,
00068                                 const typename IteratorType::iterator_type& i);
00069 
00070 # define BMIG_DCI(Handler, Kind)                        \
00071     DeltaConstIterator<Graph,                           \
00072                        typename Graph::Handler,         \
00073                        typename Graph::Kind##_iterator>
00074     template <typename Graph>
00075     typename BMIG_DCI(hstate_t, src)::data_type
00076     op_get_delta_iterator_value(const BMIG_DCI(hstate_t, src)&,
00077                                 const Graph&,
00078                                 const typename BMIG_DCI(hstate_t, src)::iterator_type& i)
00079     {
00080       return typename BMIG_DCI(hstate_t, src)::data_type(i->to_);
00081     }
00082     template <typename Graph>
00083     typename BMIG_DCI(hstate_t, dst)::data_type
00084     op_get_delta_iterator_value(const BMIG_DCI(hstate_t, dst)&,
00085                                 const Graph&,
00086                                 const typename BMIG_DCI(hstate_t, dst)::iterator_type& i)
00087     {
00088       return typename BMIG_DCI(hstate_t, dst)::data_type(i->from_);
00089     }
00090 # undef BMIG_DCI
00091 # define BMIG_DCI(Handler, Kind)                        \
00092     DeltaConstIterator<Graph,                           \
00093                        typename Graph::Handler,         \
00094                        T>
00095     template <typename Graph, typename T>
00096     typename BMIG_DCI(htransition_t, T)::data_type
00097     op_get_delta_iterator_value(const BMIG_DCI(htransition_t, T)&,
00098                                 const Graph& g,
00099                                 const typename BMIG_DCI(htransition_t, T)::iterator_type& i)
00100     {
00101       return g.get_htransition(i);
00102     }
00103 # undef BMIG_DCI
00104 
00105 
00106     BMIG_ITERATOR_TPARAM
00107     typename BMIG_ITERATOR::data_type
00108     BMIG_ITERATOR::operator*() const
00109     {
00110       return op_get_delta_iterator_value(*this, graph_, i_);
00111     }
00112 
00113 # undef BMIG_ITERATOR_TPARAM
00114 # undef BMIG_ITERATOR
00115 
00116   } // End of namespace bmig
00117 
00118 } // End of namespace vcsn
00119 
00120 #endif // ! VAUCANSON_AUTOMATA_IMPLEMENTATION_BMIG_ITERATOR_HXX

Generated on Thu Oct 9 20:22:35 2008 for Vaucanson by  doxygen 1.5.1