Vaucanson  1.4.1
vgraph_container.hxx
1 // vgraph_container.hxx: 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 
18 #ifndef VAUCANSON_AUTOMATA_IMPLEMENTATION_BMIG_VGRAPH_CONTAINER_HXX
19 # define VAUCANSON_AUTOMATA_IMPLEMENTATION_BMIG_VGRAPH_CONTAINER_HXX
20 
21 # include <vaucanson/automata/implementation/bmig/vgraph_container.hh>
22 
23 namespace vcsn
24 {
25  namespace bmig
26  {
27 
28  /*--------------------.
29  | Convenient macros. |
30  `--------------------*/
31 
32 # define TPARAM \
33  template<typename EdgesIterator, typename GraphData, typename HTransition>
34 
35  /*--------------------------.
36  | VGraphContainer iterator. |
37  `--------------------------*/
38 
39 # define ITERATOR \
40  VGraphContainerIterator<EdgesIterator, GraphData, HTransition>
41 
42  TPARAM
43  ITERATOR::VGraphContainerIterator(const GraphData& c,
44  EdgesIterator i)
45  : container_(c)
46  {
47  if (i != c.end())
48  {
49  it_ = i++;
50  next_ = i;
51  }
52  else
53  {
54  it_ = i;
55  next_ = i;
56  }
57  }
58 
59 
60  TPARAM
61  HTransition
62  ITERATOR::operator*() const
63  {
64  return HTransition(it_);
65  }
66 
67  TPARAM
68  bool
69  ITERATOR::operator==(const VGraphContainerIterator& v) const
70  {
71  return v.it_ == it_;
72  }
73 
74  TPARAM
75  bool
76  ITERATOR::operator!=(const VGraphContainerIterator& v) const
77  {
78  return v.it_ != it_;
79  }
80 
81  TPARAM
82  ITERATOR&
83  ITERATOR::operator++()
84  {
85  if (next_ != container_.end())
86  it_ = next_++;
87  else
88  it_ = next_;
89  return *this;
90  }
91 
92  TPARAM
93  ITERATOR
94  ITERATOR::operator++(int)
95  {
96  iterator tmp = it_;
97  if (next_ != container_.end())
98  it_ = next_++;
99  else
100  it_ = next_;
101  return ITERATOR(container_, tmp);
102  }
103 
104  /*-----------------------------------------.
105  | Container wrapper for Boost multi_index. |
106  `-----------------------------------------*/
107 
108 # define CONTAINER \
109  VGraphContainer<EdgesIterator, GraphData, HTransition>
110 
111  TPARAM
112  CONTAINER::VGraphContainer(const GraphData& g)
113  : graph_(g)
114  {
115  }
116 
117  TPARAM
118  typename CONTAINER::iterator
119  CONTAINER::begin() const
120  {
121  return ITERATOR(graph_, graph_.begin());
122  }
123 
124  TPARAM
125  typename CONTAINER::iterator
126  CONTAINER::end() const
127  {
128  return ITERATOR(graph_, graph_.end());
129  }
130 
131  TPARAM
132  size_t
133  CONTAINER::size() const
134  {
135  return graph_.size();
136  }
137 
138  }
139 }
140 
141 # undef ITERATOR
142 # undef CONTAINER
143 # undef BMIGRAPH
144 #endif // !VAUCANSON_AUTOMATA_IMPLEMENTATION_BMIG_VGRAPH_CONTAINER_HXX
145