diff --git a/Jupiter/ArrayList.h b/Jupiter/ArrayList.h index a76c667..99d1302 100644 --- a/Jupiter/ArrayList.h +++ b/Jupiter/ArrayList.h @@ -52,6 +52,13 @@ namespace Jupiter */ T *remove(size_t index); + /** + * @brief Removes the last element in the list, and returns the data removed. + * + * @return Data removed. + */ + T *pop(); + /** * @brief Adds data to the list at a specified index. * @@ -182,6 +189,11 @@ template T *Jupiter::ArrayList::remove(size_t index) return r; } +template T *Jupiter::ArrayList::pop() +{ + return Jupiter::ArrayList::data[--Jupiter::List::length]; +} + template void Jupiter::ArrayList::add(T *ndata, size_t index) { if (Jupiter::List::length == Jupiter::ArrayList::dataSize) Jupiter::ArrayList::expandArray(); diff --git a/Jupiter/IRC_Client.cpp b/Jupiter/IRC_Client.cpp index 6282bf0..bbec229 100644 --- a/Jupiter/IRC_Client.cpp +++ b/Jupiter/IRC_Client.cpp @@ -115,8 +115,15 @@ struct Jupiter::IRC::Client::Channel::User::Data { Jupiter::IRC::Client::User *user; Jupiter::StringS prefixes; + + ~Data(); }; +Jupiter::IRC::Client::Channel::User::Data::~Data() +{ + --Jupiter::IRC::Client::Channel::User::Data::user->data_->channelCount; +} + struct Jupiter::IRC::Client::Channel::Data { Jupiter::StringS channel; @@ -1054,7 +1061,7 @@ int Jupiter::IRC::Client::primaryHandler() this->OnPart(chan, nick, reason); for (i = Jupiter::plugins->size() - 1; i >= 0; i--) Jupiter::plugins->get(i)->OnPart(this, chan, nick, reason); if (nick.equalsi(Jupiter::IRC::Client::data_->nickname)) Jupiter::IRC::Client::data_->delChannel(chan); - if (user->getChannelCount() == 0) Jupiter::IRC::Client::data_->users.remove(userIndex); + if (user->getChannelCount() == 0) delete Jupiter::IRC::Client::data_->users.remove(userIndex); } } } @@ -1090,7 +1097,7 @@ int Jupiter::IRC::Client::primaryHandler() Jupiter::IRC::Client::data_->delChannel(chan); if (Jupiter::IRC::Client::data_->joinOnKick) Jupiter::IRC::Client::joinChannel(chan); } - if (user->getChannelCount() == 0) Jupiter::IRC::Client::data_->users.remove(userIndex); + if (user->getChannelCount() == 0) delete Jupiter::IRC::Client::data_->users.remove(userIndex); } } } @@ -1110,7 +1117,7 @@ int Jupiter::IRC::Client::primaryHandler() Jupiter::IRC::Client::data_->channels.get(i)->delUser(nick); this->OnQuit(nick, message); for (i = 0; i < Jupiter::plugins->size(); i++) Jupiter::plugins->get(i)->OnQuit(this, nick, message); - if (user->getChannelCount() == 0) Jupiter::IRC::Client::data_->users.remove(userIndex); + if (user->getChannelCount() == 0) delete Jupiter::IRC::Client::data_->users.remove(userIndex); } } else if (w2.equalsi("INVITE")) @@ -1617,11 +1624,7 @@ void Jupiter::IRC::Client::Channel::delUser(const Jupiter::ReadableString &nickn void Jupiter::IRC::Client::Channel::delUser(size_t index) { if (index < Jupiter::IRC::Client::Channel::data_->users.size()) - { - Jupiter::IRC::Client::Channel::User *user = Jupiter::IRC::Client::Channel::data_->users.remove(index); - user->data_->user->data_->channelCount--; - delete user; - } + delete Jupiter::IRC::Client::Channel::data_->users.remove(index); } void Jupiter::IRC::Client::Channel::addUserPrefix(size_t index, char prefix) diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index 0b4e025..dd0d014 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ