TypeTraits.h

Go to the documentation of this file.
00001 /*
00002  * Expression Template Matrix Library
00003  *
00004  * Copyright (C) 2004 - 2006 Ricky Lung <mtlung@users.sourceforge.net>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 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  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00030 #ifndef _EXMAT_TYPETRAITS_H
00031 #define _EXMAT_TYPETRAITS_H
00032 
00033 #include <limits>
00034 #include "PlatformSpec.h"
00035 #include "Metaprogramming.h"
00036 
00037 namespace exmat {
00038 
00039 /****************************************************************************
00040  * Traits, perform proper type conversion
00041  */
00042 
00043 /************************************************/
00044 // Value type traits
00045 template<class A, class B>
00046 struct TypeTraits
00047 {
00048     typedef typename IF<
00049         OR_bool<
00050             LESS<       // Compare the exponent of type A and B first
00051                 std::numeric_limits<A>::max_exponent10, std::numeric_limits<B>::max_exponent10
00052             >::RET,
00053             AND_bool<
00054                 EQUAL<
00055                     std::numeric_limits<A>::max_exponent10, std::numeric_limits<B>::max_exponent10
00056                 >::RET,
00057                 LESS<
00058                     std::numeric_limits<A>::digits, std::numeric_limits<B>::digits
00059                 >::RET
00060             >::RET
00061         >::RET,
00062     B, A>::RET HigherValue;
00063     typedef typename IF<
00064         OR_bool<
00065             LESS<       // Compare the exponent of type A and B first
00066                 std::numeric_limits<A>::max_exponent10, std::numeric_limits<B>::max_exponent10
00067             >::RET,
00068             AND_bool<
00069                 EQUAL<
00070                     std::numeric_limits<A>::max_exponent10, std::numeric_limits<B>::max_exponent10
00071                 >::RET,
00072                 LESS<
00073                     std::numeric_limits<A>::digits, std::numeric_limits<B>::digits
00074                 >::RET
00075             >::RET
00076         >::RET,
00077     A, B>::RET LowerValue;
00078 };
00079 
00080 // Specializations to shorten compile time
00081 #define TYPETRAITS_SPEC(T1, T2, RT1, RT2)   \
00082 template<> struct TypeTraits<T1, T2> {      \
00083     typedef RT1 HigherValue;                \
00084     typedef RT2 LowerValue;                 \
00085 };
00086 TYPETRAITS_SPEC(int, int, int, int);
00087 TYPETRAITS_SPEC(float, float, float, float);
00088 TYPETRAITS_SPEC(double, double, double, double);
00089 #undef TYPETRAITS_SPEC
00090 
00091 #define HEleType(T1, T2) typename TypeTraits<T1, T2>::HigherValue
00092 #define LEleType(T1, T2) typename TypeTraits<T1, T2>::LowerValue
00093 
00094 }   // namespace exmat
00095 
00096 #endif  // _EXMAT_TYPETRAITS_H

Generated on Sat May 6 23:12:03 2006 for Exmat by  doxygen 1.4.6-NO