AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [INC] NestedStringMap - StringMaps.. But with nesting (https://forums.alliedmods.net/showthread.php?t=304459)

Kinsi 01-16-2018 00:46

[INC] NestedStringMap - StringMaps.. But with nesting
 
7 Attachment(s)
Had the idea to do this for a while, came around to do it today because i happened to be reminded of it and was bored.

Example:

PHP Code:

        //Create a nested stringmap object with enabled Iteration
    
NestedStringMap topLevel = new NestedStringMap(true);
    
    
//Child does not exist yet, will be created, written into the parent, and returned
    
NestedStringMap child topLevel.Child("firstChild");
    
    
//Creates a sub-child in the created child, and sets the value of SomeKey to 1337
    
child.Child("child1").SetValue("SomeKey"1337);
    
    
//Retrieves the set key from the created sub-child
    
LogMessage("Read: %i"child.Child("child1").GetAndReturnValue("SomeKey"));
    
    
//Creates some more sub-childs because why not. We'll disable Iteration for these, 
    //thus no ArrayLists will be created / maintained alongside of them.
    
child.Child("child2"Iterator_Disable);
    
child.Child("child3"Iterator_Disable);
    
    
//iterating over the children of the first child-NestedStringMap
    
NestedStringMapChildren NSMC;
    
    if(
child.GetIterator(NSMC)) {
        for(
int i 0NSMC.Lengthi++) {
            
char childName[255];
            
            
NestedStringMap x view_as<NestedStringMap>(NSMC.GetChild(i));
            
            
x.GetName(childNamesizeof(childName));
            
            
LogMessage("Child %i in NestedStringMap %i has name %s"ichildchildName);
        }
    }
    
    
//Retrieve the sub-child from the child, go back to its parent again and close that.
    //Yes, it essentially is no different than "child.Close()";
    //Calling Close() will take care of also closing any possibly nested children
    
child.Child("child3").Parent().Close();
    
    
//Finally close the top level NestedStringMap
    
topLevel.Close(); 

Source: https://github.com/kinsi55/NestedStringMap

Have ideas for things to implement? PR them.

HF bois

RumbleFrog 01-16-2018 00:56

Re: [INC] NestedStringMap - StringMaps.. But with nesting
 
Ay, thanks for implementing my request. Time to make something stupid.

Kinsi 01-18-2018 00:09

Re: [INC] NestedStringMap - StringMaps.. But with nesting
 
Update: Added iterator support.

ThatKidWhoGames 05-21-2018 13:57

Re: [INC] NestedStringMap - StringMaps.. But with nesting
 
Thanks for this!!


All times are GMT -4. The time now is 09:28.

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