Archived

This topic is now archived and is closed to further replies.

psykr

Setting << int

Recommended Posts

I have a class that represents a single setting in-game (e.g. fullscreen on, resolution, etc). Now, I''m trying to add support for multiple ints, so that I can do Setting( L"window_position" ) << x << y, but the problem is that with multiple calls, I get window_position x,y,x,y,x,y,x,y,etc with the following code:
// set an int in settings registry

Setting& Setting::operator << ( int const n ) {
	// if letters exist, add comma

	if( parameter.length() > 0 )
		parameter += L'','';

	// add number to end of string

	std::wstringstream wss;
	std::wstring temp;
	wss << n; wss >> temp;
	parameter += temp;

	return *this;
}
I can''t figure out a way to get around this problem, other than breaking it up into Setting( L"window_position.x" ) << x, but I don''t want to do that. Any ideas to prevent getting "window_position x,y,x,y,x,y,x,y"?

Share this post


Link to post
Share on other sites
Umm....
// set an int in settings registry

Setting& Setting::operator << ( int const n ) {
static int numParameters = 0;
if (numParameters >= maxParameters) {
parameter = L"";
numParameters = 0;
}
// if letters exist, add comma

if( parameter.length() > 0 )
parameter += L',';

// add number to end of string

std::wstringstream wss;
std::wstring temp;
wss << n; wss >> temp;
parameter += temp;
++numParameters;
return *this;
}


Then maxParameters would be defined by each instance of the class (perhaps it's a constant and is filled on initialization).

[EDIT] Wide character...

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________


[edited by - Thunder_Hawk on October 7, 2003 8:03:36 PM]

Share this post


Link to post
Share on other sites