bool jsval_to_std_map_string_string(JSContext *cx, jsval v, std::map<std::string, std::string>* ret) { if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) { return true; } JSObject* tmp = JSVAL_TO_OBJECT(v); if (!tmp) { CCLOG("%s", "jsval_to_ccvaluemap: the jsval is not an object."); return false; } JSObject* it = JS_NewPropertyIterator(cx, tmp); while (true) { jsid idp; jsval key; if (! JS_NextProperty(cx, it, &idp) || ! JS_IdToValue(cx, idp, &key)) { return false; // error } if (key == JSVAL_VOID) { break; // end of iteration } if (!JSVAL_IS_STRING(key)) { continue; // ignore integer properties } JSStringWrapper keyWrapper(JSVAL_TO_STRING(key), cx); JS::RootedValue value(cx); JS_GetPropertyById(cx, tmp, idp, &value); if (value.isString()) { JSStringWrapper valueWapper(JSVAL_TO_STRING(value), cx); ret->insert(std::make_pair(keyWrapper.get(), valueWapper.get())); } else { CCASSERT(false, "not a string"); } } return true; }
value_struct::operator map<string, xmlrpc_c::value>() const { this->validateInstantiated(); env_wrap env; unsigned int structSize; structSize = xmlrpc_struct_size(&env.env_c, this->cValueP); throwIfError(env); map<string, xmlrpc_c::value> retval; for (unsigned int i = 0; i < structSize; ++i) { class cMemberWrapper { public: xmlrpc_value *keyP; xmlrpc_value *valueP; cMemberWrapper(xmlrpc_value *const structP, unsigned int const index) { env_wrap env; xmlrpc_struct_read_member(&env.env_c, structP, index, &keyP, &valueP); throwIfError(env); } ~cMemberWrapper() { xmlrpc_DECREF(keyP); xmlrpc_DECREF(valueP); } }; cMemberWrapper memberWrapper(this->cValueP, i); cStringWrapper keyWrapper(memberWrapper.keyP); string const key(keyWrapper.str, keyWrapper.length); retval[key] = xmlrpc_c::value(memberWrapper.valueP); } return retval; }