jeudi 29 juillet 2021

Poco::Dynamic::Var created empty object by operator []

I try to check the parameter is existing in Poco::Dynamic::Var. But after checking I found that source object is changed. Appeared a new parameter, which I checked.

Problem:

How to check the presence of a parameter in an Poco::Dynamic::Var without modifying the source object.

Code example:

void checkParamInConfig(Poco::Dynamic::Var &conf) {
    std::cout << "before:" << conf.toString() << std::endl;

    // new key problem
    if (conf["Configuration"]["NewParam"].isEmpty()) {
        std::cout<<"NewParam not found"<<std::endl;
    }
    
    std::cout << "after:" << conf.toString() << std::endl;
}

Output:

before:{ "Configuration" : { "Param1" : true, "Param2" : true, "Param3" : true } }
NewParam not found
after:{ "Configuration" : { "NewParam" : null, "Param1" : true, "Param2" : true, "Param3" : true } }  

Aucun commentaire:

Enregistrer un commentaire