Click here to Skip to main content
12,248,339 members (48,164 online)
Click here to Skip to main content

Stats

21.3K views
429 downloads
27 bookmarked
Posted

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

, 12 Apr 2016 Ms-PL
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
/*
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 box1 )
{
	std::wstring wsfmtstr = fmt;

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

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

	Process(str);
}

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

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

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

	Process(str);
}

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

	std::vector<std::wstring> vs;
	vs.push_back( box1.ToString() );
	vs.push_back( box2.ToString() );
	vs.push_back( box3.ToString() );

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

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box box1, Box box2, Box box3, Box box4 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( box1.ToString() );
	vs.push_back( box2.ToString() );
	vs.push_back( box3.ToString() );
	vs.push_back( box4.ToString() );

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

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box box1, Box box2, Box box3, Box box4, Box box5 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( box1.ToString() );
	vs.push_back( box2.ToString() );
	vs.push_back( box3.ToString() );
	vs.push_back( box4.ToString() );
	vs.push_back( box5.ToString() );

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

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box box1, Box box2, Box box3, Box box4, Box box5, Box box6 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( box1.ToString() );
	vs.push_back( box2.ToString() );
	vs.push_back( box3.ToString() );
	vs.push_back( box4.ToString() );
	vs.push_back( box5.ToString() );
	vs.push_back( box6.ToString() );

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

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box box1, Box box2, Box box3, Box box4, Box box5, Box box6, Box box7 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( box1.ToString() );
	vs.push_back( box2.ToString() );
	vs.push_back( box3.ToString() );
	vs.push_back( box4.ToString() );
	vs.push_back( box5.ToString() );
	vs.push_back( box6.ToString() );
	vs.push_back( box7.ToString() );

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

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box box1, Box box2, Box box3, Box box4, 
	Box box5, Box box6, Box box7, Box box8 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( box1.ToString() );
	vs.push_back( box2.ToString() );
	vs.push_back( box3.ToString() );
	vs.push_back( box4.ToString() );
	vs.push_back( box5.ToString() );
	vs.push_back( box6.ToString() );
	vs.push_back( box7.ToString() );
	vs.push_back( box8.ToString() );

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

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box box1, Box box2, Box box3, Box box4, 
	Box box5, Box box6, Box box7, Box box8, Box box9 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( box1.ToString() );
	vs.push_back( box2.ToString() );
	vs.push_back( box3.ToString() );
	vs.push_back( box4.ToString() );
	vs.push_back( box5.ToString() );
	vs.push_back( box6.ToString() );
	vs.push_back( box7.ToString() );
	vs.push_back( box8.ToString() );
	vs.push_back( box9.ToString() );

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

	Process(str);
}

void AbstractTextout::Print( 
	const wchar_t* fmt, 
	Box box1, Box box2, Box box3, Box box4, Box box5, 
	Box box6, Box box7, Box box8, Box box9, Box box10 )
{
	std::wstring wsfmtstr = fmt;

	std::vector<std::wstring> vs;
	vs.push_back( box1.ToString() );
	vs.push_back( box2.ToString() );
	vs.push_back( box3.ToString() );
	vs.push_back( box4.ToString() );
	vs.push_back( box5.ToString() );
	vs.push_back( box6.ToString() );
	vs.push_back( box7.ToString() );
	vs.push_back( box8.ToString() );
	vs.push_back( box9.ToString() );
	vs.push_back( box10.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)

Share

About the Author

Shao Voon Wong
Software Developer (Senior)
Singapore Singapore
IT Certifications

  • IT Infrastructure Library Foundational (ITIL v3)
  • Scrum Alliance Certified Scrum Master (CSM)
  • EC-Council Certified Secure Programmer (ECSP) .NET
  • EC-Council Certified Ethical Hacker (CEH)
  • EC-Council Certified Security Analyst (ECSA)
  • Certified Secure Software Lifecycle Professional (CSSLP)

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160426.1 | Last Updated 12 Apr 2016
Article Copyright 2016 by Shao Voon Wong
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid