diff options
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llcommon/resultset.cpp | 14 | ||||
-rw-r--r-- | indra/llcommon/resultset.h | 21 | ||||
-rw-r--r-- | indra/newview/llagentlistener.cpp | 24 | ||||
-rw-r--r-- | indra/newview/llinventorylistener.cpp | 40 |
4 files changed, 36 insertions, 63 deletions
diff --git a/indra/llcommon/resultset.cpp b/indra/llcommon/resultset.cpp index 4d7b00eabd..8bdfbec272 100644 --- a/indra/llcommon/resultset.cpp +++ b/indra/llcommon/resultset.cpp @@ -61,20 +61,6 @@ 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) { diff --git a/indra/llcommon/resultset.h b/indra/llcommon/resultset.h index 90d52b6fe4..10d84c038f 100644 --- a/indra/llcommon/resultset.h +++ b/indra/llcommon/resultset.h @@ -17,6 +17,7 @@ #include "llsd.h" #include <iosfwd> // std::ostream #include <utility> // std::pair +#include <vector> namespace LL { @@ -41,11 +42,6 @@ struct ResultSet: public LLIntTracker<ResultSet> LLSD getSlice(int index, int count) const; // Like getSlice(), but also return adjusted start position. std::pair<LLSD, int> getSliceStart(int index, int count) const; -/*==========================================================================*| - // Retrieve LLSD corresponding to a single entry from the result set, - // with index validation. - LLSD getSingle(int index) const; -|*==========================================================================*/ /*---------------- the rest is solely for debug logging ----------------*/ std::string mName; @@ -54,6 +50,21 @@ struct ResultSet: public LLIntTracker<ResultSet> virtual ~ResultSet(); }; +// VectorResultSet is for the simple case of a ResultSet managing a single +// std::vector<T>. +template <typename T> +struct VectorResultSet: public ResultSet +{ + using super = VectorResultSet<T>; + + VectorResultSet(const std::string& name): ResultSet(name) {} + int getLength() const override { return narrow(mVector.size()); } + LLSD getSingle(int index) const override { return getSingleFrom(mVector[index]); } + virtual LLSD getSingleFrom(const T&) const = 0; + + std::vector<T> mVector; +}; + } // namespace LL std::ostream& operator<<(std::ostream& out, const LL::ResultSet& self); diff --git a/indra/newview/llagentlistener.cpp b/indra/newview/llagentlistener.cpp index 2810cd6706..3d07ead95d 100644 --- a/indra/newview/llagentlistener.cpp +++ b/indra/newview/llagentlistener.cpp @@ -729,15 +729,11 @@ void LLAgentListener::getID(LLSD const& event_data) Response response(llsd::map("id", gAgentID), event_data); } -struct AvResultSet : public LL::ResultSet +struct AvResultSet : public LL::VectorResultSet<LLVOAvatar*> { - AvResultSet() : LL::ResultSet("nearby_avatars") {} - std::vector<LLVOAvatar*> mAvatars; - - int getLength() const override { return narrow(mAvatars.size()); } - LLSD getSingle(int index) const override + AvResultSet() : super("nearby_avatars") {} + LLSD getSingleFrom(LLVOAvatar* const& av) const override { - auto av = mAvatars[index]; LLAvatarName av_name; LLAvatarNameCache::get(av->getID(), &av_name); LLVector3 region_pos = av->getCharacterPosition(); @@ -749,15 +745,11 @@ struct AvResultSet : public LL::ResultSet } }; -struct ObjResultSet : public LL::ResultSet +struct ObjResultSet : public LL::VectorResultSet<LLViewerObject*> { - ObjResultSet() : LL::ResultSet("nearby_objects") {} - std::vector<LLViewerObject*> mObjects; - - int getLength() const override { return narrow(mObjects.size()); } - LLSD getSingle(int index) const override + ObjResultSet() : super("nearby_objects") {} + LLSD getSingleFrom(LLViewerObject* const& obj) const override { - auto obj = mObjects[index]; return llsd::map("id", obj->getID(), "global_pos", ll_sd_from_vector3d(obj->getPositionGlobal()), "region_pos", ll_sd_from_vector3(obj->getPositionRegion()), @@ -791,7 +783,7 @@ void LLAgentListener::getNearbyAvatarsList(LLSD const& event_data) { if ((dist_vec_squared(avatar->getPositionGlobal(), agent_pos) <= radius)) { - avresult->mAvatars.push_back(avatar); + avresult->mVector.push_back(avatar); } } } @@ -813,7 +805,7 @@ void LLAgentListener::getNearbyObjectsList(LLSD const& event_data) { if ((dist_vec_squared(object->getPositionGlobal(), agent_pos) <= radius)) { - objresult->mObjects.push_back(object); + objresult->mVector.push_back(object); } } } diff --git a/indra/newview/llinventorylistener.cpp b/indra/newview/llinventorylistener.cpp index 88b07c0b0b..13ca12a69a 100644 --- a/indra/newview/llinventorylistener.cpp +++ b/indra/newview/llinventorylistener.cpp @@ -107,15 +107,11 @@ LLInventoryListener::LLInventoryListener() // This struct captures (possibly large) category results from // getDirectDescendants() and collectDescendantsIf(). -struct CatResultSet: public LL::ResultSet +struct CatResultSet: public LL::VectorResultSet<LLInventoryModel::cat_array_t::value_type> { - CatResultSet(): LL::ResultSet("categories") {} - LLInventoryModel::cat_array_t mCategories; - - int getLength() const override { return narrow(mCategories.size()); } - LLSD getSingle(int index) const override + CatResultSet(): super("categories") {} + LLSD getSingleFrom(const LLPointer<LLViewerInventoryCategory>& cat) const override { - auto cat = mCategories[index]; return llsd::map("id", cat->getUUID(), "name", cat->getName(), "parent_id", cat->getParentUUID(), @@ -125,15 +121,11 @@ struct CatResultSet: public LL::ResultSet // This struct captures (possibly large) item results from // getDirectDescendants() and collectDescendantsIf(). -struct ItemResultSet: public LL::ResultSet +struct ItemResultSet: public LL::VectorResultSet<LLInventoryModel::item_array_t::value_type> { - ItemResultSet(): LL::ResultSet("items") {} - LLInventoryModel::item_array_t mItems; - - int getLength() const override { return narrow(mItems.size()); } - LLSD getSingle(int index) const override + ItemResultSet(): super("items") {} + LLSD getSingleFrom(const LLPointer<LLViewerInventoryItem>& item) const override { - auto item = mItems[index]; return llsd::map("id", item->getUUID(), "name", item->getName(), "parent_id", item->getParentUUID(), @@ -160,14 +152,14 @@ void LLInventoryListener::getItemsInfo(LLSD const &data) LLViewerInventoryItem* item = gInventory.getItem(it); if (item) { - itemresult->mItems.push_back(item); + itemresult->mVector.push_back(item); } else { LLViewerInventoryCategory *cat = gInventory.getCategory(it); if (cat) { - catresult->mCategories.push_back(cat); + catresult->mVector.push_back(cat); } } } @@ -202,8 +194,8 @@ void LLInventoryListener::getDirectDescendants(LLSD const &data) auto catresult = new CatResultSet; auto itemresult = new ItemResultSet; - catresult->mCategories = *cats; - itemresult->mItems = *items; + catresult->mVector = *cats; + itemresult->mVector = *items; response["categories"] = catresult->getKeyLength(); response["items"] = itemresult->getKeyLength(); @@ -260,8 +252,8 @@ void LLInventoryListener::collectDescendantsIf(LLSD const &data) // collectDescendentsIf() method so it doesn't steal too many cycles. gInventory.collectDescendentsIf( folder_id, - catresult->mCategories, - itemresult->mItems, + catresult->mVector, + itemresult->mVector, LLInventoryModel::EXCLUDE_TRASH, collector); @@ -269,14 +261,6 @@ void LLInventoryListener::collectDescendantsIf(LLSD const &data) response["items"] = itemresult->getKeyLength(); } -/*==========================================================================*| -void LLInventoryListener::getSingle(LLSD const& data) -{ - auto result = LL::ResultSet::getInstance(data["result"]); - sendReply(llsd::map("single", result->getSingle(data["index"])), data); -} -|*==========================================================================*/ - void LLInventoryListener::getSlice(LLSD const& data) { auto result = LL::ResultSet::getInstance(data["result"]); |