- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# bmig_support.hxx

    00001 // boost_support.hxx: this file is part of the Vaucanson project.
    00002 //
    00003 // Vaucanson, a generic library for finite state machines.
    00004 //
    00005 // Copyright (C) 2007, 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 VCSN_AUTOMATA_IMPLEMENTATION_BMIG_BMIG_SUPPORT_HXX
    00018 # define VCSN_AUTOMATA_IMPLEMENTATION_BMIG_BMIG_SUPPORT_HXX
    00019
    00020 # include <vaucanson/automata/implementation/bmig/bmig_support.hh>
    00021
    00022 namespace vcsn
    00023 {
    00024   namespace misc
    00025   {
    00026     //Specialization for std::vector<boost::shared_ptr<std::size_t> >
    00027     inline
    00028     SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::SupportIterator (const container_t* c,
    00029                                                                                   int i)
    00030       : current_(i), container_size_(c->size()), container_(c)
    00031     {}
    00032
    00033     inline
    00034     SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::handler_t
    00035     SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::operator* () const
    00036     {
    00037       return handler_t((*container_)[current_]);
    00038     }
    00039
    00040     inline
    00041     SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >&
    00042     SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::operator++ ()
    00043     {
    00044       if (container_->size() == container_size_)
    00045         ++current_;
    00046       else
    00047         container_size_ = container_->size();
    00048       return *this;
    00049     }
    00050
    00051     inline
    00052     SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >&
    00053     SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::operator-- ()
    00054     {
    00055       if (container_->size() == container_size_)
    00056         --current_;
    00057       else
    00058         container_size_ = container_->size();
    00059       return *this;
    00060     }
    00061
    00062     inline
    00063     SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >
    00064     SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::operator++ (int)
    00065     {
    00066       SupportIterator<std::vector<boost::shared_ptr<std::size_t> > > tmp = *this;
    00067       ++(*this);
    00068       return tmp;
    00069     }
    00070
    00071     inline
    00072     bool
    00073     SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::operator!= (const SupportIterator& o) const
    00074     {
    00075       return o.current_ != current_;
    00076     }
    00077
    00078     inline
    00079     bool
    00080     SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::operator== (const SupportIterator& o) const
    00081     {
    00082       return ! (*this != o);
    00083     }
    00084
    00085     //Specialization for std::vector<boost::shared_ptr<std::size_t> >
    00086     inline
    00087     SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::SupportIterator (const container_t* c, set_iterator it)
    00088       : current_(it), container_size_(c->size()), container_(c)
    00089     {}
    00090
    00091     inline
    00092     SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::handler_t
    00093     SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::operator* () const
    00094     {
    00095       return handler_t(*current_);
    00096     }
    00097
    00098     inline
    00099     SupportIterator<std::set<boost::shared_ptr<std::size_t> > >&
    00100     SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::operator++ ()
    00101     {
    00102       if (container_->size() == container_size_)
    00103         ++current_;
    00104       else
    00105         container_size_ = container_->size();
    00106       return *this;
    00107     }
    00108
    00109     inline
    00110     SupportIterator<std::set<boost::shared_ptr<std::size_t> > >&
    00111     SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::operator-- ()
    00112     {
    00113       if (container_->size() == container_size_)
    00114         --current_;
    00115       else
    00116         container_size_ = container_->size();
    00117       return *this;
    00118     }
    00119
    00120     inline
    00121     SupportIterator<std::set<boost::shared_ptr<std::size_t> > >
    00122     SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::operator++ (int)
    00123     {
    00124       SupportIterator<std::set<boost::shared_ptr<std::size_t> > > tmp = *this;
    00125       ++(*this);
    00126       return tmp;
    00127     }
    00128
    00129     inline
    00130     bool
    00131     SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::operator!= (const SupportIterator& o) const
    00132     {
    00133       return o.current_ != current_;
    00134     }
    00135
    00136     inline
    00137     bool
    00138     SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::operator== (const SupportIterator& o) const
    00139     {
    00140       return ! (*this != o);
    00141     }
    00142
    00143     /*------------------.
    00144     | SupportIterator.  |
    00145     `------------------*/
    00146
    00147     //Specialization for vcsn::bmig::InitialContainer.
    00148     template <typename U, typename HState>
    00149     SupportIterator<vcsn::bmig::InitialContainer<U, HState> >
    00150     ::SupportIterator (const container_t* c, container_iterator i)
    00151       : container_ (c)
    00152     {
    00153       if (i != c->end())
    00154       {
    00155         i_ = i++;
    00156         next_ = i;
    00157       }
    00158       else
    00159       {
    00160         i_ = i;
    00161         next_ = i;
    00162       }
    00163     }
    00164
    00165     template <typename U, typename HState>
    00166     typename SupportIterator<vcsn::bmig::InitialContainer<U, HState> >::handler_t
    00167     SupportIterator<vcsn::bmig::InitialContainer<U, HState> >::operator* () const
    00168     {
    00169       return handler_t(i_->first);
    00170     }
    00171
    00172     template <typename U, typename HState>
    00173     SupportIterator<vcsn::bmig::InitialContainer<U, HState> >&
    00174     SupportIterator<vcsn::bmig::InitialContainer<U, HState> >::operator++ ()
    00175     {
    00176       if (next_ != container_->end())
    00177         i_ = next_++;
    00178       else
    00179         i_ = next_;
    00180       return *this;
    00181     }
    00182
    00183     template <typename U, typename HState>
    00184     SupportIterator<vcsn::bmig::InitialContainer<U, HState> >
    00185     SupportIterator<vcsn::bmig::InitialContainer<U, HState> >::operator++ (int)
    00186     {
    00187       SupportIterator<vcsn::bmig::InitialContainer<U, HState> > tmp = *this;
    00188       ++(*this);
    00189       return tmp;
    00190     }
    00191
    00192     template <typename U, typename HState>
    00193     bool
    00194     SupportIterator<vcsn::bmig::InitialContainer<U, HState> >::operator!= (const SupportIterator& o) const
    00195     {
    00196       return o.i_ != i_;
    00197     }
    00198
    00199     template <typename U, typename HState>
    00200     bool
    00201     SupportIterator<vcsn::bmig::InitialContainer<U, HState> >::operator== (const SupportIterator& o) const
    00202     {
    00203       return ! (*this != o);
    00204     }
    00205
    00206
    00207
    00208     /*----------.
    00209     | Support.  |
    00210     `----------*/
    00211
    00213     template <class U, class HState>
    00214     Support<vcsn::bmig::InitialContainer<U, HState> >::Support (const Support& s)
    00215       : m_ (s.m_)
    00216     {
    00217     }
    00218
    00219     template <class U, class HState>
    00220     Support<vcsn::bmig::InitialContainer<U, HState> >::Support (const Support::container_t& m)
    00221       : m_ (m)
    00222     {
    00223     }
    00224
    00225     template <class U, class HState>
    00226     unsigned
    00227     Support<vcsn::bmig::InitialContainer<U, HState> >::size () const
    00228     {
    00229       return m_.size ();
    00230     }
    00231
    00232     template <class U, class HState>
    00233     typename Support<vcsn::bmig::InitialContainer<U, HState> >::iterator
    00234     Support<vcsn::bmig::InitialContainer<U, HState> >::find (const HState& k) const
    00235     {
    00236       return m_.find (k.value());
    00237     }
    00238
    00239     template <class U, class HState>
    00240     bool
    00241     Support<vcsn::bmig::InitialContainer<U, HState> >::empty () const
    00242     {
    00243       return m_.empty ();
    00244     }
    00245
    00246     template <class U, class HState>
    00247     typename Support<vcsn::bmig::InitialContainer<U, HState> >::iterator
    00248     Support<vcsn::bmig::InitialContainer<U, HState> >::begin () const
    00249     {
    00250       return iterator (&m_, m_.begin ());
    00251     }
    00252
    00253     template <class U, class HState>
    00254     typename Support<vcsn::bmig::InitialContainer<U, HState> >::iterator
    00255     Support<vcsn::bmig::InitialContainer<U, HState> >::end () const
    00256     {
    00257       return iterator (&m_, m_.end ());
    00258     }
    00259
    00260     template <class U, class HState>
    00261     typename Support<vcsn::bmig::InitialContainer<U, HState> >::handler_t
    00262     Support<vcsn::bmig::InitialContainer<U, HState> >::back () const
    00263     {
    00264       return handler_t(*max_element (begin (), end ()));
    00265     }
    00266
    00267   }
    00268 }
    00269
    00270 namespace vcsn
    00271 {
    00272   namespace misc
    00273   {
    00274
    00275   /*----------.
    00276   | Support.  |
    00277   `----------*/
    00278
    00280     inline
    00281     Support<std::vector<boost::shared_ptr<std::size_t> > >
    00282     ::Support (const std::vector<boost::shared_ptr<std::size_t> >& m)
    00283       : m_ (m)
    00284     {
    00285     }
    00286
    00287     inline
    00288     unsigned
    00289     Support<std::vector<boost::shared_ptr<std::size_t> > >
    00290     ::size () const
    00291     {
    00292       return m_.size ();
    00293     }
    00294
    00295     inline
    00296     Support<std::vector<boost::shared_ptr<std::size_t> > >::iterator
    00297     Support<std::vector<boost::shared_ptr<std::size_t> > >
    00298     ::find (const handler<state_h, boost::shared_ptr<std::size_t>  >& k) const
    00299     {
    00300       if (k < m_.size())
    00301         return iterator(&m_, k);
    00302       else
    00303         return iterator(&m_, m_.size());
    00304     }
    00305
    00306     inline
    00307     bool
    00308     Support<std::vector<boost::shared_ptr<std::size_t> > >
    00309     ::empty () const
    00310     {
    00311       return m_.empty ();
    00312     }
    00313
    00314     inline
    00315     Support<std::vector<boost::shared_ptr<std::size_t> > >::const_iterator
    00316     Support<std::vector<boost::shared_ptr<std::size_t> > >
    00317     ::begin () const
    00318     {
    00319       return iterator (&m_, 0);
    00320     }
    00321
    00322     inline
    00323     Support<std::vector<boost::shared_ptr<std::size_t> > >::const_iterator
    00324     Support<std::vector<boost::shared_ptr<std::size_t> > >
    00325     ::end () const
    00326     {
    00327       return iterator (&m_, m_.size());
    00328     }
    00329
    00330     inline
    00331     Support<std::vector<boost::shared_ptr<std::size_t> > >::handler_t
    00332     Support<std::vector<boost::shared_ptr<std::size_t> > >
    00333     ::back () const
    00334     {
    00335       return handler_t(m_.back());
    00336     }
    00337
    00339     inline
    00340     Support<std::set<boost::shared_ptr<std::size_t> > >
    00341     ::Support (const std::set<boost::shared_ptr<std::size_t> >& m)
    00342       : m_ (m)
    00343     {
    00344     }
    00345
    00346     inline
    00347     unsigned
    00348     Support<std::set<boost::shared_ptr<std::size_t> > >
    00349     ::size () const
    00350     {
    00351       return m_.size ();
    00352     }
    00353
    00354     inline
    00355     Support<std::set<boost::shared_ptr<std::size_t> > >::iterator
    00356     Support<std::set<boost::shared_ptr<std::size_t> > >
    00357     ::find (const handler<state_h, boost::shared_ptr<std::size_t>  >& k) const
    00358     {
    00359         return iterator(&m_, m_.find(k.value()));
    00360     }
    00361
    00362     inline
    00363     bool
    00364     Support<std::set<boost::shared_ptr<std::size_t> > >
    00365     ::empty () const
    00366     {
    00367       return m_.empty ();
    00368     }
    00369
    00370     inline
    00371     Support<std::set<boost::shared_ptr<std::size_t> > >::const_iterator
    00372     Support<std::set<boost::shared_ptr<std::size_t> > >
    00373     ::begin () const
    00374     {
    00375       return iterator (&m_, m_.begin());
    00376     }
    00377
    00378     inline
    00379     Support<std::set<boost::shared_ptr<std::size_t> > >::const_iterator
    00380     Support<std::set<boost::shared_ptr<std::size_t> > >
    00381     ::end () const
    00382     {
    00383       return iterator (&m_, m_.end());
    00384     }
    00385
    00386     inline
    00387     Support<std::set<boost::shared_ptr<std::size_t> > >::handler_t
    00388     Support<std::set<boost::shared_ptr<std::size_t> > >
    00389     ::back () const
    00390     {
    00391       //FIXME Maybe wrong! Compare pointers instead of id.
    00392       return handler_t(*max_element (begin (), end ()));
    00393     }
    00394
    00395
    00396   }
    00397 }
    00398
    00399
    00400 #endif // !VCSN_AUTOMATA_IMPLEMENTATION_BMIG_BMIG_SUPPORT_HXX
    00401