• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

ord.hh

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

Generated on Thu Sep 8 2011 18:32:10 for Milena (Olena) by  doxygen 1.7.1