Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2008, 2009 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_TRAIT_OP_ORD_HH 00028 # define MLN_TRAIT_OP_ORD_HH 00029 00033 00034 # include <mln/trait/op/decl.hh> 00035 # include <mln/trait/solve.hh> 00036 00037 00038 namespace mln 00039 { 00040 00041 // Forward declarations. 00042 namespace internal { 00043 template <typename T> struct ord_less; 00044 template <typename T> struct ord_vec; 00045 } 00046 namespace util { 00047 template <typename T> bool ord_strict(const T& lhs, const T& rhs); 00048 } 00049 00050 00051 namespace trait 00052 { 00053 00054 namespace op 00055 { 00056 00057 template <typename T> 00058 struct ord : public solve_unary<ord, T> 00059 { 00060 }; 00061 00062 } // end of namespace mln::trait::op 00063 00064 00065 template <template <class> class Category, typename T> 00066 struct set_unary_< op::ord, Category, T > 00067 { 00068 typedef mln::internal::ord_less<T> ret; 00069 }; 00070 00071 00072 } // end of namespace mln::trait 00073 00074 00075 namespace internal 00076 { 00077 00078 template <typename T> 00079 struct ord_less 00080 { 00081 bool strict(const T& lhs, const T& rhs) const; 00082 bool weak(const T& lhs, const T& rhs) const; 00083 }; 00084 00085 template <typename T> 00086 struct ord_vec 00087 { 00088 bool strict(const T& lhs, const T& rhs) const; 00089 bool weak(const T& lhs, const T& rhs) const; 00090 }; 00091 00092 00093 # ifndef MLN_INCLUDE_ONLY 00094 00095 // ord_less 00096 00097 template <typename T> 00098 inline 00099 bool 00100 ord_less<T>::strict(const T& lhs, const T& rhs) const 00101 { 00102 return lhs < rhs; 00103 } 00104 00105 template <typename T> 00106 inline 00107 bool 00108 ord_less<T>::weak(const T& lhs, const T& rhs) const 00109 { 00110 return lhs <= rhs; 00111 } 00112 00113 // ord_vec 00114 00115 template <typename T> 00116 inline 00117 bool 00118 ord_vec<T>::strict(const T& lhs, const T& rhs) const 00119 { 00120 for (unsigned i = 0; i < T::dim; ++i) 00121 { 00122 if (lhs[i] == rhs[i]) 00123 continue; 00124 return mln::util::ord_strict(lhs[i], rhs[i]); 00125 } 00126 return false; 00127 } 00128 00129 template <typename T> 00130 inline 00131 bool 00132 ord_vec<T>::weak(const T& lhs, const T& rhs) const 00133 { 00134 for (unsigned i = 0; i < T::dim; ++i) 00135 { 00136 if (lhs[i] == rhs[i]) 00137 continue; 00138 return mln::util::ord_strict(lhs[i], rhs[i]); 00139 } 00140 return true; 00141 } 00142 00143 # endif // ! MLN_INCLUDE_ONLY 00144 00145 } // end of namespace mln::trait::internal 00146 00147 } // end of namespace mln 00148 00149 00150 # include <mln/util/ord.hh> 00151 # include <mln/trait/solve.hh> 00152 00153 00154 #endif // ! MLN_TRAIT_OP_ORD_HH