From ab04d116cc47fa979018525fce4f11b379aeeec5 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 3 Sep 2024 12:35:55 -0400 Subject: Break out llinventorylistener.cpp's InvResultSet as LL::ResultSet. We may well want to leverage that API for additional queries that could potentially return large datasets. --- indra/llcommon/resultset.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 indra/llcommon/resultset.cpp (limited to 'indra/llcommon/resultset.cpp') diff --git a/indra/llcommon/resultset.cpp b/indra/llcommon/resultset.cpp new file mode 100644 index 0000000000..ee8cc68c6c --- /dev/null +++ b/indra/llcommon/resultset.cpp @@ -0,0 +1,93 @@ +/** + * @file resultset.cpp + * @author Nat Goodspeed + * @date 2024-09-03 + * @brief Implementation for resultset. + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Copyright (c) 2024, Linden Research, Inc. + * $/LicenseInfo$ + */ + +// Precompiled header +#include "linden_common.h" +// associated header +#include "resultset.h" +// STL headers +// std headers +// external library headers +// other Linden headers +#include "llerror.h" +#include "llsdutil.h" + +namespace LL +{ + +LLSD ResultSet::getKeyLength() const +{ + return llsd::array(getKey(), getLength()); +} + +std::pair ResultSet::getSliceStart(int index, int count) const +{ + // only call getLength() once + auto length = getLength(); + // Adjust bounds [start, end) to overlap the actual result set from + // [0, getLength()). Permit negative index; e.g. with a result set + // containing 5 entries, getSlice(-2, 5) will adjust start to 0 and + // end to 3. + int start = llclamp(index, 0, length); + int end = llclamp(index + count, 0, length); + LLSD result{ LLSD::emptyArray() }; + // beware of count <= 0, or an [index, count) range that doesn't even + // overlap [0, length) at all + if (end > start) + { + // right away expand the result array to the size we'll need + result[end - 1] = LLSD(); + for (int i = start; i < end; ++i) + { + result[i] = getSingle(i); + } + } + return { result, start }; +} + +LLSD ResultSet::getSlice(int index, int count) const +{ + return getSliceStart(index, count).first; +} + +/*==========================================================================*| +LLSD ResultSet::getSingle(int index) const +{ + if (0 <= index && index < getLength()) + { + return getSingle_(index); + } + else + { + return {}; + } +} +|*==========================================================================*/ + +ResultSet::ResultSet(const std::string& name): + mName(name) +{ + LL_DEBUGS("Lua") << *this << LL_ENDL; +} + +ResultSet::~ResultSet() +{ + // We want to be able to observe that the consuming script eventually + // destroys each of these ResultSets. + LL_DEBUGS("Lua") << "~" << *this << LL_ENDL; +} + +} // namespace LL + +std::ostream& operator<<(std::ostream& out, const LL::ResultSet& self) +{ + return out << "ResultSet(" << self.mName << ", " << self.getKey() << ")"; +} -- cgit v1.2.3 From 517163c126f7c0620f506532d67d9097083728d9 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 3 Sep 2024 18:02:31 -0400 Subject: Fix a bug in ResultSet::getSliceStart(). When asked to retrieve a slice starting at an `index > 0`, `getSliceStart()` was returning an LLSD array whose first `index` entries were `isUndefined()`, followed by the desired data. Fix to omit those undefined entries. --- indra/llcommon/resultset.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'indra/llcommon/resultset.cpp') diff --git a/indra/llcommon/resultset.cpp b/indra/llcommon/resultset.cpp index ee8cc68c6c..cb46db04fa 100644 --- a/indra/llcommon/resultset.cpp +++ b/indra/llcommon/resultset.cpp @@ -43,11 +43,14 @@ std::pair ResultSet::getSliceStart(int index, int count) const // overlap [0, length) at all if (end > start) { - // right away expand the result array to the size we'll need - result[end - 1] = LLSD(); - for (int i = start; i < end; ++i) + // Right away expand the result array to the size we'll need. + // (end - start) is that size; (end - start - 1) is the index of the + // last entry in result. + result[end - start - 1] = LLSD(); + for (int i = 0; (start + i) < end; ++i) { - result[i] = getSingle(i); + // For this to be a slice, set result[0] = getSingle(start), etc. + result[i] = getSingle(start + i); } } return { result, start }; -- cgit v1.2.3 From 49bf86b52459b183d3988388dbb74d8888a71925 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 5 Sep 2024 08:45:24 -0400 Subject: Fix a few trailing whitespaces. --- indra/llcommon/resultset.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon/resultset.cpp') diff --git a/indra/llcommon/resultset.cpp b/indra/llcommon/resultset.cpp index cb46db04fa..4d7b00eabd 100644 --- a/indra/llcommon/resultset.cpp +++ b/indra/llcommon/resultset.cpp @@ -3,7 +3,7 @@ * @author Nat Goodspeed * @date 2024-09-03 * @brief Implementation for resultset. - * + * * $LicenseInfo:firstyear=2024&license=viewerlgpl$ * Copyright (c) 2024, Linden Research, Inc. * $/LicenseInfo$ -- cgit v1.2.3