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

mixin.hh

00001 // Copyright (C) 2007, 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_VALUE_MIXIN_HH
00027 # define MLN_VALUE_MIXIN_HH
00028 
00029 # include <mln/core/concept/function.hh>
00030 # include <mln/core/concept/image.hh>
00031 # include <mln/value/internal/value_like.hh>
00032 
00033 namespace mln
00034 {
00035 
00036   namespace value
00037   {
00038     template <typename T, typename F>
00039     struct mixin;
00040   }
00041 
00042   namespace trait
00043   {
00044 
00045     template <typename T, typename F>
00046     struct value_< mln::value::mixin<T, F> >
00047       : value_< T > // FIXME
00048     {
00049       static const T max()
00050       {
00051         static const F f = F();
00052         return f.max();
00053       }
00054     };
00055 
00056   } // end of namespace trait
00057 
00058 
00059   namespace value
00060   {
00061 
00062     template <typename T, typename F>
00063     struct mixin : T // , Value < mixin<T, F> >, internal::value_like_ <T, mln_enc(T), mixin<T, F>, mixin<T, F> >
00064     {
00065       // typedef T value;
00066 
00067       mixin()
00068       {
00069       }
00070 
00071       mixin(const T& t)
00072         : T(t)
00073       {
00074       }
00075 
00076       mixin(const mixin& rhs)
00077         : T(rhs)
00078       {
00079       }
00080 
00081       mixin& operator=(const mixin& rhs)
00082       {
00083         // FIXME: (?) Test if (this == &rhs)...
00084         this->T::operator=(rhs);
00085         return *this;
00086       }
00087 
00088       mixin& operator=(const T& t)
00089       {
00090         // FIXME: (?) Test if (this == &t)...
00091         this->T::operator=(t);
00092         return *this;
00093       }
00094     };
00095 
00096   } // end of namespace mln::value
00097 
00098 
00099   template <typename T, typename F>
00100   bool operator < (const value::mixin<T,F>& lhs, const value::mixin<T,F>& rhs)
00101   {
00102     static F f;
00103     return f.less(lhs, rhs);
00104   }
00105 
00106   // FIXME : check if there is an operator== in F
00107 
00108   //  template <typename T, typename F>
00109   //  bool operator == (const value::mixin<T,F>& lhs, const value::mixin<T,F>& rhs)
00110   //  {
00111   //    static F f;
00112   //    return f.equal(lhs, rhs);
00113   //  }
00114 
00115   template <typename T, typename F>
00116   bool operator == (const value::mixin<T,F>& lhs, const value::mixin<T,F>& rhs)
00117   {
00118     static F f;
00119     return !(f.less(lhs, rhs) || f.less(rhs, lhs));
00120   }
00121 
00122   template <typename T, typename F>
00123   bool operator <= (const value::mixin<T,F>& lhs, const value::mixin<T,F>& rhs)
00124   {
00125     static F f;
00126     return f.less(lhs, rhs) || lhs == rhs;
00127   }
00128 
00129   template <typename T, typename F>
00130   bool operator > (const value::mixin<T,F>& lhs, const value::mixin<T,F>& rhs)
00131   {
00132     static F f;
00133     return ! (f.less(lhs, rhs) || lhs == rhs);
00134   }
00135 
00136   template <typename T, typename F>
00137   bool operator >= (const value::mixin<T,F>& lhs, const value::mixin<T,F>& rhs)
00138   {
00139     static F f;
00140     return ! f.less(lhs, rhs);
00141   }
00142 
00143 # ifndef MLN_INCLUDE_ONLY
00144 
00145 # endif // MLN_INCLUDE_ONLY
00146 
00147 }; // end of namespace mln
00148 
00149 #endif // ! MLN_VALUE_MIXIN_HH

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