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

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

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