00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright 2003-2005 Serious Hack Inc. 00004 // 00005 // This software is provided 'as-is', without any express or implied 00006 // warranty. In no event will the authors be held liable for any damages 00007 // arising from the use of this software. 00008 // 00009 // Permission is granted to anyone to use this software for any purpose, 00010 // including commercial applications, and to alter it and redistribute it 00011 // freely, subject to the following restrictions: 00012 // 00013 // 1. The origin of this software must not be misrepresented; you must 00014 // not claim that you wrote the original software. If you use this 00015 // software in a product, an acknowledgment in the product documentation 00016 // would be appreciated but is not required. 00017 // 00018 // 2. Altered source versions must be plainly marked as such, and must 00019 // not be misrepresented as being the original software. 00020 // 00021 // 3. This notice may not be removed or altered from any source 00022 // distribution. 00024 #ifndef SHTYPEINFO_HPP 00025 #define SHTYPEINFO_HPP 00026 00027 #include <string> 00028 #include <vector> 00029 #include "ShHashMap.hpp" 00030 #include "ShVariableType.hpp" 00031 #include "ShDataType.hpp" 00032 #include "ShRefCount.hpp" 00033 #include "ShFraction.hpp" 00034 #include "ShHalf.hpp" 00035 00036 namespace SH { 00037 00039 struct ShVariantFactory; 00040 00041 00045 struct 00046 SH_DLLEXPORT 00047 ShTypeInfo { 00048 virtual ~ShTypeInfo() {} 00049 00051 virtual const char* name() const = 0; 00052 00054 virtual int datasize() const = 0; 00055 00057 virtual const ShVariantFactory* variantFactory() const = 0; 00058 00062 static void init(); 00063 00065 static const ShTypeInfo* get(ShValueType valueType, ShDataType dataType); 00066 00067 typedef ShPairHashMap<ShValueType, ShDataType, const ShTypeInfo*> TypeInfoMap; 00068 private: 00070 static TypeInfoMap* m_valueTypes; 00071 00073 static void addCasts(); 00074 00076 static void addOps(); 00077 }; 00078 00079 // generic level, singleton ShTypeInfo class holding information for 00080 // a particular type 00081 template<typename T, ShDataType DT> 00082 struct ShDataTypeInfo: public ShTypeInfo { 00083 public: 00084 typedef typename ShDataTypeCppType<T, DT>::type type; 00085 static const type Zero; 00086 static const type One; 00087 00088 const char* name() const; 00089 int datasize() const; 00090 const ShVariantFactory* variantFactory() const; 00091 00092 static const ShDataTypeInfo* instance(); 00093 00094 protected: 00095 static ShDataTypeInfo *m_instance; 00096 ShDataTypeInfo() {} 00097 }; 00098 00099 00100 SH_DLLEXPORT 00101 extern const ShTypeInfo* shTypeInfo(ShValueType valueType, ShDataType dataType = SH_HOST); 00102 00103 SH_DLLEXPORT 00104 extern const ShVariantFactory* shVariantFactory(ShValueType valueType, ShDataType dataType = SH_HOST); 00105 00106 SH_DLLEXPORT 00107 extern const char* shValueTypeName(ShValueType valueType); 00108 } 00109 00110 #include "ShTypeInfoImpl.hpp" 00111 00112 #endif
1.4.3-20050530