Vaucanson 1.4
sparse_interval.hh
Go to the documentation of this file.
00001 // sparse_interval.hh: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 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_MISC_SPARSE_INTERVAL_HH
00018 # define VCSN_MISC_SPARSE_INTERVAL_HH
00019 
00026 # include <iterator>
00027 # include <map>
00028 # include <string>
00029 
00030 namespace vcsn
00031 {
00032   namespace misc
00033   {
00034 
00037 
00038     template <class Integer, class ExcludedContainer>
00039     class SparseIterator
00040     {
00041       public:
00042         typedef Integer           integer_t;
00043         typedef ExcludedContainer excluded_container_t;
00044 
00045         SparseIterator (integer_t, const excluded_container_t&);
00046 
00047         SparseIterator& operator++ ();
00048         SparseIterator  operator++ (int);
00049         SparseIterator& operator-- ();
00050         SparseIterator  operator-- (int);
00051         integer_t       operator* ();
00052         bool            operator!= (const SparseIterator&) const;
00053         bool            operator== (const SparseIterator&) const;
00054         SparseIterator& operator= (const SparseIterator&);
00055 
00056       private:
00057         const excluded_container_t*     excluded_;
00058         integer_t                       integer_;
00059     };
00060 
00063   } // misc
00064 } // vcsn
00065 
00066 namespace std
00067 {
00068 
00069   template <class Integer, class ExcludedContainer>
00070   struct iterator_traits<vcsn::misc::SparseIterator
00071                          <Integer, ExcludedContainer> >
00072   {
00073       typedef input_iterator_tag iterator_category;
00074       typedef Integer              value_type;
00075       typedef int                  difference_type;
00076       typedef int*                 pointer;
00077       typedef int&                 reference;
00078   };
00079 
00080 } // std
00081 
00082 namespace vcsn
00083 {
00084   namespace misc
00085   {
00086 
00097     template <class Integer, class ExcludedContainer>
00098     class SparseInterval
00099     {
00100       public:
00101         typedef Integer         integer_t;
00102         typedef ExcludedContainer       excluded_container_t;
00103         typedef SparseIterator<integer_t, excluded_container_t> iterator;
00104         typedef SparseIterator<integer_t, excluded_container_t> const_iterator;
00105 
00106         SparseInterval (integer_t, integer_t, const excluded_container_t&);
00107         SparseInterval (const SparseInterval&);
00108 
00109         iterator begin () const;
00110         iterator end () const;
00111         unsigned size () const;
00112         integer_t max () const;
00113         std::string to_string () const;
00114 
00115       private:
00116         const excluded_container_t&     excluded_;
00117         integer_t                       from_;
00118         integer_t                       to_;
00119     };
00120 
00121 
00124   } // misc
00125 } // vcsn
00126 
00127 
00128 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00129 #  include <vaucanson/misc/sparse_interval.hxx>
00130 # endif // VCSN_USE_INTERFACE_ONLY
00131 
00132 
00133 #endif // ! VCSN_MISC_SPARSE_INTERVAL_HH