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