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

ShVariantCast.hpp

Go to the documentation of this file.
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 SHVARIANTCAST_HPP
00025 #define SHVARIANTCAST_HPP
00026 
00027 #include "ShDllExport.hpp"
00028 #include "ShVariableType.hpp"
00029 #include "ShDataType.hpp"
00030 #include "ShVariant.hpp"
00031 
00032 namespace SH {
00033 
00034 // forward declaration
00035 class ShVariant;
00036 
00039 
00040 struct 
00041 SH_DLLEXPORT
00042 ShVariantCast {
00043   public:
00044     virtual ~ShVariantCast() {}
00045 
00051     virtual void doCast(ShVariant* dest, const ShVariant* src) const = 0;
00052     // @}
00053 
00054     virtual void getCastTypes(ShValueType &dest, ShDataType &destDT, 
00055                               ShValueType &src, ShDataType &srcDT) const = 0;
00056 
00059     virtual void getDestTypes(ShValueType &valueType, ShDataType &dataType) const = 0;
00060 };
00061 
00068 template<typename Dest, ShDataType DestDT, 
00069   typename Src, ShDataType SrcDT>
00070 struct ShDataVariantCast: public ShVariantCast {
00071   public:
00072     static const ShValueType DestValueType = ShStorageTypeInfo<Dest>::value_type;
00073     static const ShValueType SrcValueType = ShStorageTypeInfo<Src>::value_type;
00074     typedef typename ShDataTypeCppType<Dest, DestDT>::type D;
00075     typedef typename ShDataTypeCppType<Src, SrcDT>::type S;
00076 
00077     typedef ShDataVariant<Dest, DestDT> DestVariant;
00078     typedef const ShDataVariant<Src, SrcDT> SrcVariant;
00079 
00080     void doCast(ShVariant* dest, const ShVariant* src) const;
00081 
00082     void getCastTypes(ShValueType &dest, ShDataType &destDT, 
00083                       ShValueType &src, ShDataType &srcDT) const;
00084 
00085     void getDestTypes(ShValueType &valueType, ShDataType &dataType) const; 
00086 
00087     void doCast(D &dest, const S &src) const;
00088 
00089     static const ShDataVariantCast *instance();
00090   private:
00091     static ShDataVariantCast *m_instance;
00092     ShDataVariantCast() {}
00093 };
00094 
00095 
00096 }
00097 
00098 #include "ShVariantCastImpl.hpp"
00099 
00100 #endif

Generated on Thu Apr 21 17:32:50 2005 for Sh by  doxygen 1.4.2