Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
is_masked_impl_selector.hh
1 // Copyright (C) 2009, 2011 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_INTERNAL_IS_MASKED_IMPL_SELECTOR_HH
28 # define MLN_CORE_INTERNAL_IS_MASKED_IMPL_SELECTOR_HH
29 
33 
34 # include <mln/util/edge.hh>
35 
36 
37 namespace mln
38 {
39 
40  // Forward declarations.
41  template <typename G, typename F> class p_edges;
42  template <typename G, typename F> class p_vertices;
43 
44 
45 
46  namespace internal
47  {
48 
51  template <typename S, typename D, typename E>
52  struct is_masked_impl_selector
53  {
55  bool is_masked(const mln_graph_element(S)& center,
56  const mln_graph_element(S)& element) const;
57  };
58 
60  template <typename G1, typename F1, typename G2, typename F2, typename E>
61  struct is_masked_impl_selector< p_vertices<G1,F1>, p_edges<G2,F2>, E >
62  {
63  typedef p_vertices<G1,F1> S;
64 
66  bool is_masked(const mln_graph_element(S)& center,
67  const mln_graph_element(S)& element) const;
68  };
69 
71  template <typename G1, typename F1, typename G2, typename F2, typename E>
72  struct is_masked_impl_selector< p_edges<G1,F1>, p_vertices<G2,F2>, E >
73  {
74  typedef p_edges<G1,F1> S;
75 
77  bool is_masked(const mln_graph_element(S)& center,
78  const mln_graph_element(S)& element) const;
79  };
80 
81 
82 # ifndef MLN_INCLUDE_ONLY
83 
84 
85  template <typename S, typename I, typename E>
86  inline
87  bool
88  is_masked_impl_selector<S,I,E>::is_masked(const mln_graph_element(S)& center,
89  const mln_graph_element(S)& element) const
90  {
91  (void) center;
92  E& iter = internal::force_exact<E>(*this);
93  return ! iter.target_()->mask()(element.id());
94  }
95 
96 
97  template <typename G1, typename F1, typename G2, typename F2, typename E>
98  inline
99  bool
100  is_masked_impl_selector< p_vertices<G1,F1>, p_edges<G2,F2>, E >
101  ::is_masked(const mln_graph_element(S)& center,
102  const mln_graph_element(S)& element) const
103  {
104  E& iter = internal::force_exact<E>(*this);
105 
106  util::edge<G1> e = center.edge_with(element);
107  mln_postcondition(e.is_valid());
108 
109  return ! iter.target_()->mask()(e.id());
110  }
111 
112 
119  template <typename G1, typename F1, typename G2, typename F2, typename E>
120  inline
121  bool
122  is_masked_impl_selector< p_edges<G1,F1>, p_vertices<G2,F2>, E >
123  ::is_masked(const mln_graph_element(S)& center,
124  const mln_graph_element(S)& element) const
125  {
126  E& iter = internal::force_exact<E>(*this);
127 
128  if (center.v1() == element.v2() || center.v2() == element.v2())
129  return ! iter.target_()->mask()(element.v1());
130 
131  //else if (center.v2() == element.v1() || center.v1() == element.v1())
132  return ! iter.target_()->mask()(element.v2());
133  }
134 
135 # endif // ! MLN_INCLUDE_ONLY
136 
137  } // end of namespace mln::internal
138 
139 } // end of namespace mln
140 
141 
142 #endif // ! MLN_CORE_INTERNAL_IS_MASKED_IMPL_SELECTOR_HH