summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-16 19:20:30 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-16 19:20:30 +0200
commit69258182848b2781b0081d82453d33f42dd81679 (patch)
tree38d64cf8b1884727b941aecb95562f4390ad482b
parent736795a624ae5f04b11fa284cb8a4b14579c1766 (diff)
downloadmana-69258182848b2781b0081d82453d33f42dd81679.tar.gz
mana-69258182848b2781b0081d82453d33f42dd81679.tar.bz2
mana-69258182848b2781b0081d82453d33f42dd81679.tar.xz
mana-69258182848b2781b0081d82453d33f42dd81679.zip
Some cleanups
* std::string arguments to 'const std::string &' * findMember2 renamed to findOrCreateMember * Made some functions const
-rw-r--r--src/gui/partywindow.cpp16
-rw-r--r--src/gui/partywindow.h37
-rw-r--r--src/gui/widgets/channeltab.cpp11
-rw-r--r--src/gui/widgets/channeltab.h5
-rw-r--r--src/gui/widgets/chattab.cpp2
-rw-r--r--src/gui/widgets/chattab.h5
-rw-r--r--src/gui/widgets/whispertab.cpp8
-rw-r--r--src/gui/widgets/whispertab.h5
-rw-r--r--src/net/ea/gui/partytab.cpp2
-rw-r--r--src/net/ea/gui/partytab.h2
10 files changed, 49 insertions, 44 deletions
diff --git a/src/gui/partywindow.cpp b/src/gui/partywindow.cpp
index 08698dab..c13a0810 100644
--- a/src/gui/partywindow.cpp
+++ b/src/gui/partywindow.cpp
@@ -54,9 +54,9 @@ void PartyWindow::draw(gcn::Graphics *graphics)
Window::draw(graphics);
}
-PartyMember *PartyWindow::findMember(int id)
+PartyMember *PartyWindow::findMember(int id) const
{
- PartyList::iterator it = mMembers.find(id);
+ PartyList::const_iterator it = mMembers.find(id);
if (it == mMembers.end())
return NULL;
@@ -64,7 +64,7 @@ PartyMember *PartyWindow::findMember(int id)
return it->second;
}
-PartyMember *PartyWindow::findMember2(int id)
+PartyMember *PartyWindow::findOrCreateMember(int id)
{
PartyMember *member = findMember(id);
@@ -79,10 +79,10 @@ PartyMember *PartyWindow::findMember2(int id)
return member;
}
-int PartyWindow::findMember(const std::string &name)
+int PartyWindow::findMember(const std::string &name) const
{
- PartyList::iterator itr = mMembers.begin(),
- itr_end = mMembers.end();
+ PartyList::const_iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
while (itr != itr_end)
{
@@ -97,10 +97,10 @@ int PartyWindow::findMember(const std::string &name)
}
void PartyWindow::updateMember(int id, const std::string &memberName,
- bool leader, bool online)
+ bool leader, bool online)
{
// create new party member
- PartyMember *player = findMember2(id);
+ PartyMember *player = findOrCreateMember(id);
player->id = id;
player->name = memberName;
player->leader = leader;
diff --git a/src/gui/partywindow.h b/src/gui/partywindow.h
index 60c4da29..3729cc09 100644
--- a/src/gui/partywindow.h
+++ b/src/gui/partywindow.h
@@ -49,77 +49,74 @@ struct PartyMember
};
/**
- * Party Window.
+ * Party window.
*
* \ingroup Interface
*/
class PartyWindow : public Window, gcn::ActionListener
{
public:
- /**
- * Constructor.
- */
PartyWindow();
/**
- * Release all the players created
+ * Release all the players created.
*/
~PartyWindow();
/**
- * Draws the party window
+ * Draws the party window.
*/
void draw(gcn::Graphics *graphics);
/**
* Find a party member based on ID. Returns NULL if not found.
*/
- PartyMember *findMember(int id);
-
- /**
- * Find a party member based on ID. Creates if not found.
- */
- PartyMember *findMember2(int id);
+ PartyMember *findMember(int id) const;
/**
* Returns the id of the first member found with the given name or -1
* if it isn't found.
*/
- int findMember(const std::string &name);
+ int findMember(const std::string &name) const;
/**
- * Update/add a party member
+ * Update/add a party member.
*/
void updateMember(int id, const std::string &memberName,
- bool leader = false, bool online = true);
+ bool leader = false, bool online = true);
/**
- * Remove party member
+ * Remove party member with the given id.
*/
void removeMember(int id);
/**
- * Remove party member
+ * Remove party member with the given name.
*/
void removeMember(const std::string &name);
/**
- * Remove party member
+ * Updates the online state of the member with the given id.
*/
void updateOnlne(int id, bool online);
/**
- * Show party invite
+ * Show party invite.
*/
void showPartyInvite(const std::string &inviter,
const std::string &partyName = "");
/**
- * Handle events
+ * Handle events.
*/
void action(const gcn::ActionEvent &event);
private:
+ /**
+ * Find a party member based on ID. Creates if not found.
+ */
+ PartyMember *findOrCreateMember(int id);
+
typedef std::map<int, PartyMember*> PartyList;
PartyList mMembers;
std::string mPartyInviter;
diff --git a/src/gui/widgets/channeltab.cpp b/src/gui/widgets/channeltab.cpp
index 0bafc10f..e3edbba0 100644
--- a/src/gui/widgets/channeltab.cpp
+++ b/src/gui/widgets/channeltab.cpp
@@ -28,8 +28,9 @@
#include "utils/gettext.h"
-ChannelTab::ChannelTab(Channel *channel) : ChatTab(channel->getName()),
- mChannel(channel)
+ChannelTab::ChannelTab(Channel *channel) :
+ ChatTab(channel->getName()),
+ mChannel(channel)
{
channel->setTab(this);
}
@@ -38,7 +39,8 @@ ChannelTab::~ChannelTab()
{
}
-void ChannelTab::handleInput(const std::string &msg) {
+void ChannelTab::handleInput(const std::string &msg)
+{
Net::getChatHandler()->sendToChannel(getChannel()->getId(), msg);
}
@@ -51,7 +53,8 @@ void ChannelTab::showHelp()
chatLog(_("/kick > Kick a user from the channel"));
}
-bool ChannelTab::handleCommand(std::string type, std::string args)
+bool ChannelTab::handleCommand(const std::string &type,
+ const std::string &args)
{
if (type == "help")
{
diff --git a/src/gui/widgets/channeltab.h b/src/gui/widgets/channeltab.h
index 886ae28e..2f668b89 100644
--- a/src/gui/widgets/channeltab.h
+++ b/src/gui/widgets/channeltab.h
@@ -33,11 +33,12 @@ class ChannelTab : public ChatTab
{
public:
- Channel *getChannel() { return mChannel; }
+ Channel *getChannel() const { return mChannel; }
void showHelp();
- bool handleCommand(std::string type, std::string args);
+ bool handleCommand(const std::string &type,
+ const std::string &args);
protected:
friend class Channel;
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index 0e3ae423..44840423 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -274,7 +274,7 @@ void ChatTab::handleInput(const std::string &msg) {
Net::getChatHandler()->talk(msg);
}
-void ChatTab::handleCommand(std::string msg)
+void ChatTab::handleCommand(const std::string &msg)
{
commandHandler->handleCommand(msg, this);
}
diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h
index ccb85d2a..27c27480 100644
--- a/src/gui/widgets/chattab.h
+++ b/src/gui/widgets/chattab.h
@@ -113,7 +113,8 @@ class ChatTab : public Tab
* @returns true if the command was handled
* false if the command was not handled
*/
- virtual bool handleCommand(std::string type, std::string args)
+ virtual bool handleCommand(const std::string &type,
+ const std::string &args)
{ return false; }
protected:
@@ -124,7 +125,7 @@ class ChatTab : public Tab
virtual void handleInput(const std::string &msg);
- virtual void handleCommand(std::string msg);
+ virtual void handleCommand(const std::string &msg);
ScrollArea *mScrollArea;
BrowserBox *mTextOutput;
diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp
index 975cac94..87a88222 100644
--- a/src/gui/widgets/whispertab.cpp
+++ b/src/gui/widgets/whispertab.cpp
@@ -43,7 +43,8 @@ WhisperTab::~WhisperTab()
chatWindow->removeWhisper(mNick);
}
-void WhisperTab::handleInput(const std::string &msg) {
+void WhisperTab::handleInput(const std::string &msg)
+{
if (msg.length() == 0) {
chatLog(_("Cannot send empty chat!"), BY_SERVER, false);
return;
@@ -55,7 +56,7 @@ void WhisperTab::handleInput(const std::string &msg) {
msg.c_str()), BY_PLAYER, false);
}
-void WhisperTab::handleCommand(std::string msg)
+void WhisperTab::handleCommand(const std::string &msg)
{
if (msg == "close")
delete this;
@@ -68,7 +69,8 @@ void WhisperTab::showHelp()
chatLog(_("/close > Close the whisper tab"));
}
-bool WhisperTab::handleCommand(std::string type, std::string args)
+bool WhisperTab::handleCommand(const std::string &type,
+ const std::string &args)
{
if (type == "help")
{
diff --git a/src/gui/widgets/whispertab.h b/src/gui/widgets/whispertab.h
index 0d39b6ec..af71025b 100644
--- a/src/gui/widgets/whispertab.h
+++ b/src/gui/widgets/whispertab.h
@@ -36,7 +36,8 @@ class WhisperTab : public ChatTab
void showHelp();
- bool handleCommand(std::string type, std::string args);
+ bool handleCommand(const std::string &type,
+ const std::string &args);
protected:
friend class ChatWindow;
@@ -52,7 +53,7 @@ class WhisperTab : public ChatTab
void handleInput(const std::string &msg);
- void handleCommand(std::string msg);
+ void handleCommand(const std::string &msg);
private:
std::string mNick;
diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp
index e9651af9..b37105e9 100644
--- a/src/net/ea/gui/partytab.cpp
+++ b/src/net/ea/gui/partytab.cpp
@@ -55,7 +55,7 @@ void PartyTab::showHelp()
chatLog(_("/leave > Leave the party you are in"));
}
-bool PartyTab::handleCommand(std::string type, std::string args)
+bool PartyTab::handleCommand(const std::string &type, const std::string &args)
{
if (type == "help")
{
diff --git a/src/net/ea/gui/partytab.h b/src/net/ea/gui/partytab.h
index fac4061b..1e4b6e0c 100644
--- a/src/net/ea/gui/partytab.h
+++ b/src/net/ea/gui/partytab.h
@@ -35,7 +35,7 @@ class PartyTab : public ChatTab
void showHelp();
- bool handleCommand(std::string type, std::string args);
+ bool handleCommand(const std::string &type, const std::string &args);
protected:
void handleInput(const std::string &msg);