00001 /* 00002 * The Mana World 00003 * Copyright (C) 2004 The Mana World Development Team 00004 * 00005 * This file is part of The Mana World. 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #include "channelmanager.h" 00023 #include "channel.h" 00024 00025 #include "utils/dtor.h" 00026 00027 ChannelManager::ChannelManager() 00028 { 00029 } 00030 00031 ChannelManager::~ChannelManager() 00032 { 00033 delete_all(mChannels); 00034 mChannels.clear(); 00035 } 00036 00037 Channel *ChannelManager::findById(int id) const 00038 { 00039 Channel *channel = 0; 00040 for (std::list<Channel*>::const_iterator itr = mChannels.begin(), 00041 end = mChannels.end(); 00042 itr != end; 00043 itr++) 00044 { 00045 Channel *c = (*itr); 00046 if (c->getId() == id) 00047 { 00048 channel = c; 00049 break; 00050 } 00051 } 00052 return channel; 00053 } 00054 00055 Channel *ChannelManager::findByName(const std::string &name) const 00056 { 00057 Channel *channel = 0; 00058 if (!name.empty()) 00059 { 00060 for (std::list<Channel*>::const_iterator itr = mChannels.begin(), 00061 end = mChannels.end(); 00062 itr != end; 00063 itr++) 00064 { 00065 Channel *c = (*itr); 00066 if (c->getName() == name) 00067 { 00068 channel = c; 00069 break; 00070 } 00071 } 00072 } 00073 return channel; 00074 } 00075 00076 void ChannelManager::addChannel(Channel *channel) 00077 { 00078 mChannels.push_back(channel); 00079 } 00080 00081 void ChannelManager::removeChannel(Channel *channel) 00082 { 00083 mChannels.remove(channel); 00084 delete channel; 00085 }