diff options
| author | Callum Prentice <callum@lindenlab.com> | 2025-08-22 17:12:03 -0700 |
|---|---|---|
| committer | Callum Prentice <callum@lindenlab.com> | 2025-08-22 17:12:03 -0700 |
| commit | e935a8aebca4ae014b5f6b438612ac5674678fe6 (patch) | |
| tree | 531498d040a62c01d444fe91eb99afb091c7fff4 /indra/llcommon/llsdutil.h | |
| parent | bebd1b208e1b342fabf59844851124a91513e83b (diff) | |
| parent | cefee59b0e5fff683a50fe61633a9c14493d7145 (diff) | |
Merge branch 'develop' into callum/viewer-cef-2025-08
Diffstat (limited to 'indra/llcommon/llsdutil.h')
| -rw-r--r-- | indra/llcommon/llsdutil.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/indra/llcommon/llsdutil.h b/indra/llcommon/llsdutil.h index c31030c5ea..497c0ad3eb 100644 --- a/indra/llcommon/llsdutil.h +++ b/indra/llcommon/llsdutil.h @@ -554,6 +554,45 @@ LLSD shallow(LLSD value, LLSD filter=LLSD()) { return llsd_shallow(value, filter } // 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; +}; + + +/***************************************************************************** * toArray(), toMap() *****************************************************************************/ namespace llsd |
