00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
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