Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_UTIL_SITE_PAIR_HH 00027 # define MLN_UTIL_SITE_PAIR_HH 00028 00029 # include <mln/core/concept/proxy.hh> 00030 # include <mln/util/ord_pair.hh> 00031 00035 00036 namespace mln 00037 { 00038 00039 namespace util 00040 { 00041 00042 /* FIXME: The class mln::internal::image_base requires its site 00043 types to have a `coord' typedef, but util::ord_pair has none. 00044 Hence this small workaround. Use ord_pair directly as soon as 00045 image_base is refurbished. */ 00050 // 00051 template <typename P> 00052 class site_pair : public mln::Object< site_pair<P> > 00053 { 00054 public: 00055 /* FIXME: We should not need to define this typedef 00056 (see. mln::internal::image_base's site `coord' typedef). */ 00057 typedef mln_coord(P) coord; 00058 00059 site_pair(); 00060 site_pair(const P& first, const P& second); 00061 00063 const P& first() const; 00065 const P& second() const; 00066 00068 const util::ord_pair<P>& pair() const; 00069 00070 private: 00071 util::ord_pair<P> pair_; 00072 }; 00073 00074 00075 /* FIXME: The proxy mechanism requires operator== and operator<= for 00076 line_graph_psite to compile (note: line_graph_psite aggregates a 00077 site_pair); why? It seems its static assertions do not check the 00078 right guy(s). IMHO (Roland's), it should look for 00079 line_graph_psite's operators, not site_pair's. */ 00080 template <typename P> 00081 bool operator==(const site_pair<P>& lhs, const site_pair<P>& rhs); 00082 00083 template <typename P> 00084 bool operator< (const site_pair<P>& lhs, const site_pair<P>& rhs); 00085 00086 template <typename P> 00087 bool operator< (const site_pair<P>& lhs, const site_pair<P>& rhs); 00088 00089 template <typename P> 00090 std::ostream& 00091 operator<<(std::ostream& ostr, const site_pair<P>& p); 00092 00093 } // end of namespace mln::util 00094 00095 00096 namespace internal 00097 { 00098 00101 00102 template <typename P, typename E> 00103 struct subject_impl< const util::site_pair<P>, E > 00104 { 00105 const P& first() const; 00106 const P& second() const; 00107 const util::ord_pair<P>& pair() const; 00108 00109 private: 00110 const E& exact_() const; 00111 }; 00112 00114 00115 } // end of namespace mln::internal 00116 00117 00118 00119 # ifndef MLN_INCLUDE_ONLY 00120 00121 namespace util 00122 { 00123 00124 /*---------------. 00125 | Construction. | 00126 `---------------*/ 00127 00128 template <typename P> 00129 site_pair<P>::site_pair() 00130 { 00131 } 00132 00133 template <typename P> 00134 site_pair<P>::site_pair(const P& first, const P& second) 00135 : pair_(first, second) 00136 { 00137 } 00138 00139 template <typename P> 00140 inline 00141 const P& 00142 site_pair<P>::first() const 00143 { 00144 return pair_.first(); 00145 } 00146 00147 template <typename P> 00148 inline 00149 const P& 00150 site_pair<P>::second() const 00151 { 00152 return pair_.second(); 00153 } 00154 00155 template <typename P> 00156 inline 00157 const util::ord_pair<P>& 00158 site_pair<P>::pair() const 00159 { 00160 return pair_; 00161 } 00162 00163 /*-------------. 00164 | Comparison. | 00165 `-------------*/ 00166 00167 template <typename P> 00168 inline 00169 bool 00170 operator==(const site_pair<P>& lhs, const site_pair<P>& rhs) 00171 { 00172 return lhs.pair() == rhs.pair(); 00173 } 00174 00175 template <typename P> 00176 inline 00177 bool 00178 operator< (const site_pair<P>& lhs, const site_pair<P>& rhs) 00179 { 00180 return lhs.pair() < rhs.pair(); 00181 } 00182 00183 template <typename P> 00184 inline 00185 bool 00186 operator<=(const site_pair<P>& lhs, const site_pair<P>& rhs) 00187 { 00188 return lhs.pair() <= rhs.pair(); 00189 } 00190 00191 template <typename P> 00192 inline 00193 std::ostream& 00194 operator<<(std::ostream& ostr, const site_pair<P>& p) 00195 { 00196 ostr << "(" << p.first() << ", " << p.second() << ")"; 00197 return ostr; 00198 } 00199 00200 } // end of mln::util 00201 00202 namespace internal 00203 { 00204 00205 template <typename P, typename E> 00206 inline 00207 const E& 00208 subject_impl< const util::site_pair<P>, E >::exact_() const 00209 { 00210 return internal::force_exact<const E>(*this); 00211 } 00212 00213 template <typename P, typename E> 00214 inline 00215 const P& 00216 subject_impl< const util::site_pair<P>, E >::first() const 00217 { 00218 return exact_().get_subject().first(); 00219 } 00220 00221 template <typename P, typename E> 00222 inline 00223 const P& 00224 subject_impl< const util::site_pair<P>, E >::second() const 00225 { 00226 return exact_().get_subject().second(); 00227 } 00228 00229 } // end of namespace mln::internal 00230 00231 # endif // ! MLN_INCLUDE_ONLY 00232 00233 } // end of mln 00234 00235 00236 #endif // ! MLN_UTIL_SITE_PAIR_HH