Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
p_edges_psite.hh
1 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_CORE_SITE_SET_P_EDGES_PSITE_HH
27 # define MLN_CORE_SITE_SET_P_EDGES_PSITE_HH
28 
32 
33 # include <mln/core/internal/graph_psite_base.hh>
34 # include <mln/util/edge.hh>
35 
36 
37 namespace mln
38 {
39 
40  // Forward declaration.
41  template <typename G, typename F> class p_edges;
42  namespace util { template <typename G> class vertex; }
43  namespace internal { template <typename T, typename E> struct subject_impl; }
44 
45 
46  template <typename G, typename F>
47  class p_edges_psite :
48  public internal::graph_psite_base< p_edges<G,F>, p_edges_psite<G,F> >
49  {
50  typedef p_edges_psite<G,F> self_;
51  typedef internal::graph_psite_base<p_edges<G,F>, self_> super_;
52 
53  public:
54 
55  typedef p_edges<G,F> target_t;
56 
59  p_edges_psite();
60  p_edges_psite(const p_edges<G,F>& s);
61  p_edges_psite(const p_edges<G,F>& s, unsigned);
63 
67  const util::edge<G>& e() const;
68  util::vertex<G> v1() const;
69  util::vertex<G> v2() const;
71  };
72 
73 
74 
75  template <typename G, typename F>
76  bool
77  operator==(const p_edges_psite<G,F>& lhs, const p_edges_psite<G,F>& rhs);
78 
79  template <typename G, typename F>
80  bool
81  operator!=(const p_edges_psite<G,F>& lhs, const p_edges_psite<G,F>& rhs);
82 
83  template <typename G, typename F>
84  bool
85  operator<(const p_edges_psite<G,F>& lhs, const p_edges_psite<G,F>& rhs);
86 
87 
88 
89  namespace internal
90  {
91 
93 
94  template <typename G, typename F, typename E>
95  struct subject_impl< const p_edges_psite<G,F>&, E >
96  : subject_impl< const graph_psite_base< p_edges<G,F>,
97  p_edges_psite<G,F> >&, E >
98  {
99  const util::edge<G>& e() const;
100  util::vertex<G> v1() const;
101  util::vertex<G> v2() const;
102 
103  private:
104  const E& exact_() const;
105  };
106 
107  template <typename G, typename F, typename E>
108  struct subject_impl< p_edges_psite<G,F>&, E >
109  : subject_impl< const p_edges_psite<G,F>&, E >,
110  subject_impl< graph_psite_base< p_edges<G,F>,
111  p_edges_psite<G,F> >&, E >
112  {
113  };
114 
115  } // end of namespace mln::internal
116 
117 
118 
119 
120 # ifndef MLN_INCLUDE_ONLY
121 
122  template <typename G, typename F>
123  inline
124  p_edges_psite<G, F>::p_edges_psite()
125  {
126  }
127 
128  template <typename G, typename F>
129  inline
130  p_edges_psite<G, F>::p_edges_psite(const p_edges<G,F>& s)
131  : super_(s)
132  {
133  }
134 
135  template <typename G, typename F>
136  inline
137  p_edges_psite<G, F>::p_edges_psite(const p_edges<G,F>& s, unsigned id)
138  : super_(s, id)
139  {
140  }
141 
142  template <typename G, typename F>
143  inline
144  const util::edge<G>&
145  p_edges_psite<G, F>::e() const
146  {
147  return this->elt_;
148  }
149 
150  template <typename G, typename F>
151  inline
152  util::vertex<G>
153  p_edges_psite<G, F>::v1() const
154  {
155  return this->elt_.graph().vertex(this->elt_.v1());
156  }
157 
158  template <typename G, typename F>
159  inline
160  util::vertex<G>
161  p_edges_psite<G, F>::v2() const
162  {
163  return this->elt_.graph().vertex(this->elt_.v2());
164  }
165 
166 
167  /*--------------.
168  | Comparisons. |
169  `--------------*/
170 
171  template <typename G, typename F>
172  bool
173  operator==(const p_edges_psite<G,F>& lhs, const p_edges_psite<G,F>& rhs)
174  {
175  mln_assertion(lhs.target_() == rhs.target_());
176  return lhs.id() == rhs.id();
177  }
178 
179  template <typename G, typename F>
180  bool
181  operator!=(const p_edges_psite<G,F>& lhs, const p_edges_psite<G,F>& rhs)
182  {
183  mln_assertion(lhs.target_() == rhs.target_());
184  return lhs.id() != rhs.id();
185  }
186 
187  template <typename G, typename F>
188  bool
189  operator<(const p_edges_psite<G,F>& lhs, const p_edges_psite<G,F>& rhs)
190  {
191  mln_assertion(lhs.target_() == rhs.target_());
192  return lhs.id() < rhs.id();
193  }
194 
195 
196 
197  namespace internal
198  {
199 
201 
202  template <typename G, typename F, typename E>
203  inline
204  const E&
205  subject_impl< const p_edges_psite<G,F>&, E >::exact_() const
206  {
207  return internal::force_exact<const E>(*this);
208  }
209 
210  template <typename G, typename F, typename E>
211  inline
212  const util::edge<G>&
213  subject_impl< const p_edges_psite<G,F>&, E >::e() const
214  {
215  return exact_().get_subject().e();
216  }
217 
218  template <typename G, typename F, typename E>
219  inline
220  util::vertex<G>
221  subject_impl< const p_edges_psite<G,F>&, E >::v1() const
222  {
223  return exact_().get_subject().v1();
224  }
225 
226  template <typename G, typename F, typename E>
227  inline
228  util::vertex<G>
229  subject_impl< const p_edges_psite<G,F>&, E >::v2() const
230  {
231  return exact_().get_subject().v2();
232  }
233 
234  } // end of namespace mln::internal
235 
236 # endif // ! MLN_INCLUDE_ONLY
237 
238 } // end of namespace mln
239 
240 
241 #endif // ! MLN_CORE_SITE_SET_P_EDGES_PSITE_HH