Click here to Skip to main content
13,043,145 members (58,284 online)
Click here to Skip to main content

Stats

25.5K views
28 bookmarked
Posted 12 Apr 2016

Linq-To-XML Style of Node Creation for C++

, 12 Apr 2016
Linq-To-XML Node Creation for Native C++
BuildProcessTemplates
Elmax.vsmdi
ElmaxNet
Properties
Elmax
Elmax.vcxproj.user
StringUtils
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
TryoutNet
Properties
Tryout
res
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax-ver089
Elmax.vsmdi
Elmax
Elmax.vcxproj.user
StringUtils
ElmaxNet
Properties
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout
res
Tryout.ico
Tryout.vcxproj.user
TryoutNet
Properties
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
#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;
}


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Cake Processor
Software Developer (Senior)
United States United States

Semi-retired from writing articles but may contribute tips from time to time.



IT Certifications


  • IT Infrastructure Library Foundational (ITIL v3)

  • Scrum Alliance Certified Scrum Master (CSM)

  • Certified Secure Software Lifecycle Professional (CSSLP)


You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 12 Apr 2016
Article Copyright 2016 by Cake Processor
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid