00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00087
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
00099
00100
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