Click here to Skip to main content
15,860,972 members
Articles / Programming Languages / Visual C++ 10.0

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

Rate me:
Please Sign up or sign in to vote.
4.78/5 (14 votes)
12 Apr 2016Ms-PL11 min read 43.3K   500   29  
Linq-To-XML Node Creation for Native C++
#include "StdAfx.h"
#include "StringUtils.h"
#include "BaseConverter.h"

using namespace Elmax;
std::wstring ToStr(bool val)
{
	std::wstring dest;

	if(val)
		dest = L"true";
	else
		dest = L"false";

	return dest;
}

std::wstring ToStr(char val)
{
	std::wstring dest;

	dest = val;

	return dest;
}

std::wstring ToStr(short val)
{
	std::wstring dest;

	const int size = 20;
	wchar_t buf[size];
	memset( buf, 0, sizeof(buf) );
	errno_t nRet = _itow_s( val, buf, size, 10 );

	dest = L"0";
	if( 0 == nRet )
		dest = buf;

	return dest;
}

std::wstring ToStr(int val)
{
	std::wstring dest;

	const int size = 20;
	wchar_t buf[size];
	memset( buf, 0, sizeof(buf) );
	errno_t nRet = _itow_s( val, buf, size, 10 );

	dest = L"0";
	if( 0 == nRet )
		dest = buf;

	return dest;
}

std::wstring ToStr(__int64 val)
{
	std::wstring dest;

	const int size = 30;
	wchar_t buf[size];
	memset( buf, 0, sizeof(buf) );
	errno_t nRet = _i64tow_s( val, buf, size, 10 );

	dest = L"0";
	if( 0 == nRet )
		dest = buf;

	return dest;
}

std::wstring ToStr(unsigned char val)
{
	std::wstring dest;

	const int size = 20;
	wchar_t buf[size];
	memset( buf, 0, sizeof(buf) );
	errno_t nRet = _ultow_s( val, buf, size, 10 );

	dest = L"0";
	if( 0 == nRet )
		dest = buf;

	return dest;
}

std::wstring ToStr(unsigned short val)
{
	std::wstring dest;

	const int size = 20;
	wchar_t buf[size];
	memset( buf, 0, sizeof(buf) );
	errno_t nRet = _ultow_s( val, buf, size, 10 );

	dest = L"0";
	if( 0 == nRet )
		dest = buf;

	return dest;
}

std::wstring ToStr(unsigned int val)
{
	std::wstring dest;

	const int size = 20;
	wchar_t buf[size];
	memset( buf, 0, sizeof(buf) );
	errno_t nRet = _ultow_s( val, buf, size, 10 );

	dest = L"0";
	if( 0 == nRet )
		dest = buf;

	return dest;
}

std::wstring ToStr(unsigned __int64 val)
{
	std::wstring dest;

	const int size = 30;
	wchar_t buf[size];
	memset( buf, 0, sizeof(buf) );
	errno_t nRet = _ui64tow_s( val, buf, size, 10 );

	dest = L"0";
	if( 0 == nRet )
		dest = buf;

	return dest;
}

std::wstring ToStr(float val)
{
	std::wstring dest;

	const int size = 60;
	wchar_t buf[size];
	memset( buf, 0, sizeof(buf) );
	int nRet = swprintf_s( buf, size, L"%f", val );

	dest = L"0.0";
	if( -1 != nRet )
		dest = buf;

	return dest;
}

std::wstring ToStr(double val)
{
	std::wstring dest;

	const int size = 60;
	wchar_t buf[size];
	memset( buf, 0, sizeof(buf) );
	int nRet = swprintf_s( buf, size, L"%lf", val );

	dest = L"0.0";
	if( -1 != nRet )
		dest = buf;

	return dest;
}

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)


Written By
Software Developer (Senior)
Singapore Singapore
Shao Voon is from Singapore. His interest lies primarily in computer graphics, software optimization, concurrency, security, and Agile methodologies.

In recent years, he shifted focus to software safety research. His hobby is writing a free C++ DirectX photo slideshow application which can be viewed here.

Comments and Discussions