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

mixin.hh

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

Generated on Fri Sep 16 2011 16:33:44 for Milena (Olena) by  doxygen 1.7.1