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

Generated on Wed Jun 15 18:12:42 2005 for Sh by  doxygen 1.4.3-20050530