Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members

promote.h

00001 /* -*- c++ -*- */
00002 /*
00003  * Expresso, a C++ Array template class library
00004  * Copyright (C) 1998,2004 Oskar Enoksson (enok@lysator.liu.se)
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the
00018  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA  02111-1307, USA.
00020  */
00021 #ifndef EXPRESSO_PROMOTE_HDR
00022 #define EXPRESSO_PROMOTE_HDR
00023 
00024 #include "tmpltool.h"
00025 
00026 namespace esso {
00027 
00028   enum { 
00029     schar, uchar, ssint, usint, 
00030     sint,  uint,  slint, ulint, 
00031     flt,   dflt,  ldflt, dummy 
00032   };
00033 
00034   template<class T>
00035   struct TypeToLevel {};
00036 
00037   template<> struct TypeToLevel<signed char> { 
00038   enum { Level=schar }; };
00039   template<> struct TypeToLevel<unsigned char> { 
00040   enum { Level=uchar }; };
00041   template<> struct TypeToLevel<signed short int> { 
00042   enum { Level=ssint }; };
00043   template<> struct TypeToLevel<unsigned short int> { 
00044   enum { Level=usint }; };
00045   template<> struct TypeToLevel<signed int> { 
00046   enum { Level=sint }; };
00047   template<> struct TypeToLevel<unsigned int> { 
00048   enum { Level=uint }; };
00049   template<> struct TypeToLevel<signed long int> { 
00050   enum { Level=slint }; };
00051   template<> struct TypeToLevel<unsigned long int> { 
00052   enum { Level=ulint }; };
00053   template<> struct TypeToLevel<float> { 
00054   enum { Level=flt }; };
00055   template<> struct TypeToLevel<double> { 
00056   enum { Level=dflt }; };
00057   template<> struct TypeToLevel<long double> { 
00058   enum { Level=ldflt }; };
00059 
00060   template<int N>
00061   struct LevelToType;
00062 
00063   template<> struct LevelToType<schar> { 
00064   typedef signed char Type; };
00065   template<> struct LevelToType<uchar> { 
00066   typedef unsigned char Type; };
00067   template<> struct LevelToType<ssint> { 
00068   typedef signed short int Type; };
00069   template<> struct LevelToType<usint> { 
00070   typedef unsigned short int Type; };
00071   template<> struct LevelToType<sint> { 
00072   typedef signed int Type; };
00073   template<> struct LevelToType<uint> { 
00074   typedef unsigned int Type; };
00075   template<> struct LevelToType<slint> { 
00076   typedef signed long int Type; };
00077   template<> struct LevelToType<ulint> { 
00078   typedef unsigned long int Type; };
00079   template<> struct LevelToType<flt> { 
00080   typedef float Type; };
00081   template<> struct LevelToType<dflt> { 
00082   typedef double Type; };
00083   template<> struct LevelToType<ldflt> { 
00084   typedef long double Type; };
00085 
00086   // Promotion rule for determining the element type
00087   // of the results of arithmetic array expressions.
00088   template<class Op, class T1, class T2>
00089   struct BPromote { 
00090   private:
00091     enum { Level1 = TypeToLevel<T1>::Level,
00092            Level2 = TypeToLevel<T2>::Level };
00093     enum { maxLevel = TmplTools::Max<Level1,Level2>::value };
00094   public:
00095     typedef typename LevelToType<maxLevel>::Type T;
00096   };
00097 
00098   // The following three promotion rules make it possible to use
00099   // any mix of Array<N,Ix<M,T> > and Array<N,T2> arrays 
00100   // arithmetic expressions and assignments.
00101   template<class Op, class T1, class T2, int N>
00102   struct BPromote<Op,Ix<N,T1>,Ix<N,T2> > { 
00103     typedef Ix<N,typename BPromote<Op,T1,T2>::T> T;
00104   };
00105   template<class Op, class T1, class T2, int N>
00106   struct BPromote<Op,Ix<N,T1>,T2> { 
00107     typedef Ix<N,typename BPromote<Op,T1,T2>::T> T;
00108   };
00109   template<class Op, class T1, class T2, int N>
00110   struct BPromote<Op,T1,Ix<N,T2> > { 
00111     typedef Ix<N,typename BPromote<Op,T1,T2>::T> T;
00112   };
00113 }
00114 
00115 #endif

Generated on Wed May 12 13:34:34 2004 for Expresso by doxygen 1.3.3