summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-07-09 10:24:32 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-07-09 10:24:32 -0400
commitf009f8da6b140f02f6463a43d336ab2644782fa1 (patch)
tree42ae287114dbc042e75f189c1237be2d81d7f41d
parentb8c09ed80d076f44b08d6aaa59fffd98abd55811 (diff)
Introduce LLSDParam<vector<T>> and LLSDParam<map<string, T>>.
Use LLSDParam<uuid_vec_t> in LLAppearanceListener::wearItems() and detachItems() to build the vector of LLUUIDs from the passed LLSD array.
-rw-r--r--indra/llcommon/llsdutil.h61
-rw-r--r--indra/newview/llappearancelistener.cpp33
2 files changed, 66 insertions, 28 deletions
diff --git a/indra/llcommon/llsdutil.h b/indra/llcommon/llsdutil.h
index 7c31dc8aa0..3f59222e9b 100644
--- a/indra/llcommon/llsdutil.h
+++ b/indra/llcommon/llsdutil.h
@@ -525,6 +525,67 @@ private:
} // namespace llsd
/*****************************************************************************
+* LLSDParam<std::vector<T>>
+*****************************************************************************/
+// Given an LLSD array, return a const std::vector<T>&, where T is a type
+// supported by LLSDParam. Bonus: if the LLSD value is actually a scalar,
+// return a single-element vector containing the converted value.
+template <typename T>
+class LLSDParam<std::vector<T>>: public LLSDParamBase
+{
+public:
+ LLSDParam(const LLSD& array)
+ {
+ // treat undefined "array" as empty vector
+ if (array.isDefined())
+ {
+ // what if it's a scalar?
+ if (! array.isArray())
+ {
+ v.push_back(LLSDParam<T>(array));
+ }
+ else // really is an array
+ {
+ // reserve space for the array entries
+ v.reserve(array.size());
+ for (const auto& item : llsd::inArray(array))
+ {
+ v.push_back(LLSDParam<T>(item));
+ }
+ }
+ }
+ }
+
+ operator const std::vector<T>&() const { return v; }
+
+private:
+ std::vector<T> v;
+};
+
+/*****************************************************************************
+* LLSDParam<std::map<std::string, T>>
+*****************************************************************************/
+// Given an LLSD map, return a const std::map<std::string, T>&, where T is a
+// type supported by LLSDParam.
+template <typename T>
+class LLSDParam<std::map<std::string, T>>: public LLSDParamBase
+{
+public:
+ LLSDParam(const LLSD& map)
+ {
+ for (const auto& pair : llsd::inMap(map))
+ {
+ m[pair.first] = LLSDParam<T>(pair.second);
+ }
+ }
+
+ operator const std::map<std::string, T>&() const { return m; }
+
+private:
+ std::map<std::string, T> m;
+};
+
+/*****************************************************************************
* deep and shallow clone
*****************************************************************************/
// Creates a deep clone of an LLSD object. Maps, Arrays and binary objects
diff --git a/indra/newview/llappearancelistener.cpp b/indra/newview/llappearancelistener.cpp
index c39799c5e9..0dab352311 100644
--- a/indra/newview/llappearancelistener.cpp
+++ b/indra/newview/llappearancelistener.cpp
@@ -91,38 +91,15 @@ void LLAppearanceListener::wearOutfit(LLSD const &data)
void LLAppearanceListener::wearItems(LLSD const &data)
{
- const LLSD& items_id{ data["items_id"] };
- uuid_vec_t ids;
- if (! items_id.isArray())
- {
- ids.push_back(items_id.asUUID());
- }
- else // array
- {
- for (const auto &id : llsd::inArray(items_id))
- {
- ids.push_back(id);
- }
- }
- LLAppearanceMgr::instance().wearItemsOnAvatar(ids, true, data["replace"].asBoolean());
+ LLAppearanceMgr::instance().wearItemsOnAvatar(
+ LLSDParam<uuid_vec_t>(data["items_id"]),
+ true, data["replace"].asBoolean());
}
void LLAppearanceListener::detachItems(LLSD const &data)
{
- const LLSD& items_id{ data["items_id"] };
- uuid_vec_t ids;
- if (! items_id.isArray())
- {
- ids.push_back(items_id.asUUID());
- }
- else // array
- {
- for (const auto &id : llsd::inArray(items_id))
- {
- ids.push_back(id);
- }
- }
- LLAppearanceMgr::instance().removeItemsFromAvatar(ids);
+ LLAppearanceMgr::instance().removeItemsFromAvatar(
+ LLSDParam<uuid_vec_t>(data["items_id"]));
}
void LLAppearanceListener::getOutfitsList(LLSD const &data)