Vaucanson  1.4.1
bmig_support.hh
1 // boost_support.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2007, 2008 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_AUTOMATA_IMPLEMENTATION_BMIG_BMIG_SUPPORT_HH
18 # define VCSN_AUTOMATA_IMPLEMENTATION_BMIG_BMIG_SUPPORT_HH
19 
20 # include <vaucanson/misc/support.hh>
21 # include <vaucanson/automata/implementation/bmig/initial_container.hh>
22 # include <boost/shared_ptr.hpp>
23 
24 namespace vcsn
25 {
26  namespace misc
27  {
28 
29  template <>
30  class SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >
31  {
32  public:
33  typedef boost::shared_ptr<std::size_t> data_type;
34  typedef vcsn::handler<state_h, data_type> handler_t;
35  typedef std::vector<data_type> container_t;
36  typedef container_t::const_iterator vector_iterator;
37  typedef SupportIterator<container_t> self_t;
38 
39  typedef vector_iterator::iterator_category iterator_category;
40  typedef vector_iterator::difference_type difference_type;
41  typedef data_type value_type;
42  typedef data_type* pointer;
43  typedef data_type& reference;
44 
45  SupportIterator () {}
46  SupportIterator (const container_t* c, int i);
47 
48  handler_t operator* () const;
49  self_t& operator++ ();
50  self_t& operator-- ();
51  self_t operator++ (int);
52  bool operator!= (const SupportIterator&) const;
53  bool operator== (const SupportIterator&) const;
54 
55  private:
56  int current_;
57  std::size_t container_size_;
58  const container_t* container_;
59  };
60 
62  template <>
63  class Support<std::vector<boost::shared_ptr<std::size_t> > >
64  {
65  public:
66  typedef boost::shared_ptr<std::size_t> value_type;
67  typedef vcsn::handler<state_h, value_type> handler_t;
69  typedef iterator const_iterator;
71 
72  Support (const std::vector<value_type>&);
73 
74  const_iterator begin () const;
75  const_iterator end () const;
76  unsigned size () const;
77 
78  // Find the element associated to \a k.
79  iterator find (const handler_t& k) const;
80 
82  bool empty () const;
83 
84  handler_t back () const;
85  private:
86  const std::vector<value_type>& m_;
87  };
88 
89  }
90 }
91 
93 namespace std
94 {
95  template <>
96  struct iterator_traits<vcsn::misc::SupportIterator<std::vector<boost::shared_ptr<std::size_t> > > >
97  {
98  typedef input_iterator_tag iterator_category;
99  typedef boost::shared_ptr<size_t> value_type;
100  typedef int difference_type;
101  typedef int* pointer;
102  typedef int& reference;
103  };
104 } // std
105 
106 namespace vcsn
107 {
108  namespace misc
109  {
110 
111  template <>
112  class SupportIterator<std::set<boost::shared_ptr<std::size_t> > >
113  {
114  public:
115  typedef boost::shared_ptr<std::size_t> data_type;
116  typedef vcsn::handler<state_h, data_type> handler_t;
117  typedef std::set<data_type> container_t;
118  typedef container_t::const_iterator set_iterator;
119  typedef SupportIterator<container_t> self_t;
120 
121  typedef set_iterator::iterator_category iterator_category;
122  typedef set_iterator::difference_type difference_type;
123  typedef data_type value_type;
124  typedef data_type* pointer;
125  typedef data_type& reference;
126 
127  SupportIterator () {}
128  SupportIterator (const container_t* c, set_iterator it);
129 
130  handler_t operator* () const;
131  self_t& operator++ ();
132  self_t& operator-- ();
133  self_t operator++ (int);
134  bool operator!= (const SupportIterator&) const;
135  bool operator== (const SupportIterator&) const;
136 
137  private:
138  set_iterator current_;
139  std::size_t container_size_;
140  const container_t* container_;
141  };
142 
144  template <>
145  class Support<std::set<boost::shared_ptr<std::size_t> > >
146  {
147  public:
148  typedef boost::shared_ptr<std::size_t> value_type;
149  typedef vcsn::handler<state_h, value_type> handler_t;
151  typedef iterator const_iterator;
153 
154  Support (const std::set<value_type>&);
155 
156  const_iterator begin () const;
157  const_iterator end () const;
158  unsigned size () const;
159 
160  // Find the element associated to \a k.
161  iterator find (const handler_t& k) const;
162 
164  bool empty () const;
165 
166  handler_t back () const;
167  private:
168  const std::set<value_type>& m_;
169  };
170 
171  }
172 }
173 
175 namespace std
176 {
177  template <>
178  struct iterator_traits<vcsn::misc::SupportIterator<std::set<boost::shared_ptr<std::size_t> > > >
179  {
180  typedef input_iterator_tag iterator_category;
181  typedef boost::shared_ptr<std::size_t> value_type;
182  typedef int difference_type;
183  typedef int* pointer;
184  typedef int& reference;
185  };
186 } // std
187 
188 namespace vcsn
189 {
190  namespace misc
191  {
192  template <typename U, typename HState>
193  class SupportIterator<vcsn::bmig::InitialContainer<U, HState> >
194  {
195  public:
196  typedef typename vcsn::bmig::InitialContainer<U, HState>::Type container_t;
197  typedef typename container_t::key_type key_type;
198  typedef typename container_t::const_iterator container_iterator;
199  typedef SupportIterator<vcsn::bmig::InitialContainer<U, HState> > self_t;
200  typedef vcsn::handler<state_h, HState> handler_t;
201  typedef typename container_iterator::iterator_category iterator_category;
202  typedef typename container_iterator::difference_type difference_type;
203  typedef key_type value_type;
204  typedef key_type* pointer;
205  typedef key_type& reference;
206 
207  SupportIterator () {}
208  SupportIterator (const container_t* c, container_iterator);
209 
210  handler_t operator* () const;
211  self_t& operator++ ();
212  self_t& operator-- ();
213  self_t operator++ (int);
214  bool operator!= (const SupportIterator&) const;
215  bool operator== (const SupportIterator&) const;
216 
217 
218  private:
219  container_iterator i_;
220  container_iterator next_;
221  const container_t* container_;
222  };
223 
224 
226  template <typename U, typename HState>
227  class Support<vcsn::bmig::InitialContainer<U, HState> >
228  {
229  public:
230  typedef typename vcsn::bmig::InitialContainer<U, HState>::Type container_t;
233  typedef vcsn::handler<state_h, HState> handler_t;
234 
235  Support (const container_t&);
236  Support (const Support&);
237 
238  iterator begin () const;
239  iterator end () const;
240  unsigned size () const;
241 
242  // Find the element associated to \a k.
243  iterator find (const HState& k) const;
244 
246  bool empty () const;
247 
248  handler_t back () const;
249  private:
250  const container_t& m_;
251  };
252 
253  }
254 }
255 
257 namespace std
258 {
259  template <class T, class U>
260  struct iterator_traits<vcsn::misc::SupportIterator<std::vector<vcsn::handler<T, U> > > >
261  {
262  typedef input_iterator_tag iterator_category;
263  typedef U value_type;
264  typedef int difference_type;
265  typedef int* pointer;
266  typedef int& reference;
267  };
268 } // std
269 
270 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
271 # include <vaucanson/automata/implementation/bmig/bmig_support.hxx>
272 # endif // VCSN_USE_INTERFACE_ONLY
273 
274 #endif // !VCSN_AUTOMATA_IMPLEMENTATION_BMIG_BMIG_SUPPORT_HH
275