Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » TextSettings update
TextSettings update [message #19976] Fri, 06 February 2009 19:29 Go to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
TextSettings is fairly useless right now. There is no way to handle an INI file without knowing what is inside.

I propose these changes:
class TextSettings {
	VectorMap< String, VectorMap< String, String > > settings;

public:
	String Get(const char *group, const char *key) const;
	String Get(const char *key) const                            { return Get("", key); }
	String Get(int groupIndex, const char *key) const;
	String Get(int groupIndex, int keyIndex) const;
	
	String operator()(const char *group, const char *key) const  { return Get(group, key); }
	String operator()(const char *key) const                     { return Get(key); }

	void Clear()                                                 { settings.Clear(); }
	void Load(const char *filename);
	
	int GetGroupCount()                                          { return settings.GetCount(); }
	int GetKeyCount(int group)                                   { return settings[group].GetCount(); }
	
	String GetGroupName(int groupIndex)                          { return settings.GetKey(groupIndex); }
	String GetKey(int groupIndex, int keyIndex)                  { return settings[groupIndex].GetKey(keyIndex); }
};


String TextSettings::Get(const char *group, const char *key) const
{
	int itemi = settings.Find(group);
	return itemi < 0 ? Null : settings.Get(group).Get(key, Null);
}

String TextSettings::Get(int groupIndex, const char *key) const
{
	return groupIndex >= 0 && groupIndex < settings.GetCount() ? settings[groupIndex].Get(key, Null) : Null;
}

String TextSettings::Get(int groupIndex, int keyIndex) const
{
	if (groupIndex >= 0 && groupIndex < settings.GetCount())
		return keyIndex >= 0 && keyIndex < settings[groupIndex].GetCount() ? settings[groupIndex][keyIndex] : Null;
	else
		return Null;
}
Re: TextSettings update [message #19986 is a reply to message #19976] Sun, 08 February 2009 08:03 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, why not. In Core now.

Mirek
Re: TextSettings update [message #33627 is a reply to message #19976] Thu, 01 September 2011 14:08 Go to previous messageGo to next message
navinv is currently offline  navinv
Messages: 8
Registered: September 2010
Promising Member
Hi Mirek,

I am using TextSettings, currently you can't have any whitespace before or after the equal sign. I have to write like this...
[MySQL]
host=localhost
user=root
password=mysql
db=insure

But instead I would prefer to write like
[MySQL]
host     = localhost
user     = root
password = mysql
db       = insure

I propose a minor change to handle the whitespaces before and after the equal sign.

Util.cpp, Line 444

settings[themei].GetAdd(key) = value;

settings[themei].GetAdd(TrimBoth(key)) = TrimBoth(value);
Re: TextSettings update [message #33633 is a reply to message #33627] Fri, 02 September 2011 10:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, why not.

Mirek
Re: TextSettings update [message #35399 is a reply to message #33633] Fri, 10 February 2012 06:44 Go to previous message
navinv is currently offline  navinv
Messages: 8
Registered: September 2010
Promising Member
Hi Mirek,

After update to 4193, I realized that you have updated the Util.cpp as I suggested, Thank you. But I am not able to understand why you have left the key variable.

Is there any particular reason why you did this.

This is what I suggested
settings[themei].GetAdd(TrimBoth(key)) = TrimBoth(value);


This is what you did
settings[themei].GetAdd(key) = TrimBoth(value);


Regards
Previous Topic: problem with new and delete
Next Topic: Out of memory panic
Goto Forum:
  


Current Time: Fri Apr 19 23:23:08 CEST 2024

Total time taken to generate the page: 0.02285 seconds