Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShTypeInfo.hpp

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

Generated on Mon Jan 24 18:36:36 2005 for Sh by  doxygen 1.4.1