typetraits_builtin_int.hh

00001 // Copyright (C) 2002, 2003, 2004  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_REAL_TYPETRAITS_BUILTIN_INT_HH
00029 # define NTG_REAL_TYPETRAITS_BUILTIN_INT_HH
00030 
00031 # include <ntg/real/behavior.hh>
00032 # include <ntg/core/predecls.hh>
00033 # include <ntg/core/type_traits.hh>
00034 
00035 /*-------.
00036 | macros |
00037 `-------*/
00038 
00039 # define TYPETRAITS_BUILTIN_INT(Name, Value)                                    \
00040   template<>                                                                    \
00041   struct typetraits<Name> : public typetraits<Value<Name > >                    \
00042   {                                                                             \
00043     typedef Name self;                                                          \
00044     typedef builtin::to_ntg<Name >::ret ntg_type;                               \
00045     typedef builtin::abstract_trait<Name >::ret abstract_type;                  \
00046     template <class E>                                                          \
00047     struct build_value_type                                                     \
00048     {                                                                           \
00049       typedef typename builtin::value_type<Name, E >::ret ret;                  \
00050     };                                                                          \
00051                                                                                 \
00052     typedef optraits<self> optraits;                                            \
00053     typedef unsafe::get<self> behavior_type;                                    \
00054     typedef unsafe abstract_behavior_type;                                      \
00055                                                                                 \
00056     typedef self                                       base_type;               \
00057     typedef self                                       storage_type;            \
00058     typedef builtin::signed_trait<Name >::ret          signed_type;             \
00059     typedef builtin::unsigned_trait<Name >::ret        unsigned_type;           \
00060     typedef builtin::cumul_trait<Name >::ret           cumul_type;              \
00061     typedef builtin::largest_trait<Name >::ret         largest_type;            \
00062     typedef builtin::signed_largest_trait<Name >::ret   signed_largest_type;    \
00063     typedef builtin::signed_cumul_trait<Name >::ret     signed_cumul_type;      \
00064     typedef builtin::unsigned_largest_trait<Name >::ret unsigned_largest_type;  \
00065     typedef builtin::unsigned_cumul_trait<Name >::ret   unsigned_cumul_type;    \
00066     typedef self                                       integer_type;            \
00067   };
00068 
00069 namespace ntg {
00070 
00071   namespace builtin  {
00072 
00073     template <class T>
00074     struct abstract_trait { typedef unsigned_integer ret; };
00075     template <> struct abstract_trait<signed long>  { typedef signed_integer ret; };
00076     template <> struct abstract_trait<signed int>   { typedef signed_integer ret; };
00077     template <> struct abstract_trait<signed short> { typedef signed_integer ret; };
00078     template <> struct abstract_trait<signed char>  { typedef signed_integer ret; };
00079     template <> struct abstract_trait<       char>  { typedef signed_integer ret; };
00080 
00081     template <class T>
00082     struct signed_trait { typedef T ret; };
00083     template <> struct signed_trait<unsigned long>  { typedef signed long  ret; };
00084     template <> struct signed_trait<unsigned int>   { typedef signed int   ret; };
00085     template <> struct signed_trait<unsigned short> { typedef signed int   ret; };
00086     template <> struct signed_trait<unsigned char>  { typedef signed short ret; };
00087 
00088     template <class T>
00089     struct unsigned_trait { typedef T ret; };
00090     template <> struct unsigned_trait<signed long>  { typedef unsigned long  ret; };
00091     template <> struct unsigned_trait<signed int>   { typedef unsigned int   ret; };
00092     template <> struct unsigned_trait<signed short> { typedef unsigned short ret; };
00093     template <> struct unsigned_trait<signed char>  { typedef unsigned char  ret; };
00094     template <> struct unsigned_trait<       char>  { typedef unsigned char  ret; };
00095 
00096     template <class T>
00097     struct cumul_trait { typedef T ret; };
00098     template <> struct cumul_trait<unsigned short> { typedef unsigned int   ret; };
00099     template <> struct cumul_trait<  signed short> { typedef signed int     ret; };
00100     template <> struct cumul_trait<unsigned char>  { typedef unsigned short ret; };
00101     template <> struct cumul_trait<  signed char>  { typedef signed short   ret; };
00102     template <> struct cumul_trait<         char>  { typedef signed short   ret; };
00103 
00104     template <class T>
00105     struct largest_trait { typedef T ret; };
00106     template <> struct largest_trait<unsigned short> { typedef unsigned int   ret; };
00107     template <> struct largest_trait<  signed short> { typedef signed int     ret; };
00108     template <> struct largest_trait<unsigned char>  { typedef unsigned int   ret; };
00109     template <> struct largest_trait<  signed char>  { typedef signed int     ret; };
00110     template <> struct largest_trait<         char>  { typedef signed int     ret; };
00111 
00112     template <class T>
00113     struct signed_largest_trait { typedef signed int ret; };
00114     template <> struct signed_largest_trait<unsigned long>  { typedef signed long ret; };
00115 
00116     template <class T>
00117     struct signed_cumul_trait { typedef signed int ret; };
00118     template <> struct signed_cumul_trait<unsigned long>  { typedef signed long ret; };
00119     template <> struct signed_cumul_trait<unsigned char>  { typedef signed short ret; };
00120     template <> struct signed_cumul_trait<  signed char>  { typedef signed short ret; };
00121     template <> struct signed_cumul_trait<         char>  { typedef signed short ret; };
00122 
00123     template <class T>
00124     struct unsigned_largest_trait { typedef unsigned int ret; };
00125     template <> struct unsigned_largest_trait<  signed long>  { typedef unsigned long ret; };
00126 
00127     template <class T>
00128     struct unsigned_cumul_trait { typedef unsigned int ret; };
00129     template <> struct unsigned_cumul_trait<signed long>    { typedef unsigned long ret; };
00130     template <> struct unsigned_cumul_trait<unsigned char>  { typedef unsigned short ret; };
00131     template <> struct unsigned_cumul_trait<  signed char>  { typedef unsigned short ret; };
00132     template <> struct unsigned_cumul_trait<         char>  { typedef unsigned short ret; };
00133 
00134     template<class T> struct to_ntg { typedef T ret; };
00135     template<> struct to_ntg<unsigned char>  { typedef int_u8u  ret; };
00136     template<> struct to_ntg<  signed char>  { typedef int_s8u  ret; };
00137     template<> struct to_ntg<         char>  { typedef int_s8u  ret; };
00138     template<> struct to_ntg<unsigned short> { typedef int_u16u ret; };
00139     template<> struct to_ntg<  signed short> { typedef int_s16u ret; };
00140     template<> struct to_ntg<unsigned int>   { typedef int_u32u ret; };
00141     template<> struct to_ntg<  signed int>   { typedef int_s32u ret; };
00142     template<> struct to_ntg<unsigned long>  { typedef int_u32u ret; };
00143     template<> struct to_ntg<  signed long>  { typedef int_s32u ret; };
00144 
00145     template <class T, class E> struct value_type { typedef uint_value<E> ret; };
00146     template <class E> struct value_type<signed  long, E> { typedef sint_value<E> ret; };
00147     template <class E> struct value_type<signed   int, E> { typedef sint_value<E> ret; };
00148     template <class E> struct value_type<signed short, E> { typedef sint_value<E> ret; };
00149     template <class E> struct value_type<signed  char, E> { typedef sint_value<E> ret; };
00150     template <class E> struct value_type<        char, E> { typedef sint_value<E> ret; };
00151 
00152   } // end of builtin.
00153 
00154   namespace internal {
00155 
00156     TYPETRAITS_BUILTIN_INT(unsigned long, uint_value)
00157     TYPETRAITS_BUILTIN_INT(signed long, sint_value)
00158 
00159     TYPETRAITS_BUILTIN_INT(unsigned int, uint_value)
00160     TYPETRAITS_BUILTIN_INT(signed int, sint_value)
00161 
00162     TYPETRAITS_BUILTIN_INT(unsigned short, uint_value)
00163     TYPETRAITS_BUILTIN_INT(signed short, sint_value)
00164 
00165     TYPETRAITS_BUILTIN_INT(unsigned char, uint_value)
00166     TYPETRAITS_BUILTIN_INT(signed char, sint_value)
00167     TYPETRAITS_BUILTIN_INT(char, sint_value)
00168 
00169   } // end of internal.
00170 
00171 } // end of ntg.
00172 
00173 #endif // !NTG_REAL_TYPETRAITS_BUILTIN_INT_HH

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