Click here to Skip to main content
14,239,386 members

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

Rate this:
4.78 (14 votes)
Please Sign up or sign in to vote.
4.78 (14 votes)
12 Apr 2016Ms-PL
Linq-To-XML Node Creation for Native C++
BuildProcessTemplates
Elmax.vsmdi
ElmaxNet
Properties
Elmax
Elmax.vcxproj.user
Elmax_2005.vcproj
Elmax_2008.vcproj
StringUtils
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
TryoutNet
Properties
Tryout
res
Tryout.ico
Tryout.vcproj
Tryout.vcxproj.user
Tryout_2008.vcproj
Elmax.vsmdi
Elmax.vcxproj.user
Elmax_2005.vcproj
Elmax_2008.vcproj
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcproj
Tryout.vcxproj.user
Tryout_2008.vcproj
Elmax.vsmdi
Elmax.vcxproj.user
Elmax_2005.vcproj
Elmax_2008.vcproj
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcproj
Tryout.vcxproj.user
Tryout_2008.vcproj
Elmax.vsmdi
Elmax.vcxproj.user
Elmax_2005.vcproj
Elmax_2008.vcproj
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcproj
Tryout.vcxproj.user
Tryout_2008.vcproj
Elmax.vsmdi
Elmax.vcxproj.user
Elmax_2005.vcproj
Elmax_2008.vcproj
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcproj
Tryout.vcxproj.user
Tryout_2008.vcproj
Elmax.vsmdi
Elmax.vcxproj.user
Elmax_2005.vcproj
Elmax_2008.vcproj
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcproj
Tryout.vcxproj.user
Tryout_2008.vcproj
Elmax-ver089
Elmax.vsmdi
Elmax
Elmax.vcxproj.user
Elmax_2005.vcproj
Elmax_2008.vcproj
StringUtils
ElmaxNet
Properties
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout
res
Tryout.ico
Tryout.vcproj
Tryout.vcxproj.user
Tryout_2008.vcproj
TryoutNet
Properties
Elmax.vsmdi
Elmax.vcxproj.user
Elmax_2005.vcproj
Elmax_2008.vcproj
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcproj
Tryout.vcxproj.user
Tryout_2008.vcproj
#include "StdAfx.h"
#include "StrUtil.h"
#include "..\\BaseConverter.h"
#include <cassert>

using namespace Elmax;

StrUtil::StrUtil(void)
{
}


StrUtil::~StrUtil(void)
{
}

std::wstring StrUtil::Format( 
	const wchar_t* fmt, 
	DataType D1 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( D1.ToString() );

	return Replace( wsfmtstr, vs );
}

std::wstring StrUtil::Format( 
	const wchar_t* fmt, 
	DataType D1, 
	DataType D2 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( D1.ToString() );
	vs.push_back( D2.ToString() );

	return Replace( wsfmtstr, vs );
}

std::wstring StrUtil::Format( 
	const wchar_t* fmt, 
	DataType D1, 
	DataType D2, 
	DataType D3 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( D1.ToString() );
	vs.push_back( D2.ToString() );
	vs.push_back( D3.ToString() );

	return Replace( wsfmtstr, vs );
}

std::wstring StrUtil::Format( 
	const wchar_t* fmt, 
	DataType D1, 
	DataType D2, 
	DataType D3, 
	DataType D4 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( D1.ToString() );
	vs.push_back( D2.ToString() );
	vs.push_back( D3.ToString() );
	vs.push_back( D4.ToString() );

	return Replace( wsfmtstr, vs );
}

std::wstring StrUtil::Format( 
	const wchar_t* fmt, 
	DataType D1, 
	DataType D2, 
	DataType D3, 
	DataType D4, 
	DataType D5 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( D1.ToString() );
	vs.push_back( D2.ToString() );
	vs.push_back( D3.ToString() );
	vs.push_back( D4.ToString() );
	vs.push_back( D5.ToString() );

	return Replace( wsfmtstr, vs );
}

std::wstring StrUtil::Format( 
	const wchar_t* fmt, 
	DataType D1, 
	DataType D2, 
	DataType D3, 
	DataType D4, 
	DataType D5, 
	DataType D6 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( D1.ToString() );
	vs.push_back( D2.ToString() );
	vs.push_back( D3.ToString() );
	vs.push_back( D4.ToString() );
	vs.push_back( D5.ToString() );
	vs.push_back( D6.ToString() );

	return Replace( wsfmtstr, vs );
}

std::wstring StrUtil::Format( 
	const wchar_t* fmt, 
	DataType D1, 
	DataType D2, 
	DataType D3, 
	DataType D4, 
	DataType D5, 
	DataType D6, 
	DataType D7 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( D1.ToString() );
	vs.push_back( D2.ToString() );
	vs.push_back( D3.ToString() );
	vs.push_back( D4.ToString() );
	vs.push_back( D5.ToString() );
	vs.push_back( D6.ToString() );
	vs.push_back( D7.ToString() );

	return Replace( wsfmtstr, vs );
}

std::wstring StrUtil::Format( 
	const wchar_t* fmt, 
	DataType D1, 
	DataType D2, 
	DataType D3, 
	DataType D4, 
	DataType D5, 
	DataType D6, 
	DataType D7, 
	DataType D8 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( D1.ToString() );
	vs.push_back( D2.ToString() );
	vs.push_back( D3.ToString() );
	vs.push_back( D4.ToString() );
	vs.push_back( D5.ToString() );
	vs.push_back( D6.ToString() );
	vs.push_back( D7.ToString() );
	vs.push_back( D8.ToString() );

	return Replace( wsfmtstr, vs );
}

std::wstring StrUtil::Format( 
	const wchar_t* fmt, 
	DataType D1, 
	DataType D2, 
	DataType D3, 
	DataType D4, 
	DataType D5, 
	DataType D6, 
	DataType D7, 
	DataType D8, 
	DataType D9 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( D1.ToString() );
	vs.push_back( D2.ToString() );
	vs.push_back( D3.ToString() );
	vs.push_back( D4.ToString() );
	vs.push_back( D5.ToString() );
	vs.push_back( D6.ToString() );
	vs.push_back( D7.ToString() );
	vs.push_back( D8.ToString() );
	vs.push_back( D9.ToString() );

	return Replace( wsfmtstr, vs );
}

std::wstring StrUtil::Format( 
	const wchar_t* fmt, 
	DataType D1, 
	DataType D2, 
	DataType D3, 
	DataType D4, 
	DataType D5, 
	DataType D6, 
	DataType D7, 
	DataType D8, 
	DataType D9, 
	DataType D10 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( D1.ToString() );
	vs.push_back( D2.ToString() );
	vs.push_back( D3.ToString() );
	vs.push_back( D4.ToString() );
	vs.push_back( D5.ToString() );
	vs.push_back( D6.ToString() );
	vs.push_back( D7.ToString() );
	vs.push_back( D8.ToString() );
	vs.push_back( D9.ToString() );
	vs.push_back( D10.ToString() );

	return Replace( wsfmtstr, vs );
}

std::wstring StrUtil::Replace( 
	std::wstring& fmtstr, 
	std::vector<std::wstring>& vs )
{
	size_t pos = 0;
	for( size_t i=0; i<vs.size(); ++i )
	{
		pos = 0;
		std::wstring anchor = Anchor( i );

		while( std::wstring::npos != pos )
		{
			pos = fmtstr.find( anchor, pos );

			if( std::wstring::npos != pos )
			{
				//fmtstr.replace( pos, 1, vs.at(i) );
				fmtstr.erase( pos, anchor.size() );
				fmtstr.insert( pos, vs.at(i) );
				pos += vs.at(i).size();
			}
		}
	}

	return fmtstr;
}

std::wstring StrUtil::Anchor( int i )
{
	std::wstring str2 = L"";
	BaseConverter conv;

	conv.SetInt32(str2, i);
	std::wstring str = L"{";
	str += str2 + L"}";

	return str;
}

size_t StrUtil::Split( 
	const std::wstring& StrToExtract,
	DataTypeRef D1 )
{
	std::vector<DataTypeRef*> vecDTR;
	vecDTR.push_back(&D1);

	assert( m_pSplitStrategy );
	return m_pSplitStrategy->Extract( StrToExtract, vecDTR );
}

size_t StrUtil::Split( 
	const std::wstring& StrToExtract,
	DataTypeRef D1,
	DataTypeRef D2 )
{
	std::vector<DataTypeRef*> vecDTR;
	vecDTR.push_back(&D1);
	vecDTR.push_back(&D2);

	assert( m_pSplitStrategy );
	return m_pSplitStrategy->Extract( StrToExtract, vecDTR );
}

size_t StrUtil::Split( 
	const std::wstring& StrToExtract,
	DataTypeRef D1,
	DataTypeRef D2,
	DataTypeRef D3 )
{
	std::vector<DataTypeRef*> vecDTR;
	vecDTR.push_back(&D1);
	vecDTR.push_back(&D2);
	vecDTR.push_back(&D3);

	assert( m_pSplitStrategy );
	return m_pSplitStrategy->Extract( StrToExtract, vecDTR );
}

size_t StrUtil::Split( 
	const std::wstring& StrToExtract,
	DataTypeRef D1,
	DataTypeRef D2,
	DataTypeRef D3,
	DataTypeRef D4 )
{
	std::vector<DataTypeRef*> vecDTR;
	vecDTR.push_back(&D1);
	vecDTR.push_back(&D2);
	vecDTR.push_back(&D3);
	vecDTR.push_back(&D4);

	assert( m_pSplitStrategy );
	return m_pSplitStrategy->Extract( StrToExtract, vecDTR );
}

size_t StrUtil::Split( 
	const std::wstring& StrToExtract,
	DataTypeRef D1,
	DataTypeRef D2,
	DataTypeRef D3,
	DataTypeRef D4,
	DataTypeRef D5 )
{
	std::vector<DataTypeRef*> vecDTR;
	vecDTR.push_back(&D1);
	vecDTR.push_back(&D2);
	vecDTR.push_back(&D3);
	vecDTR.push_back(&D4);
	vecDTR.push_back(&D5);

	assert( m_pSplitStrategy );
	return m_pSplitStrategy->Extract( StrToExtract, vecDTR );
}

size_t StrUtil::Split( 
	const std::wstring& StrToExtract,
	DataTypeRef D1,
	DataTypeRef D2,
	DataTypeRef D3,
	DataTypeRef D4,
	DataTypeRef D5,
	DataTypeRef D6 )
{
	std::vector<DataTypeRef*> vecDTR;
	vecDTR.push_back(&D1);
	vecDTR.push_back(&D2);
	vecDTR.push_back(&D3);
	vecDTR.push_back(&D4);
	vecDTR.push_back(&D5);
	vecDTR.push_back(&D6);

	assert( m_pSplitStrategy );
	return m_pSplitStrategy->Extract( StrToExtract, vecDTR );
}

size_t StrUtil::Split( 
	const std::wstring& StrToExtract,
	DataTypeRef D1,
	DataTypeRef D2,
	DataTypeRef D3,
	DataTypeRef D4,
	DataTypeRef D5,
	DataTypeRef D6,
	DataTypeRef D7 )
{
	std::vector<DataTypeRef*> vecDTR;
	vecDTR.push_back(&D1);
	vecDTR.push_back(&D2);
	vecDTR.push_back(&D3);
	vecDTR.push_back(&D4);
	vecDTR.push_back(&D5);
	vecDTR.push_back(&D6);
	vecDTR.push_back(&D7);

	assert( m_pSplitStrategy );
	return m_pSplitStrategy->Extract( StrToExtract, vecDTR );
}

size_t StrUtil::Split( 
	const std::wstring& StrToExtract,
	DataTypeRef D1,
	DataTypeRef D2,
	DataTypeRef D3,
	DataTypeRef D4,
	DataTypeRef D5,
	DataTypeRef D6,
	DataTypeRef D7,
	DataTypeRef D8 )
{
	std::vector<DataTypeRef*> vecDTR;
	vecDTR.push_back(&D1);
	vecDTR.push_back(&D2);
	vecDTR.push_back(&D3);
	vecDTR.push_back(&D4);
	vecDTR.push_back(&D5);
	vecDTR.push_back(&D6);
	vecDTR.push_back(&D7);
	vecDTR.push_back(&D8);

	assert( m_pSplitStrategy );
	return m_pSplitStrategy->Extract( StrToExtract, vecDTR );
}

size_t StrUtil::Split( 
	const std::wstring& StrToExtract,
	DataTypeRef D1,
	DataTypeRef D2,
	DataTypeRef D3,
	DataTypeRef D4,
	DataTypeRef D5,
	DataTypeRef D6,
	DataTypeRef D7,
	DataTypeRef D8,
	DataTypeRef D9 )
{
	std::vector<DataTypeRef*> vecDTR;
	vecDTR.push_back(&D1);
	vecDTR.push_back(&D2);
	vecDTR.push_back(&D3);
	vecDTR.push_back(&D4);
	vecDTR.push_back(&D5);
	vecDTR.push_back(&D6);
	vecDTR.push_back(&D7);
	vecDTR.push_back(&D8);
	vecDTR.push_back(&D9);

	assert( m_pSplitStrategy );
	return m_pSplitStrategy->Extract( StrToExtract, vecDTR );
}

size_t StrUtil::Split( 
	const std::wstring& StrToExtract,
	DataTypeRef D1,
	DataTypeRef D2,
	DataTypeRef D3,
	DataTypeRef D4,
	DataTypeRef D5,
	DataTypeRef D6,
	DataTypeRef D7,
	DataTypeRef D8,
	DataTypeRef D9,
	DataTypeRef D10 )
{
	std::vector<DataTypeRef*> vecDTR;
	vecDTR.push_back(&D1);
	vecDTR.push_back(&D2);
	vecDTR.push_back(&D3);
	vecDTR.push_back(&D4);
	vecDTR.push_back(&D5);
	vecDTR.push_back(&D6);
	vecDTR.push_back(&D7);
	vecDTR.push_back(&D8);
	vecDTR.push_back(&D9);
	vecDTR.push_back(&D10);

	assert( m_pSplitStrategy );
	return m_pSplitStrategy->Extract( StrToExtract, vecDTR );
}

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

Shao Voon Wong
Software Developer (Senior)
Singapore Singapore
Shao Voon is from Singapore. His CodeProject contributions could range from being used in game changer Large Hadron Collider (LHC) of CERN to smash particles to something as frivolous as Maplestory game to as life changing as electrocardiography(ECG) project to everyday indispensable Irfanview image viewer.

CodeProject awarded him a MVP award in recognition of his article contributions in 2019. In his spare time, he prefers to writing application based on 3rd party library than writing his own library. His interest lies primarily in computer graphics, software optimization, security and Agile methodologies.

One of these days, you can find him working on a DirectX based slideshow app called Mandy Frenzy.

You can reach him by sending a message on CodeProject or at his Coding Tidbit Blog!

Stats

34.5K views
477 downloads
29 bookmarked