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

scalar.hh

00001 // Copyright (C) 2006, 2007, 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_SCALAR_HH
00027 # define MLN_VALUE_SCALAR_HH
00028  
00032 
00033 # include <mln/value/concept/scalar.hh>
00034 # include <mln/metal/is_a.hh>
00035 # include <mln/metal/if.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   namespace value
00042   {
00043 
00044     template <typename T>
00045     class scalar_ : public Scalar< scalar_<T> >
00046     {
00047     public:
00048 
00050       typedef T enc; // FIXME
00051 
00053       typedef T equiv; // FIXME
00054 
00055 
00057       scalar_();
00058 
00060       explicit scalar_(const T& val);
00061 
00063       T to_equiv() const;
00064 
00065     protected:
00066       T val_; // FIXME: const&?
00067     };
00068 
00069     template <typename T> class scalar_< scalar_<T> >; // Safety: this type should not exist!
00070 
00071 
00073     template <typename T>
00074     std::ostream& operator<<(std::ostream& ostr, const scalar_<T>& s);
00075 
00076 
00077 
00078     // Routine scalar(T) -> scalar_<T>.
00079 
00080     namespace internal
00081     {
00082 
00083       template <typename T>
00084       struct helper_scalar_
00085       {
00086         typedef mlc_is_a(T, Scalar) is_scalar_;
00087         typedef mlc_if(is_scalar_, T, scalar_<T>) ret;
00088       };
00089 
00090     } // end of namespace mln::value::internal
00091 
00092 
00093     // Routine.
00094     template <typename T>
00095     typename internal::helper_scalar_<T>::ret
00096     scalar(const T& s);  // FIXME: if T already is a scalar_...
00097 
00098 
00099 
00100 
00101 # ifndef MLN_INCLUDE_ONLY
00102 
00103     // scalar_<T>.
00104 
00105     template <typename T>
00106     inline
00107     scalar_<T>::scalar_()
00108     {
00109     }
00110 
00111     template <typename T>
00112     inline
00113     scalar_<T>::scalar_(const T& val)
00114       : val_(val)
00115     {
00116     }
00117 
00118     template <typename T>
00119     inline
00120     T
00121     scalar_<T>::to_equiv() const
00122     {
00123       return val_;
00124     }
00125 
00126     // Operator.
00127 
00128     template <typename T>
00129     inline
00130     std::ostream& operator<<(std::ostream& ostr, const scalar_<T>& s)
00131     {
00132       return ostr << s.to_equiv();
00133     }
00134 
00135     // Routine.
00136 
00137     template <typename T>
00138     inline
00139     typename internal::helper_scalar_<T>::ret
00140     scalar(const T& s)
00141     {
00142       typename internal::helper_scalar_<T>::ret tmp(s);
00143       return tmp;
00144     }
00145 
00146 # endif // ! MLN_INCLUDE_ONLY
00147 
00148   } // end of namespace mln::value
00149 
00150 } // end of namespace mln
00151 
00152 
00153 #endif // ! MLN_VALUE_SCALAR_HH

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