From f009f8da6b140f02f6463a43d336ab2644782fa1 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 9 Jul 2024 10:24:32 -0400 Subject: Introduce LLSDParam> and LLSDParam>. Use LLSDParam in LLAppearanceListener::wearItems() and detachItems() to build the vector of LLUUIDs from the passed LLSD array. --- indra/llcommon/llsdutil.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'indra/llcommon') 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 @@ -524,6 +524,67 @@ private: } // namespace llsd +/***************************************************************************** +* LLSDParam> +*****************************************************************************/ +// Given an LLSD array, return a const std::vector&, 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 +class LLSDParam>: 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(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(item)); + } + } + } + } + + operator const std::vector&() const { return v; } + +private: + std::vector v; +}; + +/***************************************************************************** +* LLSDParam> +*****************************************************************************/ +// Given an LLSD map, return a const std::map&, where T is a +// type supported by LLSDParam. +template +class LLSDParam>: public LLSDParamBase +{ +public: + LLSDParam(const LLSD& map) + { + for (const auto& pair : llsd::inMap(map)) + { + m[pair.first] = LLSDParam(pair.second); + } + } + + operator const std::map&() const { return m; } + +private: + std::map m; +}; + /***************************************************************************** * deep and shallow clone *****************************************************************************/ -- cgit v1.2.3