00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 #include "ShTypeInfo.hpp"
00028 #include "ShContext.hpp"
00029 #include "ShInterval.hpp"
00030 #include "ShEval.hpp"
00031 #include "ShCastManager.hpp"
00032 #include "ShVariantCast.hpp"
00033
00034 namespace {
00035 using namespace SH;
00036
00037
00038 template<typename T>
00039 void setTypeInfo(ShTypeInfo::TypeInfoMap &valueTypes) {
00040 ShValueType V = ShStorageTypeInfo<T>::value_type;
00041 valueTypes(V, SH_HOST) = ShDataTypeInfo<T, SH_HOST>::instance();
00042 valueTypes(V, SH_MEM) = ShDataTypeInfo<T, SH_MEM>::instance();
00043 }
00044
00045 }
00046
00047 namespace SH {
00048
00049 ShTypeInfo::TypeInfoMap ShTypeInfo::m_valueTypes;
00050
00051 void ShTypeInfo::init()
00052 {
00053 setTypeInfo<ShInterval<double> >(m_valueTypes);
00054 setTypeInfo<ShInterval<float> >(m_valueTypes);
00055
00056 setTypeInfo<double>(m_valueTypes);
00057 setTypeInfo<float>(m_valueTypes);
00058 setTypeInfo<ShHalf>(m_valueTypes);
00059
00060 setTypeInfo<int>(m_valueTypes);
00061 setTypeInfo<short>(m_valueTypes);
00062 setTypeInfo<char>(m_valueTypes);
00063 setTypeInfo<unsigned int>(m_valueTypes);
00064 setTypeInfo<unsigned short>(m_valueTypes);
00065 setTypeInfo<unsigned char>(m_valueTypes);
00066
00067 setTypeInfo<ShFracInt> (m_valueTypes);
00068 setTypeInfo<ShFracShort> (m_valueTypes);
00069 setTypeInfo<ShFracByte> (m_valueTypes);
00070 setTypeInfo<ShFracUInt> (m_valueTypes);
00071 setTypeInfo<ShFracUShort> (m_valueTypes);
00072 setTypeInfo<ShFracUByte> (m_valueTypes);
00073
00074 addOps();
00075
00076
00077
00078 addCasts();
00079 }
00080
00081 const ShTypeInfo* ShTypeInfo::get(ShValueType valueType, ShDataType dataType)
00082 {
00083 const ShTypeInfo* result = m_valueTypes(valueType, dataType);
00084 if(!result) SH_DEBUG_PRINT("Null ShTypeInfo");
00085 return result;
00086 }
00087
00088 const ShTypeInfo* shTypeInfo(ShValueType valueType, ShDataType dataType)
00089 {
00090 return ShTypeInfo::get(valueType, dataType);
00091 }
00092
00093 const ShVariantFactory* shVariantFactory(ShValueType valueType, ShDataType dataType)
00094 {
00095 return shTypeInfo(valueType, dataType)->variantFactory();
00096 }
00097
00098 const char* shValueTypeName(ShValueType valueType)
00099 {
00100 const ShTypeInfo* typeInfo = shTypeInfo(valueType, SH_HOST);
00101 if(!typeInfo) return ShStorageTypeInfo<ShInvalidStorageType>::name;
00102 return typeInfo->name();
00103 }
00104
00105 }