diff options
author | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2005-05-09 12:05:04 +0000 |
---|---|---|
committer | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2005-05-09 12:05:04 +0000 |
commit | 5f8d500a0282d533ea4b7db1d982e1149d345289 (patch) | |
tree | d4042b9671fd75b3ef54ca29f941e88206dcd1c3 | |
parent | be25dfc81df7e2ac253895d4c91307407446eadd (diff) | |
download | mana-5f8d500a0282d533ea4b7db1d982e1149d345289.tar.gz mana-5f8d500a0282d533ea4b7db1d982e1149d345289.tar.bz2 mana-5f8d500a0282d533ea4b7db1d982e1149d345289.tar.xz mana-5f8d500a0282d533ea4b7db1d982e1149d345289.zip |
Added buddylist model
-rw-r--r-- | src/resources/buddylist.cpp | 35 | ||||
-rw-r--r-- | src/resources/buddylist.h | 2 |
2 files changed, 33 insertions, 4 deletions
diff --git a/src/resources/buddylist.cpp b/src/resources/buddylist.cpp index 580d7e10..0f64492b 100644 --- a/src/resources/buddylist.cpp +++ b/src/resources/buddylist.cpp @@ -21,6 +21,7 @@ */ #include "buddylist.h" +#include <iostream> BuddyList::BuddyList() { @@ -32,22 +33,50 @@ BuddyList::~BuddyList() bool BuddyList::addBuddy(const std::string buddy) { - buddylist.push_back(buddy); + for(buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++) + { + // Buddy already exist + if(*buddyit == buddy) return false; + } + + // Buddy doesnt exist + buddylist.push_back(buddy); return true; } bool BuddyList::removeBuddy(const std::string buddy) { - return true; + for(buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++) + { + // Buddy exist, remove it + if(*buddyit == buddy) { + buddylist.remove(buddy); + return true; + } + } + + // Buddy doesnt exist + return false; } int BuddyList::getBuddyNumber(void) { - return 0; + int ret = 0; + for(buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++) + ret++; + return ret; } std::string BuddyList::getBuddy(int number) { + int i = 0; + for(buddyit = buddylist.begin(); buddyit != buddylist.end(); buddyit++) + { + if(i == number) + return *buddyit; + i++; + } + return ""; } diff --git a/src/resources/buddylist.h b/src/resources/buddylist.h index 2c41271f..cb798f1e 100644 --- a/src/resources/buddylist.h +++ b/src/resources/buddylist.h @@ -60,7 +60,7 @@ class BuddyList { private: std::list<std::string> buddylist; /**< Buddy list */ - + std::list<std::string>::iterator buddyit; /**< Iterator */ }; #endif /* _TMW_BUDDYLIST_H */ |