optraits_real.hh

00001 // Copyright (C) 2001, 2002, 2003  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library 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
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
00027 
00028 #ifndef NTG_OPTRAITS_REAL_HH_
00029 # define NTG_OPTRAITS_REAL_HH_
00030 
00031 # include <cmath>
00032 
00033 # include <mlc/is_a.hh>
00034 
00035 # include <ntg/real/real_value.hh>
00036 # include <ntg/core/type_traits.hh>
00037 # include <ntg/core/abstract_hierarchy.hh>
00038 
00039 // --
00040 
00041 # include <ntg/core/internal/global_ops_traits.hh>
00042 # include <ntg/core/macros.hh>
00043 
00044 // macros definitions
00045 # include <ntg/real/optraits_real_defs.hh>
00046 
00047 namespace ntg {
00048 
00049   namespace internal {
00050 
00051     /*---------------------.
00052     | optraits<real_value> |
00053     `---------------------*/
00054 
00056     template <class E>
00057     class optraits<real_value<E> > : public optraits<value<E> >
00058     {
00059     private:
00060       typedef typename typetraits<E>::storage_type storage_type_;
00061 
00062     public:
00063       static storage_type_ zero () { return 0; }
00064       static storage_type_ unit () { return 1; }
00065       static storage_type_ default_val() { return zero(); }
00066 
00067       //
00068       // dev note : the aim of these default operators is to check the kind
00069       // of operands (value or not), and then call the good function.
00070       //
00071       // ASSIGN_SCALAR_OPERATOR includes default check_xxx_equal functions
00072       //
00073 
00074       ASSIGN_SCALAR_OPERATOR(plus)
00075       ASSIGN_SCALAR_OPERATOR(minus)
00076       ASSIGN_SCALAR_OPERATOR(times)
00077       ASSIGN_SCALAR_OPERATOR(div)
00078 
00079       ARITH_SCALAR_OPERATOR(plus)
00080       ARITH_SCALAR_OPERATOR(minus)
00081       ARITH_SCALAR_OPERATOR(times)
00082       ARITH_SCALAR_OPERATOR(div)
00083 
00084       CMP_SCALAR_OPERATOR(cmp_eq, ==)
00085       CMP_SCALAR_OPERATOR(cmp_lt, <)
00086     };
00087 
00088     /*----------------------.
00089     | optraits<float_value> |
00090     `----------------------*/
00091 
00092     template <class E>
00093     class optraits<float_value<E> > : public optraits<real_value<E> >
00094     {
00095     public:
00096       // This is the standard size for float on std::ostream.
00097       static unsigned max_print_width () { return 11U; }
00098     };
00099 
00100     /*--------------------.
00101     | optraits<int_value> |
00102     `--------------------*/
00103 
00104     template <class E>
00105     class optraits<int_value<E> > : public optraits<real_value<E> >
00106     {
00107       typedef typename typetraits<E>::storage_type storage_type_;
00108 
00109     public:
00110       static storage_type_ inf () { return optraits<E>::min(); }
00111       static storage_type_ sup () { return optraits<E>::max(); }
00112 
00113       static unsigned max_print_width ()
00114       { 
00115         return (unsigned) log10(double(optraits<E>::max())) + 1;
00116       }
00117 
00118       ASSIGN_INT_OPERATOR(mod_equal,  %)
00119       ARITH_INT_OPERATOR(mod,  %=)
00120     };
00121 
00122     /*---------------------.
00123     | optraits<uint_value> |
00124     `---------------------*/
00125 
00126     template <class E>
00127     class optraits<uint_value<E> > : public optraits<int_value<E> >
00128     {
00129     private:
00130       typedef typename typetraits<E>::storage_type storage_type_;
00131 
00132     public:
00133       static storage_type_ min () { return 0; }
00134     };
00135 
00136     /*---------------------.
00137     | optraits<sint_value> |
00138     `---------------------*/
00139 
00140     template <class E>
00141     class optraits<sint_value<E> > : public optraits<int_value<E> >
00142     {};
00143 
00144   } // end of internal
00145 
00146 } // end of ntg
00147 
00148 #endif // ndef NTG_OPTRAITS_REAL_HH_

Generated on Thu Apr 15 20:13:13 2004 for Olena by doxygen 1.3.6-20040222