From 5a5c7b4f12a97f027259abee01e00476588a063e Mon Sep 17 00:00:00 2001 From: phosit Date: Fri, 27 Mar 2026 19:02:53 +0100 Subject: [PATCH] Use unique_ptr for glox::Tag in XmppClient --- source/lobby/XmppClient.cpp | 31 ++++++------------------------- source/lobby/XmppClient.h | 7 ++++--- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/source/lobby/XmppClient.cpp b/source/lobby/XmppClient.cpp index 8c3384d607..bc54e951e5 100644 --- a/source/lobby/XmppClient.cpp +++ b/source/lobby/XmppClient.cpp @@ -211,13 +211,6 @@ XmppClient::~XmppClient() m_client->removePresenceExtension(gloox::ExtCaps); delete m_client; - - for (const gloox::Tag* const& t : m_GameList) - delete t; - for (const gloox::Tag* const& t : m_BoardList) - delete t; - for (const gloox::Tag* const& t : m_Profile) - delete t; } /// Network @@ -280,18 +273,12 @@ void XmppClient::onDisconnect(gloox::ConnectionError error) m_mucRoom->leave(); // Clear game, board and player lists. - for (const gloox::Tag* const& t : m_GameList) - delete t; - for (const gloox::Tag* const& t : m_BoardList) - delete t; - for (const gloox::Tag* const& t : m_Profile) - delete t; - - m_BoardList.clear(); m_GameList.clear(); + m_BoardList.clear(); + m_Profile.clear(); + m_PlayerMap.clear(); m_PlayerMapUpdate = true; - m_Profile.clear(); m_HistoricGuiMessages.clear(); m_initialLoadComplete = false; @@ -619,7 +606,7 @@ JS::Value XmppClient::GUIGetGameList(const ScriptRequest& rq) "nbp", "maxnbp", "players", "mapName", "niceMapName", "mapSize", "mapType", "victoryConditions", "startTime", "mods" }; - for(const gloox::Tag* const& t : m_GameList) + for(const std::unique_ptr& t : m_GameList) { JS::RootedValue game(rq.cx); Script::CreateObject(rq, &game); @@ -644,7 +631,7 @@ JS::Value XmppClient::GUIGetBoardList(const ScriptRequest& rq) const char* attributes[] = { "name", "rank", "rating" }; - for(const gloox::Tag* const& t : m_BoardList) + for(const std::unique_ptr& t : m_BoardList) { JS::RootedValue board(rq.cx); Script::CreateObject(rq, &board); @@ -669,7 +656,7 @@ JS::Value XmppClient::GUIGetProfile(const ScriptRequest& rq) const char* stats[] = { "player", "rating", "totalGamesPlayed", "highestRating", "wins", "losses", "rank" }; - for (const gloox::Tag* const& t : m_Profile) + for (const std::unique_ptr& t : m_Profile) { JS::RootedValue profile(rq.cx); Script::CreateObject(rq, &profile); @@ -887,8 +874,6 @@ bool XmppClient::handleIq(const gloox::IQ& iq) return true; } - for (const gloox::Tag* const& t : m_GameList) - delete t; m_GameList.clear(); for (const gloox::Tag* const& t : gq->m_GameList) @@ -906,8 +891,6 @@ bool XmppClient::handleIq(const gloox::IQ& iq) if (bq->m_Command == "boardlist") { - for (const gloox::Tag* const& t : m_BoardList) - delete t; m_BoardList.clear(); for (const gloox::Tag* const& t : bq->m_StanzaBoardList) @@ -937,8 +920,6 @@ bool XmppClient::handleIq(const gloox::IQ& iq) return true; } - for (const gloox::Tag* const& t : m_Profile) - delete t; m_Profile.clear(); for (const gloox::Tag* const& t : pq->m_StanzaProfile) diff --git a/source/lobby/XmppClient.h b/source/lobby/XmppClient.h index 87bf741f00..dec6848710 100644 --- a/source/lobby/XmppClient.h +++ b/source/lobby/XmppClient.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -181,11 +182,11 @@ private: /// Whether or not the playermap has changed since the last time the GUI checked. bool m_PlayerMapUpdate; /// List of games - std::vector m_GameList; + std::vector> m_GameList; /// List of rankings - std::vector m_BoardList; + std::vector> m_BoardList; /// Profile data - std::vector m_Profile; + std::vector> m_Profile; /// ScriptInterface to root the values const ScriptInterface* m_ScriptInterface; /// Queue of messages for the GUI