00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright 2003-2005 Serious Hack Inc. 00004 // 00005 // This library is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00018 // MA 02110-1301, USA 00020 #ifndef SHTYPEINFO_HPP 00021 #define SHTYPEINFO_HPP 00022 00023 #include <string> 00024 #include <vector> 00025 #include "ShHashMap.hpp" 00026 #include "ShVariableType.hpp" 00027 #include "ShDataType.hpp" 00028 #include "ShRefCount.hpp" 00029 #include "ShFraction.hpp" 00030 #include "ShHalf.hpp" 00031 00032 namespace SH { 00033 00035 struct ShVariantFactory; 00036 00037 00041 struct 00042 SH_DLLEXPORT 00043 ShTypeInfo { 00044 virtual ~ShTypeInfo() {} 00045 00047 virtual const char* name() const = 0; 00048 00050 virtual int datasize() const = 0; 00051 00053 virtual const ShVariantFactory* variantFactory() const = 0; 00054 00058 static void init(); 00059 00061 static const ShTypeInfo* get(ShValueType valueType, ShDataType dataType); 00062 00063 typedef ShPairHashMap<ShValueType, ShDataType, const ShTypeInfo*> TypeInfoMap; 00064 private: 00066 static TypeInfoMap* m_valueTypes; 00067 00069 static void addCasts(); 00070 00072 static void addOps(); 00073 }; 00074 00075 // generic level, singleton ShTypeInfo class holding information for 00076 // a particular type 00077 template<typename T, ShDataType DT> 00078 struct ShDataTypeInfo: public ShTypeInfo { 00079 public: 00080 typedef typename ShDataTypeCppType<T, DT>::type type; 00081 static const type Zero; 00082 static const type One; 00083 00084 const char* name() const; 00085 int datasize() const; 00086 const ShVariantFactory* variantFactory() const; 00087 00088 static const ShDataTypeInfo* instance(); 00089 00090 protected: 00091 static ShDataTypeInfo *m_instance; 00092 ShDataTypeInfo() {} 00093 }; 00094 00095 00096 SH_DLLEXPORT 00097 extern const ShTypeInfo* shTypeInfo(ShValueType valueType, ShDataType dataType = SH_HOST); 00098 00099 SH_DLLEXPORT 00100 extern const ShVariantFactory* shVariantFactory(ShValueType valueType, ShDataType dataType = SH_HOST); 00101 00102 SH_DLLEXPORT 00103 extern const char* shValueTypeName(ShValueType valueType); 00104 } 00105 00106 #include "ShTypeInfoImpl.hpp" 00107 00108 #endif
1.4.3-20050530