ShVariantCast.hpp

Go to the documentation of this file.
00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2006 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 SHVARIANTCAST_HPP
00021 #define SHVARIANTCAST_HPP
00022 
00023 #include "ShDllExport.hpp"
00024 #include "ShVariableType.hpp"
00025 #include "ShDataType.hpp"
00026 #include "ShVariant.hpp"
00027 
00028 namespace SH {
00029 
00030 // forward declaration
00031 class ShVariant;
00032 
00035 
00036 class 
00037 SH_DLLEXPORT
00038 ShVariantCast {
00039   public:
00040     virtual ~ShVariantCast() {}
00041 
00047     virtual void doCast(ShVariant* dest, const ShVariant* src) const = 0;
00048     // @}
00049 
00050     virtual void getCastTypes(ShValueType &dest, ShDataType &destDT, 
00051                               ShValueType &src, ShDataType &srcDT) const = 0;
00052 
00055     virtual void getDestTypes(ShValueType &valueType, ShDataType &dataType) const = 0;
00056 };
00057 
00064 template<typename Dest, ShDataType DestDT, 
00065   typename Src, ShDataType SrcDT>
00066 struct ShDataVariantCast: public ShVariantCast {
00067   public:
00068     static const ShValueType DestValueType = ShStorageTypeInfo<Dest>::value_type;
00069     static const ShValueType SrcValueType = ShStorageTypeInfo<Src>::value_type;
00070     typedef typename ShDataTypeCppType<Dest, DestDT>::type D;
00071     typedef typename ShDataTypeCppType<Src, SrcDT>::type S;
00072 
00073     typedef ShDataVariant<Dest, DestDT> DestVariant;
00074     typedef const ShDataVariant<Src, SrcDT> SrcVariant;
00075 
00076     void doCast(ShVariant* dest, const ShVariant* src) const;
00077 
00078     void getCastTypes(ShValueType &dest, ShDataType &destDT, 
00079                       ShValueType &src, ShDataType &srcDT) const;
00080 
00081     void getDestTypes(ShValueType &valueType, ShDataType &dataType) const; 
00082 
00083     void doCast(D &dest, const S &src) const;
00084 
00085     static const ShDataVariantCast *instance();
00086   private:
00087     static ShDataVariantCast *m_instance;
00088     ShDataVariantCast() {}
00089 };
00090 
00091 
00092 }
00093 
00094 #include "ShVariantCastImpl.hpp"
00095 
00096 #endif

Generated on Thu Feb 16 14:51:40 2006 for Sh by  doxygen 1.4.6