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 <fstream>
00028 #include "ShTypeInfo.hpp"
00029 #include "ShCastManager.hpp"
00030 #include "ShVariantCast.hpp"
00031
00032 namespace {
00033 using namespace SH;
00034
00035 template<typename Dest, ShDataType DestDT, typename Src, ShDataType SrcDT>
00036 void addCast(bool automatic)
00037 {
00038 ShCastManager::instance()->addCast(ShDataVariantCast<Dest, DestDT, Src, SrcDT>::instance(), automatic);
00039 }
00040
00041
00042 template<typename Dest, typename Src>
00043 void addPromotion()
00044 {
00045 addCast<Dest, SH_HOST, Src, SH_HOST>(true);
00046 addCast<Src, SH_HOST, Dest, SH_HOST>(false);
00047 }
00048
00049
00050
00051 template<typename T>
00052 void addMemoryCast()
00053 {
00054 addCast<T, SH_HOST, T, SH_MEM>(false);
00055 addCast<T, SH_MEM, T, SH_HOST>(false);
00056 }
00057
00058 }
00059
00060 namespace SH {
00061
00062
00063 void ShTypeInfo::addCasts()
00064 {
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 addPromotion<ShInterval<double>, ShInterval<float> >();
00082 addCast<ShInterval<double>, SH_HOST, double, SH_HOST>(true);
00083
00084 addCast<ShInterval<float>, SH_HOST, float, SH_HOST>(true);
00085
00086 addPromotion<double, float>();
00087
00088 addPromotion<float, ShHalf>();
00089 addPromotion<float, int>();
00090 addPromotion<float, unsigned int>();
00091 addPromotion<float, ShFracInt> ();
00092 addPromotion<float, ShFracShort> ();
00093 addPromotion<float, ShFracByte> ();
00094 addPromotion<float, ShFracUInt> ();
00095 addPromotion<float, ShFracUShort> ();
00096 addPromotion<float, ShFracUByte> ();
00097
00098 addPromotion<int, short>();
00099 addPromotion<int, char>();
00100 addPromotion<int, unsigned short>();
00101 addPromotion<int, unsigned char>();
00102
00103
00104 addCast<float, SH_HOST, short, SH_HOST>(false);
00105 addCast<float, SH_HOST, char, SH_HOST>(false);
00106 addCast<float, SH_HOST, unsigned short, SH_HOST>(false);
00107 addCast<float, SH_HOST, unsigned char, SH_HOST>(false);
00108
00109
00110 addMemoryCast<ShInterval<double> >();
00111 addMemoryCast<ShInterval<float> >();
00112
00113 addMemoryCast<double>();
00114 addMemoryCast<float>();
00115 addMemoryCast<ShHalf>();
00116
00117 addMemoryCast<int>();
00118 addMemoryCast<short>();
00119 addMemoryCast<char>();
00120 addMemoryCast<unsigned int>();
00121 addMemoryCast<unsigned short>();
00122 addMemoryCast<unsigned char>();
00123
00124 addMemoryCast<ShFraction<int> >();
00125 addMemoryCast<ShFraction<short> >();
00126 addMemoryCast<ShFraction<char> >();
00127 addMemoryCast<ShFraction<unsigned int> >();
00128 addMemoryCast<ShFraction<unsigned short> >();
00129 addMemoryCast<ShFraction<unsigned char> >();
00130
00131 ShCastManager::instance()->init();
00132
00133 #if 0
00134 std::ofstream fout("castgraph.dot");
00135 ShCastManager::instance()->graphvizDump(fout);
00136 system("dot -Tps < castgraph.dot > castgraph.ps");
00137 #endif
00138 }
00139
00140 }