Raised This Month: $ Target: $400
 0% 

[SP] ConfigMap: StringMap & SMCParser


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
nergal
Veteran Member
Join Date: Apr 2012
Old 09-28-2020 , 13:09   Re: [SP] ConfigMap: StringMap & SMCParser
Reply With Quote #10

Quote:
Originally Posted by MAGNAT2645 View Post
That's just a stock which returns true (only if string treated as true) or false (in any other case), you don't have to use it. It was just an example of simple/advanced conversion.
alright, put this code in your cfgmap.inc and test out how it goes:

Code:
	public int GetBool(const char[] key_path, bool& b, bool simple=true) {
		if( this==null ) {
			return 0;
		}
		PackVal val;
		bool result = this.GetVal(key_path, val);
		if( result && val.tag==KeyValType_Value ) {
			val.data.Reset();
			char[] strval = new char[val.size];
			val.data.ReadString(strval, val.size);
			if( simple ) {
				b = StringToInt(strval) != 0;
			} else {
				if( !strcmp(strval, "true", false) || !strcmp(strval, "1", false) ) {
					b = true;
				} else if( !strcmp(strval, "false", false) || !strcmp(strval, "0", false) ) {
					b = false;
				} else {
					return 0;
				}
			}
			return val.size - 1;
		}
		return 0;
	}
__________________

Last edited by nergal; 09-28-2020 at 13:10.
nergal is offline
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:51.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode