Raised This Month: $32 Target: $400
 8% 

[SP] ConfigMap: StringMap & SMCParser


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
nergal
Veteran Member
Join Date: Apr 2012
Old 11-18-2019 , 20:47   [SP] ConfigMap: StringMap & SMCParser
Reply With Quote #1

presenting ConfigMap which is a StringMap Tree very much similar to KeyValues.

Difference is that it only works with strings as values and stringmaps as sections.


API:
Code:
ConfigMap(const char[] filename);

int GetSize(const char[] key_path);

int Get(const char[] key_path, char[] buffer, int buf_size);

ConfigMap GetSection(const char[] key_path);

KeyValType GetKeyValType(const char[] key_path);

int GetInt(const char[] key_path, int& i, int base=10);

int GetFloat(const char[] key_path, float& f);

stock void DeleteCfg(ConfigMap& cfg, bool clear_only=false);
Accessing values and sections is easy:

assume this config:
Code:
"root" {
    "value1"    "howdy"
    "section1" {
        "value1"    "hi"
    }
    
    "section2" {
        "subsection1" {
            "value1"    "bonjour"
        }
    }
}
to access the value "howdy", use the key path string: "root.value1"
to access the value "hi", use the key path string: "root.section1.value1"
to access the value "bonjour", use the key path string: "root.section2.subsection1.value1"

to reduce having to use these key path strings all the time on frequently used subsections, use `GetSection` to save the ConfigMap of a subsection, there is no need to free the instance to the subsection.

Download Link
Tutorial on how to use it.

Features:
Iterating key-values by number.
Retrieving keys in a performant manner.
Partial string interpolation.
Math parsing with custom variables.
__________________

Last edited by nergal; 08-26-2023 at 17:03. Reason: new version.
nergal is offline
 



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 23:23.


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