| 1 |
/* |
| 2 |
* The Mana World |
| 3 |
* Copyright (C) 2004 The Mana World Development Team |
| 4 |
* |
| 5 |
* This file is part of The Mana World. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "channelmanager.h" |
| 23 |
#include "channel.h" |
| 24 |
|
| 25 |
#include "utils/dtor.h" |
| 26 |
|
| 27 |
ChannelManager::ChannelManager() |
| 28 |
{ |
| 29 |
} |
| 30 |
|
| 31 |
ChannelManager::~ChannelManager() |
| 32 |
{ |
| 33 |
delete_all(mChannels); |
| 34 |
mChannels.clear(); |
| 35 |
} |
| 36 |
|
| 37 |
Channel *ChannelManager::findById(int id) const |
| 38 |
{ |
| 39 |
Channel *channel = 0; |
| 40 |
for (std::list<Channel*>::const_iterator itr = mChannels.begin(), |
| 41 |
end = mChannels.end(); |
| 42 |
itr != end; |
| 43 |
itr++) |
| 44 |
{ |
| 45 |
Channel *c = (*itr); |
| 46 |
if (c->getId() == id) |
| 47 |
{ |
| 48 |
channel = c; |
| 49 |
break; |
| 50 |
} |
| 51 |
} |
| 52 |
return channel; |
| 53 |
} |
| 54 |
|
| 55 |
Channel *ChannelManager::findByName(const std::string &name) const |
| 56 |
{ |
| 57 |
Channel *channel = 0; |
| 58 |
if (!name.empty()) |
| 59 |
{ |
| 60 |
for (std::list<Channel*>::const_iterator itr = mChannels.begin(), |
| 61 |
end = mChannels.end(); |
| 62 |
itr != end; |
| 63 |
itr++) |
| 64 |
{ |
| 65 |
Channel *c = (*itr); |
| 66 |
if (c->getName() == name) |
| 67 |
{ |
| 68 |
channel = c; |
| 69 |
break; |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
return channel; |
| 74 |
} |
| 75 |
|
| 76 |
void ChannelManager::addChannel(Channel *channel) |
| 77 |
{ |
| 78 |
mChannels.push_back(channel); |
| 79 |
} |
| 80 |
|
| 81 |
void ChannelManager::removeChannel(Channel *channel) |
| 82 |
{ |
| 83 |
mChannels.remove(channel); |
| 84 |
delete channel; |
| 85 |
} |