Milena (Olena)  User documentation 2.0a Id
is_masked_impl_selector.hh
00001 // Copyright (C) 2009, 2011 EPITA Research and Development Laboratory
00002 // (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_CORE_INTERNAL_IS_MASKED_IMPL_SELECTOR_HH
00028 # define MLN_CORE_INTERNAL_IS_MASKED_IMPL_SELECTOR_HH
00029 
00033 
00034 # include <mln/util/edge.hh>
00035 
00036 
00037 namespace mln
00038 {
00039 
00040   // Forward declarations.
00041   template <typename G, typename F> class p_edges;
00042   template <typename G, typename F> class p_vertices;
00043 
00044 
00045 
00046   namespace internal
00047   {
00048 
00051     template <typename S, typename D, typename E>
00052     struct is_masked_impl_selector
00053     {
00055       bool is_masked(const mln_graph_element(S)& center,
00056                      const mln_graph_element(S)& element) const;
00057     };
00058 
00060     template <typename G1, typename F1, typename G2, typename F2, typename E>
00061     struct is_masked_impl_selector< p_vertices<G1,F1>, p_edges<G2,F2>, E >
00062     {
00063       typedef p_vertices<G1,F1> S;
00064 
00066       bool is_masked(const mln_graph_element(S)& center,
00067                      const mln_graph_element(S)& element) const;
00068     };
00069 
00071     template <typename G1, typename F1, typename G2, typename F2, typename E>
00072     struct is_masked_impl_selector< p_edges<G1,F1>, p_vertices<G2,F2>, E >
00073     {
00074       typedef p_edges<G1,F1> S;
00075 
00077       bool is_masked(const mln_graph_element(S)& center,
00078                      const mln_graph_element(S)& element) const;
00079     };
00080 
00081 
00082 # ifndef MLN_INCLUDE_ONLY
00083 
00084 
00085     template <typename S, typename I, typename E>
00086     inline
00087     bool
00088     is_masked_impl_selector<S,I,E>::is_masked(const mln_graph_element(S)& center,
00089                                               const mln_graph_element(S)& element) const
00090     {
00091       (void) center;
00092       E& iter = internal::force_exact<E>(*this);
00093       return ! iter.target_()->mask()(element.id());
00094     }
00095 
00096 
00097     template <typename G1, typename F1, typename G2, typename F2, typename E>
00098     inline
00099     bool
00100     is_masked_impl_selector< p_vertices<G1,F1>, p_edges<G2,F2>, E >
00101       ::is_masked(const mln_graph_element(S)& center,
00102                   const mln_graph_element(S)& element) const
00103     {
00104       E& iter = internal::force_exact<E>(*this);
00105 
00106       util::edge<G1> e = center.edge_with(element);
00107       mln_postcondition(e.is_valid());
00108 
00109       return ! iter.target_()->mask()(e.id());
00110     }
00111 
00112 
00119     template <typename G1, typename F1, typename G2, typename F2, typename E>
00120     inline
00121     bool
00122     is_masked_impl_selector< p_edges<G1,F1>, p_vertices<G2,F2>, E >
00123       ::is_masked(const mln_graph_element(S)& center,
00124                   const mln_graph_element(S)& element) const
00125     {
00126       E& iter = internal::force_exact<E>(*this);
00127 
00128       if (center.v1() == element.v2() || center.v2() == element.v2())
00129         return ! iter.target_()->mask()(element.v1());
00130 
00131       //else if (center.v2() == element.v1() || center.v1() == element.v1())
00132       return ! iter.target_()->mask()(element.v2());
00133     }
00134 
00135 # endif // ! MLN_INCLUDE_ONLY
00136 
00137   } // end of namespace mln::internal
00138 
00139 } // end of namespace mln
00140 
00141 
00142 #endif // ! MLN_CORE_INTERNAL_IS_MASKED_IMPL_SELECTOR_HH
 All Classes Namespaces Functions Variables Typedefs Enumerator