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