00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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