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

value_like.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_INTERNAL_VALUE_LIKE_HH
00027 # define MLN_VALUE_INTERNAL_VALUE_LIKE_HH
00028 
00032 
00033 # include <mln/core/concept/value.hh>
00034 # include <mln/core/internal/force_exact.hh>
00035 
00036 
00037 namespace mln
00038 {
00039 
00040   namespace value
00041   {
00042 
00043     namespace internal
00044     {
00045 
00050       template < typename V, // Equivalent.
00051                  typename C, // Encoding.
00052                  typename N, // Interoperation.
00053                  typename E >
00054       struct value_like_ // FIXME :Remove -> : public Value<E>
00055       {
00057         typedef V equiv;
00058 
00060         typedef C enc;
00061 
00063         typedef N interop;
00064 
00066         V to_equiv() const;
00067 
00069         const C& to_enc() const;
00070 
00072         N to_interop() const;
00073 
00074 
00075         // Handle to encoding value.
00076         C& handle_() { return v_; }
00077 
00078       protected:
00079         enc v_; 
00080       };
00081 
00082 
00086       template <typename V, typename C, typename N, typename E>
00087       bool operator==(const value_like_<V,C,N,E>& lhs, const value_like_<V,C,N,E>& rhs);
00088 
00089 
00093       template <typename V, typename C, typename N, typename E>
00094       bool operator<(const value_like_<V,C,N,E>& lhs, const value_like_<V,C,N,E>& rhs);
00095 
00096 
00097 # ifndef MLN_INCLUDE_ONLY
00098 
00099       template <typename V, typename C, typename N, typename E>
00100       inline
00101       V
00102       value_like_<V,C,N,E>::to_equiv() const
00103       {
00104         return v_;
00105       }
00106 
00107       template <typename V, typename C, typename N, typename E>
00108       inline
00109       const C&
00110       value_like_<V,C,N,E>::to_enc() const
00111       {
00112         return v_;
00113       }
00114 
00115       template <typename V, typename C, typename N, typename E>
00116       inline
00117       N
00118       value_like_<V,C,N,E>::to_interop() const
00119       {
00120         return static_cast<N>(mln::internal::force_exact<E>(*this));
00121       }
00122 
00123       template <typename V, typename C, typename N, typename E>
00124       inline
00125       bool operator==(const value_like_<V,C,N,E>& lhs,
00126                       const value_like_<V,C,N,E>& rhs)
00127       {
00128         return lhs.to_enc() == rhs.to_enc();
00129       }
00130 
00131       template <typename V, typename C, typename N, typename E>
00132       inline
00133       bool operator<(const value_like_<V,C,N,E>& lhs,
00134                      const value_like_<V,C,N,E>& rhs)
00135       {
00136         return lhs.to_interop() < rhs.to_interop(); // FIXME HERE: Why interop?
00137       }
00138 
00139 # endif // ! MLN_INCLUDE_ONLY
00140 
00141     } // end of namespace mln::value::internal
00142 
00143   } // end of namespace mln::value
00144 
00145 } // end of namespace mln
00146 
00147 
00148 #endif // ! MLN_VALUE_INTERNAL_VALUE_LIKE_HH

Generated on Tue Oct 4 2011 15:25:05 for Milena (Olena) by  doxygen 1.7.1