void LLRadioGroup::setValue( const LLSD& value ) { int idx = 0; for (button_list_t::const_iterator iter = mRadioButtons.begin(); iter != mRadioButtons.end(); ++iter) { LLRadioCtrl* radio = *iter; if (radio->getPayload().asString() == value.asString()) { setSelectedIndex(idx); idx = -1; break; } ++idx; } if (idx != -1) { // string not found, try integer if (value.isInteger()) { setSelectedIndex((S32) value.asInteger(), TRUE); } else { llwarns << "LLRadioGroup::setValue: value not found: " << value.asString() << llendl; } } }
void SDTestObject::test<10>() // map operations { SDCleanupCheck check; LLSD v; ensure("undefined has no members", !v.has("amy")); ensure("undefined get() is undefined", v.get("bob").isUndefined()); v = LLSD::emptyMap(); ensure("empty map is a map", v.isMap()); ensure("empty map has no members", !v.has("cam")); ensure("empty map get() is undefined", v.get("don").isUndefined()); v.clear(); v.insert("eli", 43); ensure("insert converts to map", v.isMap()); ensure("inserted key is present", v.has("eli")); ensureTypeAndValue("inserted value", v.get("eli"), 43); v.insert("fra", false); ensure("first key still present", v.has("eli")); ensure("second key is present", v.has("fra")); ensureTypeAndValue("first value", v.get("eli"), 43); ensureTypeAndValue("second value", v.get("fra"), false); v.erase("eli"); ensure("first key now gone", !v.has("eli")); ensure("second key still present", v.has("fra")); ensure("first value gone", v.get("eli").isUndefined()); ensureTypeAndValue("second value sill there", v.get("fra"), false); v.erase("fra"); ensure("second key now gone", !v.has("fra")); ensure("second value gone", v.get("fra").isUndefined()); v["gil"] = (std::string)"good morning"; ensure("third key present", v.has("gil")); ensureTypeAndValue("third key value", v.get("gil"), "good morning"); const LLSD& cv = v; // FIX ME IF POSSIBLE ensure("missing key", cv["ham"].isUndefined()); ensure("key not present", !v.has("ham")); LLSD w = 43; const LLSD& cw = w; // FIX ME IF POSSIBLE int i = cw["ian"]; ensureTypeAndValue("other missing value", i, 0); ensure("other missing key", !w.has("ian")); ensure("no conversion", w.isInteger()); LLSD x; x = v; ensure("copy map type", x.isMap()); ensureTypeAndValue("copy map value gil", x.get("gil"), "good morning"); }
void LLAvatarActions::teleport_request_callback(const LLSD& notification, const LLSD& response) { S32 option; if (response.isInteger()) { option = response.asInteger(); } else { option = LLNotificationsUtil::getSelectedOption(notification, response); } if (0 == option) { LLMessageSystem* msg = gMessageSystem; msg->newMessageFast(_PREHASH_ImprovedInstantMessage); msg->nextBlockFast(_PREHASH_AgentData); msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); msg->nextBlockFast(_PREHASH_MessageBlock); msg->addBOOLFast(_PREHASH_FromGroup, FALSE); msg->addUUIDFast(_PREHASH_ToAgentID, notification["substitutions"]["uuid"] ); msg->addU8Fast(_PREHASH_Offline, IM_ONLINE); msg->addU8Fast(_PREHASH_Dialog, IM_TELEPORT_REQUEST); msg->addUUIDFast(_PREHASH_ID, LLUUID::null); msg->addU32Fast(_PREHASH_Timestamp, NO_TIMESTAMP); // no timestamp necessary std::string name; LLAgentUI::buildFullname(name); msg->addStringFast(_PREHASH_FromAgentName, name); msg->addStringFast(_PREHASH_Message, response["message"]); msg->addU32Fast(_PREHASH_ParentEstateID, 0); msg->addUUIDFast(_PREHASH_RegionID, LLUUID::null); msg->addVector3Fast(_PREHASH_Position, gAgent.getPositionAgent()); gMessageSystem->addBinaryDataFast( _PREHASH_BinaryBucket, EMPTY_BINARY_BUCKET, EMPTY_BINARY_BUCKET_SIZE); gAgent.sendReliableMessage(); } }
LLPathfindingLinkset::ENavMeshGenerationCategory LLPathfindingLinkset::convertCategoryFromLLSD(const LLSD &llsd) { ENavMeshGenerationCategory navMeshGenerationCategory; llassert(llsd.isInteger()); switch (llsd.asInteger()) { case LINKSET_CATEGORY_VALUE_IGNORE : navMeshGenerationCategory = kNavMeshGenerationIgnore; break; case LINKSET_CATEGORY_VALUE_INCLUDE : navMeshGenerationCategory = kNavMeshGenerationInclude; break; case LINKSET_CATEGORY_VALUE_EXCLUDE : navMeshGenerationCategory = kNavMeshGenerationExclude; break; default : navMeshGenerationCategory = kNavMeshGenerationIgnore; llassert(0); break; } return navMeshGenerationCategory; }
// see docstring in .h file std::string llsd_matches(const LLSD& prototype, const LLSD& data, const std::string& pfx) { // An undefined prototype means that any data is valid. // An undefined slot in an array or map prototype means that any data // may fill that slot. if (prototype.isUndefined()) return ""; // A prototype array must match a data array with at least as many // entries. Moreover, every prototype entry must match the // corresponding data entry. if (prototype.isArray()) { if (! data.isArray()) { return STRINGIZE(colon(pfx) << "Array" << op << sTypes.lookup(data.type())); } if (data.size() < prototype.size()) { return STRINGIZE(colon(pfx) << "Array size " << prototype.size() << op << "Array size " << data.size()); } for (LLSD::Integer i = 0; i < prototype.size(); ++i) { std::string match(llsd_matches(prototype[i], data[i], STRINGIZE('[' << i << ']'))); if (! match.empty()) { return match; } } return ""; } // A prototype map must match a data map. Every key in the prototype // must have a corresponding key in the data map; every value in the // prototype must match the corresponding key's value in the data. if (prototype.isMap()) { if (! data.isMap()) { return STRINGIZE(colon(pfx) << "Map" << op << sTypes.lookup(data.type())); } // If there are a number of keys missing from the data, it would be // frustrating to a coder to discover them one at a time, with a big // build each time. Enumerate all missing keys. std::ostringstream out; out << colon(pfx); const char* init = "Map missing keys: "; const char* sep = init; for (LLSD::map_const_iterator mi = prototype.beginMap(); mi != prototype.endMap(); ++mi) { if (! data.has(mi->first)) { out << sep << mi->first; sep = ", "; } } // So... are we missing any keys? if (sep != init) { return out.str(); } // Good, the data block contains all the keys required by the // prototype. Now match the prototype entries. for (LLSD::map_const_iterator mi2 = prototype.beginMap(); mi2 != prototype.endMap(); ++mi2) { std::string match(llsd_matches(mi2->second, data[mi2->first], STRINGIZE("['" << mi2->first << "']"))); if (! match.empty()) { return match; } } return ""; } // A String prototype can match String, Boolean, Integer, Real, UUID, // Date and URI, because any of these can be converted to String. if (prototype.isString()) { static LLSD::Type accept[] = { LLSD::TypeBoolean, LLSD::TypeInteger, LLSD::TypeReal, LLSD::TypeUUID, LLSD::TypeDate, LLSD::TypeURI }; return match_types(prototype.type(), TypeVector(boost::begin(accept), boost::end(accept)), data.type(), pfx); } // Boolean, Integer, Real match each other or String. TBD: ensure that // a String value is numeric. if (prototype.isBoolean() || prototype.isInteger() || prototype.isReal()) { static LLSD::Type all[] = { LLSD::TypeBoolean, LLSD::TypeInteger, LLSD::TypeReal, LLSD::TypeString }; // Funny business: shuffle the set of acceptable types to include all // but the prototype's type. Get the acceptable types in a set. std::set<LLSD::Type> rest(boost::begin(all), boost::end(all)); // Remove the prototype's type because we pass that separately. rest.erase(prototype.type()); return match_types(prototype.type(), TypeVector(rest.begin(), rest.end()), data.type(), pfx); } // UUID, Date and URI match themselves or String. if (prototype.isUUID() || prototype.isDate() || prototype.isURI()) { static LLSD::Type accept[] = { LLSD::TypeString }; return match_types(prototype.type(), TypeVector(boost::begin(accept), boost::end(accept)), data.type(), pfx); } // We don't yet know the conversion semantics associated with any new LLSD // data type that might be added, so until we've been extended to handle // them, assume it's strict: the new type matches only itself. (This is // true of Binary, which is why we don't handle that case separately.) Too // bad LLSD doesn't define isConvertible(Type to, Type from). return match_types(prototype.type(), TypeVector(), data.type(), pfx); }