Commit b8558496 authored by jan.koester's avatar jan.koester
Browse files

more elegant

parent 70aa8e11
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ void confplus::Yaml::loadConfig(const char *path,Config *conf){

    bool seq=false;
    std::string key,value;

    int pos = 0;
    do {
        yaml_event_t event;
        if (!yaml_parser_parse(&parse, &event))
@@ -133,10 +133,14 @@ void confplus::Yaml::loadConfig(const char *path,Config *conf){
            }
            cname+=key;
            Config::ConfigData *ckey=conf->setKey(cname.c_str());
            conf->setValue(ckey,0,value.c_str());
            conf->setValue(ckey,pos,value.c_str());
            value.clear();
            if(!seq)
            if(!seq){
                pos=0;
                key.clear();
            }else{
                ++pos;
            }
        }
        type=event.type;
        yaml_event_delete(&event);
+8 −13
Original line number Diff line number Diff line
@@ -253,13 +253,10 @@ const char * confplus::Config::getValue(confplus::Config::ConfigData* key, size_
        throw err;
    }

    size_t lvl=0;

    for(ConfigValue *cur=key->Value; cur; cur=cur->_nextValue){
        if(lvl==pos){
        if(cur->_Pos==pos){
            return cur->_Value.c_str();
        }
        ++lvl;
    }

    return nullptr;
@@ -278,20 +275,18 @@ void confplus::Config::setValue(confplus::Config::ConfigData* key, size_t pos, c
        }
    }

    ConfigValue *cur=key->Value,*bef=nullptr;
    ConfigValue **cur=&key->Value;

    while(cur){
        bef=cur;
        cur=cur->_nextValue;
    while(*cur){
        cur=&(*cur)->_nextValue;
    };

    if(!bef){
        bef = new ConfigValue();
    if(!*cur){
        *cur = new ConfigValue();
    }

    bef->_nextValue = new ConfigValue();
    bef->_Value = value;
    bef->_Pos = pos;
    (*cur)->_Value = value;
    (*cur)->_Pos = pos;

    ++key->Elements;

+3 −2
Original line number Diff line number Diff line
@@ -33,8 +33,9 @@
int main(int argc,char *argv[]){
    try{
        confplus::Config conf(argv[1]);
        if(conf.getKey("/BLOGI/HTTP/DOMAIN")){
            std::cout << "success" << std::endl;
        confplus::Config::ConfigData *domainkey=conf.getKey("/BLOGI/HTTP/DOMAIN");
        if(domainkey){
            std::cout << conf.getValue(domainkey,0) << std::endl;
        }
    }catch(confplus::ConfException &e){
        std::cerr << e.what() << std::endl;