#include "StdAfx.h"
#define _VS2005_
#if _MSC_VER < 1400
#undef _VS2005_
#endif
#include "DataTypeRef.h"
#include "..\\BaseConverter.h"
using namespace Elmax;
DataTypeRef::~DataTypeRef(void)
{
}
bool DataTypeRef::ConvStrToType( const std::wstring& str )
{
BaseConverter conv;
switch( m_type )
{
case DTR_INT:
conv.GetInt32(str, -1, *(m_ptr.pi));
break;
case DTR_UINT:
conv.GetUInt32(str, 0, *(m_ptr.pui));
break;
case DTR_SHORT:
conv.GetInt16(str, -1, *(m_ptr.psi));
break;
case DTR_USHORT:
conv.GetUInt16(str, 0, *(m_ptr.pusi));
break;
case DTR_INT64:
conv.GetInt64(str, -1, *(m_ptr.pi64));
break;
case DTR_UINT64:
conv.GetUInt64(str, 0, *(m_ptr.pui64));
break;
case DTR_FLOAT:
conv.GetFloat(str, 0.0f, *(m_ptr.pf));
break;
case DTR_DOUBLE:
conv.GetDouble(str, 0.0, *(m_ptr.pd));
break;
case DTR_STR:
{
#ifdef _VS2005_
char* pBuf = new char[str.size()+1];
if( NULL == pBuf )
return false;
memset( pBuf, 0, str.size()+1 );
size_t RetSize=0;
errno_t err = wcstombs_s( &RetSize, pBuf, str.size()+1, str.c_str(), str.size()+1 );
if( 0 != err )
{
delete [] pBuf;
return false;
}
*(m_ptr.ps)=pBuf;
delete [] pBuf;
#else // _VS2005_
char* pBuf = new char[StrUtil.size()+1];
if( NULL == pBuf )
return false;
memset( pBuf, 0, StrUtil.size()+1 );
wcstombs( pBuf, StrUtil.c_str(), StrUtil.size()+1 );
*(m_ptr.ps)=pBuf;
delete [] pBuf;
#endif // _VS2005_
}
break;
case DTR_WSTR:
*(m_ptr.pws) = str;
break;
case DTR_CHAR:
conv.GetInt8(str, '-', *(m_ptr.pc));
break;
case DTR_WCHAR:
if( str.size() > 0 )
*(m_ptr.pwc) = str.at(0);
break;
default:
return false;
}
return true;
}