Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

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

, 7 Jun 2012
Linq-To-XML Node Creation for Native C++
elmax-84498.zip
BuildProcessTemplates
ElmaxNet
Properties
Elmax
Elmax.vcxproj.user
StringUtils
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TryoutNet
Properties
Settings.settings
Tryout
res
Tryout.ico
Tryout.vcxproj.user
elmax-ver083.zip
Elmax.vcxproj.user
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver084.zip
Elmax.vcxproj.user
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver085.zip
Elmax.vcxproj.user
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver086.zip
Elmax.vcxproj.user
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver087.zip
Elmax.vcxproj.user
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
Settings.settings
Tryout.ico
Tryout.vcxproj.user
Elmax-ver089.zip
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
Settings.settings
ElmaxSrcVer082.zip
Elmax.vcxproj.user
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
Settings.settings
Tryout.ico
Tryout.vcxproj.user
/*
TextOut Library for Native C++ version 1.1.2

Copyright (c) 2007 - 2008 Wong Shao Voon

The Code Project Open License (CPOL)
http://www.codeproject.com/info/cpol10.aspx
*/

#include "stdafx.h"
#include "AbstractTextout.h"


void AbstractTextout::Print( 
	const wchar_t* fmt)
{
	std::wstring wsfmtstr = fmt;

	Process(wsfmtstr);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box D1 )
{
	std::wstring wsfmtstr = fmt;

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

	std::wstring str = StrReplace( wsfmtstr, vs );

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box D1, Box D2 )
{
	std::wstring wsfmtstr = fmt;

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

	std::wstring str = StrReplace( wsfmtstr, vs );

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box D1, Box D2, Box 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() );

	std::wstring str = StrReplace( wsfmtstr, vs );

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box D1, Box D2, Box D3, Box 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() );

	std::wstring str = StrReplace( wsfmtstr, vs );

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box D1, Box D2, Box D3, Box D4, Box 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() );

	std::wstring str = StrReplace( wsfmtstr, vs );

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box D1, Box D2, Box D3, Box D4, Box D5, Box 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() );

	std::wstring str = StrReplace( wsfmtstr, vs );

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box D1, Box D2, Box D3, Box D4, Box D5, Box D6, Box 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() );

	std::wstring str = StrReplace( wsfmtstr, vs );

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box D1, Box D2, Box D3, Box D4, 
	Box D5, Box D6, Box D7, Box 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() );

	std::wstring str = StrReplace( wsfmtstr, vs );

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box D1, Box D2, Box D3, Box D4, 
	Box D5, Box D6, Box D7, Box D8, Box 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() );

	std::wstring str = StrReplace( wsfmtstr, vs );

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box D1, Box D2, Box D3, Box D4, Box D5, 
	Box D6, Box D7, Box D8, Box D9, Box 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() );

	std::wstring str = StrReplace( wsfmtstr, vs );

	Process(str);
}

std::wstring AbstractTextout::StrReplace( 
	std::wstring& fmtstr, 
	const std::vector<std::wstring>& vs )
{
	size_t pos = 0;
	for( size_t i=0; i<vs.size(); ++i )
	{
		pos = 0;
		std::wstring anchor = StrAnchor( 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 AbstractTextout::StrAnchor( size_t i )
{
	std::wstring str = L"{";

	wchar_t buf[20];
	memset( buf, 0, sizeof(buf) );
	errno_t nRet = _itow_s( i, buf, sizeof(buf)/sizeof(wchar_t), 10 );

	if( 0 == nRet )
		str += buf;

	str += L"}";

	return str;
}

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)

About the Author

Wong Shao Voon
Software Developer
Singapore Singapore

Currently into areas like 3D graphics and application security. Hoping to revisit the cryptography and design pattern topics if time permits.


| Advertise | Privacy | Mobile
Web03 | 2.8.140718.1 | Last Updated 7 Jun 2012
Article Copyright 2011 by Wong Shao Voon
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid