FriendList.cpp
上传用户:hysujiao87
上传日期:2007-12-02
资源大小:156k
文件大小:1k
- #include "stdafx.h"
- #include "friendlist.h"
- CFriendList::CFriendList(void)
- {
- }
- CFriendList::~CFriendList(void)
- {
- clear();
- }
- void CFriendList::clear(void)
- {
- FriendIterator it = _vector.begin();
- for(; it != _vector.end(); it++)
- {
- delete *it;
- }
- _vector.clear();
- }
- HRESULT CFriendList::addFriend(const CFriendData &friendData)
- {
- CFriendData *oldData = getFriend(friendData.userID);
- if (oldData == NULL)
- {
- CFriendData *data = new CFriendData(friendData);
- _vector.push_back(data);
- return S_OK;
- }
- *oldData = friendData;
- return S_OK;
- }
- CFriendData* CFriendList::getFriend(LPCTSTR friendID)
- {
- _ASSERTE(friendID != NULL);
- if (friendID == NULL)
- return NULL;
- FriendIterator it = _vector.begin();
- for(; it != _vector.end(); it++)
- {
- if ((*it)->userID == friendID)
- return (*it);
- }
- return NULL;
- }
- CFriendData* CFriendList::getFriend(int index)
- {
- if (index >= (int)_vector.size())
- return NULL;
- return _vector[index];
- }
- HRESULT CFriendList::deleteFriend(LPCTSTR friendID)
- {
- _ASSERTE(friendID != NULL);
- if (friendID == NULL)
- return E_INVALIDARG;
-
- CFriendData *oldData = getFriend(friendID);
- FriendIterator it = _vector.begin();
- for(; it != _vector.end(); it++)
- {
- if ((*it)->userID == friendID)
- {
- delete (*it);
- _vector.erase(it);
- return S_OK;
- }
- }
- return S_OK;
- }