00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024 #ifndef SHSTORAGETYPEIMPL_HPP
00025 #define SHSTORAGETYPEIMPL_HPP
00026
00027 #include <climits>
00028 #include <cmath>
00029 #include <algorithm>
00030 #include "ShStorageType.hpp"
00031
00032 namespace SH {
00033
00034 inline bool shIsFloat(ShValueType value_type)
00035 {
00036 return !shIsInvalidValueType(value_type) &&
00037 (value_type & SH_VALUETYPE_TYPE_MASK) == SH_VALUETYPE_TYPE_FLOAT;
00038 }
00039
00040 inline bool shIsInteger(ShValueType value_type)
00041 {
00042 return !shIsInvalidValueType(value_type) &&
00043 (value_type & SH_VALUETYPE_TYPE_MASK) == SH_VALUETYPE_TYPE_INT;
00044 }
00045
00046 inline bool shIsFraction(ShValueType value_type)
00047 {
00048 return !shIsInvalidValueType(value_type) &&
00049 (value_type & SH_VALUETYPE_TYPE_MASK) == SH_VALUETYPE_TYPE_FRAC;
00050 }
00051
00052 inline bool shIsSigned(ShValueType value_type)
00053 {
00054 return !shIsInvalidValueType(value_type) &&
00055 (value_type & SH_VALUETYPE_SIGNED_MASK) == SH_VALUETYPE_SIGNED;
00056 }
00057
00058 inline bool shIsRegularValueType(ShValueType value_type)
00059 {
00060 return !shIsInvalidValueType(value_type) &&
00061 (value_type & SH_VALUETYPE_SPECIAL_MASK) == SH_VALUETYPE_SPECIAL_NONE;
00062 }
00063
00064 inline bool shIsInvalidValueType(ShValueType value_type)
00065 {
00066 return value_type == SH_VALUETYPE_END;
00067 }
00068
00069 inline
00070 ShValueType shRegularValueType(ShValueType value_type)
00071 {
00072 return shIsInvalidValueType(value_type) ? value_type :
00073 (value_type & ~SH_VALUETYPE_SPECIAL_MASK);
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 template<typename T1, typename T2>
00091 struct ShCommonType {
00092 static const ShValueType V1 = ShStorageTypeInfo<T1>::value_type;
00093 static const ShValueType V2 = ShStorageTypeInfo<T2>::value_type;
00094
00095 static const bool eitherDouble = V1 == SH_DOUBLE || V2 == SH_DOUBLE;
00096 static const bool eitherFloat = V1 == SH_FLOAT || V2 == SH_FLOAT;
00097 static const bool eitherFraction = ShIsFraction<T1>::matches || ShIsFraction<T2>::matches;
00098 static const bool bothHalf = V1 == SH_HALF && V2 == SH_HALF;
00099
00100 static const ShValueType value_type =
00101 (eitherDouble ?
00102 SH_DOUBLE :
00103 ((eitherFloat || eitherFraction) ?
00104 SH_FLOAT :
00105 (bothHalf ?
00106 SH_HALF :
00107 SH_INT)));
00108
00109 typedef typename ShValueTypeInfo<value_type>::storage_type type;
00110 };
00111 #undef SH_MATCH
00112
00113
00114 }
00115
00116 #endif