summaryrefslogtreecommitdiff
path: root/src/resources/buddylist.cpp
diff options
context:
space:
mode:
authorMateusz Kaduk <mateusz.kaduk@gmail.com>2005-05-15 09:17:40 +0000
committerMateusz Kaduk <mateusz.kaduk@gmail.com>2005-05-15 09:17:40 +0000
commit13deabf8b93a2a6307978d9f49ad8fde5dbefdfd (patch)
treee21a23d1e6606ca86fb5629cd4048d62e560191c /src/resources/buddylist.cpp
parent0632377e8b2e63f965b30ac89a9e2dca819735ef (diff)
downloadmana-13deabf8b93a2a6307978d9f49ad8fde5dbefdfd.tar.gz
mana-13deabf8b93a2a6307978d9f49ad8fde5dbefdfd.tar.bz2
mana-13deabf8b93a2a6307978d9f49ad8fde5dbefdfd.tar.xz
mana-13deabf8b93a2a6307978d9f49ad8fde5dbefdfd.zip
Using guichan ListModel
Diffstat (limited to 'src/resources/buddylist.cpp')
-rw-r--r--src/resources/buddylist.cpp39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/resources/buddylist.cpp b/src/resources/buddylist.cpp
index 0f64492b..87e6438f 100644
--- a/src/resources/buddylist.cpp
+++ b/src/resources/buddylist.cpp
@@ -24,7 +24,7 @@
#include <iostream>
BuddyList::BuddyList()
-{
+{
}
BuddyList::~BuddyList()
@@ -39,19 +39,22 @@ bool BuddyList::addBuddy(const std::string buddy)
if(*buddyit == buddy) return false;
}
- // Buddy doesnt exist
+ // Buddy doesnt exist, add it
buddylist.push_back(buddy);
+
return true;
}
bool BuddyList::removeBuddy(const std::string buddy)
{
- for(buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++)
- {
- // Buddy exist, remove it
- if(*buddyit == buddy) {
- buddylist.remove(buddy);
- return true;
+ if(buddylist.size() > 0) {
+ for(buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++)
+ {
+ // Buddy exist, remove it
+ if(*buddyit == buddy) {
+ buddylist.remove(buddy);
+ return true;
+ }
}
}
@@ -59,24 +62,20 @@ bool BuddyList::removeBuddy(const std::string buddy)
return false;
}
-int BuddyList::getBuddyNumber(void)
+int BuddyList::getNumberOfElements(void)
{
- int ret = 0;
- for(buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++)
- ret++;
- return ret;
+ return buddylist.size();
}
-std::string BuddyList::getBuddy(int number)
+std::string BuddyList::getElementAt(int number)
{
- int i = 0;
- for(buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++)
+ if(number <= buddylist.size())
{
- if(i == number)
- return *buddyit;
- i++;
+ buddyit = buddylist.begin();
+ std::advance(buddyit, number);
+ return *buddyit;
}
-
+
return "";
}