View Single Post
Author Message
Kinsi
Senior Member
Join Date: Apr 2013
Old 01-16-2018 , 00:46   [INC] NestedStringMap - StringMaps.. But with nesting
Reply With Quote #1

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
Attached Files
File Type: inc NestedStringMap.inc (9.3 KB, 237 views)
File Type: sp Get Plugin or Get Source (NestedStringMapExample.sp - 213 views - 1.9 KB)
__________________

Last edited by Kinsi; 01-18-2018 at 01:01.
Kinsi is offline