Commit 845b1f86 authored by jan.koester's avatar jan.koester
Browse files

test

parent 43d332f5
Loading
Loading
Loading
Loading
+23 −6
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@

#include <iostream>
#include <algorithm>
#include <functional>

#include <cstdio>
#include <string>
@@ -136,13 +137,29 @@ confplus::Config::ConfigData *confplus::Config::setKey(const std::string &key){
}

void confplus::Config::delKey(confplus::Config::ConfigData* key){
    ConfigData *bef=nullptr;
    for(ConfigData *cur=firstData.get(); cur; cur=cur->nextData.get()){
        if(cur==key){
            bef->nextData=std::move(key->nextData);
        }
        bef=cur;
    }
    // Search recursively through the entire tree to find and unlink the key
    std::function<bool(std::unique_ptr<ConfigData>&)> searchAndDelete;
    searchAndDelete = [&](std::unique_ptr<ConfigData> &root) -> bool {
        // Check if root itself is the target (first in sibling list)
        if (root.get() == key) {
            root = std::move(key->nextData);
            return true;
        }
        // Search siblings
        for (ConfigData *cur = root.get(); cur; cur = cur->nextData.get()) {
            if (cur->nextData.get() == key) {
                cur->nextData = std::move(key->nextData);
                return true;
            }
            // Search children
            if (cur->Child && searchAndDelete(cur->Child))
                return true;
        }
        return false;
    };

    if (firstData)
        searchAndDelete(firstData);
}