ShVariantCastImpl.hpp

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 SHVARIANTCASTIMPL_HPP
00021 #define SHVARIANTCASTIMPL_HPP
00022 
00023 #include "ShInternals.hpp"
00024 #include "ShVariant.hpp"
00025 #include "ShVariantCast.hpp"
00026 
00027 namespace SH {
00028 
00029 template<typename Dest, ShDataType DestDT, 
00030   typename Src, ShDataType SrcDT> 
00031 ShDataVariantCast<Dest, DestDT, Src, SrcDT>* 
00032 ShDataVariantCast<Dest, DestDT, Src, SrcDT>::m_instance = 0;
00033 
00034 template<typename Dest, ShDataType DestDT, 
00035   typename Src, ShDataType SrcDT> 
00036 void ShDataVariantCast<Dest, DestDT, Src, SrcDT>::doCast(
00037     ShVariant* dest, const ShVariant *src) const
00038 {
00039 
00040   SrcVariant* sv = variant_cast<Src, SrcDT>(src);
00041   DestVariant* dv = variant_cast<Dest, DestDT>(dest); 
00042 
00043   typename SrcVariant::const_iterator S = sv->begin();
00044   typename DestVariant::iterator D = dv->begin();
00045   for(;S != sv->end(); ++S, ++D) doCast(*D, *S);
00046 }
00047 
00048 template<typename Dest, ShDataType DestDT, 
00049   typename Src, ShDataType SrcDT>
00050 void ShDataVariantCast<Dest, DestDT, Src, SrcDT>::getCastTypes(
00051     ShValueType &dest, ShDataType &destDT, 
00052     ShValueType &src, ShDataType &srcDT) const
00053 {
00054   dest = DestValueType;
00055   destDT = DestDT;
00056   src = SrcValueType;
00057   srcDT = SrcDT;
00058 }
00059 
00060 template<typename Dest, ShDataType DestDT, 
00061   typename Src, ShDataType SrcDT>
00062 void ShDataVariantCast<Dest, DestDT, Src, SrcDT>::getDestTypes(
00063     ShValueType &valueType, ShDataType &dataType) const
00064 {
00065   valueType = DestValueType; 
00066   dataType = DestDT;
00067 }
00068 
00069 template<typename Dest, ShDataType DestDT, 
00070   typename Src, ShDataType SrcDT>
00071 void ShDataVariantCast<Dest, DestDT, Src, SrcDT>::doCast(D &dest, const S &src) const
00072 {
00073   shDataTypeCast<Dest, DestDT, Src, SrcDT>(dest, src);
00074 }
00075 
00076 template<typename Dest, ShDataType DestDT, 
00077   typename Src, ShDataType SrcDT>
00078 const ShDataVariantCast<Dest, DestDT, Src, SrcDT>*
00079 ShDataVariantCast<Dest, DestDT, Src, SrcDT>::instance()
00080 {
00081   if(!m_instance) m_instance = new ShDataVariantCast();
00082   return m_instance;
00083 }
00084 
00085 }
00086 
00087 #endif

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