static bool asJson(yarp::os::ConstString &accum, yarp::os::Value &v) { if (v.isInt()||v.isDouble()) { accum += v.toString(); return true; } if (v.isString()||v.isVocab()) { yarp::os::ConstString x = v.toString(); accum += "\""; for (int j=0; j<(int)x.length(); j++) { char ch = x[j]; if (ch=='\n') { accum += '\\'; accum += 'n'; } else if (ch=='\r') { accum += '\\'; accum += 'r'; } else if (ch=='\0') { accum += '\\'; accum += '0'; } else { if (ch=='\\'||ch=='\"') { accum += '\\'; } accum += ch; } } accum += "\""; } if (v.isList()) { yarp::os::Bottle *bot = v.asList(); return asJson(accum,bot); } return false; }
std::vector<double> YarpPoseController::bottle_to_vector(yarp::os::Value &val) { std::vector<double> values; if (!val.isList()) { throw StringException("Value not a list"); } Bottle* val_pointer = val.asList(); for (size_t i(0); i < val_pointer->size(); ++i) { if (val_pointer->get(i).isList()) { Bottle* val2_pointer = val_pointer->get(i).asList(); for (size_t i(0); i < val2_pointer->size(); ++i) values.push_back(val2_pointer->get(i).asDouble()); } else values.push_back(val_pointer->get(i).asDouble()); } return values; }
yarp::os::Value yarp::os::Searchable::check(const ConstString& key, const yarp::os::Value& fallback, const ConstString& comment) const { if (getMonitor()!=NULL && comment!="") { yarp::os::SearchReport report; report.key = key; report.value = comment; report.isComment = true; reportToMonitor(report); } if (getMonitor()!=NULL) { yarp::os::SearchReport report; report.key = key; report.value = fallback.toString(); report.isDefault = true; reportToMonitor(report); } yarp::os::Value& bit = find(key); bool ok = !(bit.isNull()); if (ok) { return bit; } return fallback; }
static void convertValue(JSContext * jct, JS::MutableHandleValue theData, const yarp::os::Value & inputValue) { ODL_ENTER(); //#### ODL_P2("jct = ", jct, "inputValue = ", &inputValue); //#### if (inputValue.isBool()) { theData.setBoolean(inputValue.asBool()); } else if (inputValue.isInt()) { theData.setInt32(inputValue.asInt()); } else if (inputValue.isString()) { YarpString value = inputValue.asString(); JSString * aString = JS_NewStringCopyZ(jct, value.c_str()); if (aString) { theData.setString(aString); } } else if (inputValue.isDouble()) { theData.setDouble(inputValue.asDouble()); } else if (inputValue.isDict()) { yarp::os::Property * value = inputValue.asDict(); if (value) { yarp::os::Bottle asList(value->toString()); convertDictionary(jct, theData, asList); } } else if (inputValue.isList()) { yarp::os::Bottle * value = inputValue.asList(); if (value) { yarp::os::Property asDict; if (ListIsReallyDictionary(*value, asDict)) { convertDictionary(jct, theData, *value); } else { convertList(jct, theData, *value); } } } else { // We don't know what to do with this... theData.setNull(); } ODL_EXIT(); //#### } // convertValue