Exemple #1
0
 /**
  * Import parameters from given json object.
  * Throw std::runtime_error if given json is malformated.
  */
 inline void loadJSON(const nlohmann::json& j)
 {
     //Empty case
     if (j.is_null()) {
         return;
     }
     //Check json type
     if (!j.is_object()) {
         throw std::runtime_error(
             "ParametersContainer load parameters json not object");
     }
     //Iterate on json entries
     for (nlohmann::json::const_iterator it=j.begin();it!=j.end();it++) {
         if (it.value().is_boolean()) {
             //Boolean
             if (_paramsBool.count(it.key()) == 0) {
                 throw std::runtime_error(
                     "ParametersContainer load parameters json bool does not exist: " 
                     + it.key());
             } else {
                 paramBool(it.key()).value = it.value();
             }
         } else if (it.value().is_number()) {
             //Number
             if (_paramsNumber.count(it.key()) == 0) {
                 throw std::runtime_error(
                     "ParametersContainer load parameters json number does not exist: " 
                     + it.key());
             } else {
                 paramNumber(it.key()).value = it.value();
             }
         } else if (it.value().is_string()) {
             //String
             if (_paramsStr.count(it.key()) == 0) {
                 throw std::runtime_error(
                     "ParametersContainer load parameters json str does not exist: " 
                     + it.key());
             } else {
                 paramStr(it.key()).value = it.value();
             }
         } else {
             throw std::runtime_error(
                 "ParametersContainer load parameters json malformated");
         }
     }
 }
/*
 * The check_equal function determines if the labels of the datanode and the querynode are equal.
 * The function iterates through all the labels of the query node and compares its value to that of the datanode.
 * It returns true only if all the labels match; returns false otherwises.
 */
    bool check_equal(nlohmann::json datanode, nlohmann::json querynode) {
        for (nlohmann::json::iterator it = querynode.begin(); it != querynode.end(); ++it) {
            if ((it.key() != "id") && (it.key() != "out_degree")) {
                if (datanode.find(it.key()) != datanode.end()) {
                    if(datanode[it.key()].is_string())
                    {
                        std::string d = datanode[it.key()], q= it.value();
                        if(d.find(q)== std::string::npos)
                            return false;
                    }
                    else if (datanode[it.key()] != it.value())
                        return false;
                } else
                    return false;
            }
        }
        return true;
    }