[project @ 2005-06-28 09:54:46 by unknown_lamer]
[clinton/bobotpp.git] / source / ChannelList.C
CommitLineData
cb21075d 1// ChannelList.C -*- C++ -*-
2// Copyright (c) 1997, 1998 Etienne BERNARD
3// Copyright (C) 2002 Clinton Ebadi
4
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// any later version.
9
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
39b022cb 17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
cb21075d 18
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include "ChannelList.H"
24#ifdef USESCRIPTS
25#include "Interp.H"
26#endif
27
28ChannelList::ChannelList()
29{
30#ifdef HAVE_STL_CLEAR
31 channel_list.clear();
32#endif
33}
34
35ChannelList::~ChannelList()
36{
37 Channel *c;
38 std::map<String, Channel *, std::less<String> >::iterator it;
39
40 while (channel_list.size()!=0) {
41 it = channel_list.begin();
42 c = (*it).second;
43 channel_list.erase(it);
44 delete c;
45 }
46}
47
48void
49ChannelList::addChannel(ServerConnection *cnx, String name, String wantedModes)
50{
51 name = name.toLower();
52 channel_list[name] = new Channel(cnx, name, wantedModes);
53}
54
55void
56ChannelList::delChannel(String name)
57{
58 name = name.toLower();
59 Channel *c = channel_list[name];
60 if (c != 0) {
61 channel_list.erase(name);
62 delete c;
63 }
64}
65
66Channel *
67ChannelList::getChannel(String name)
68{
69 name = name.toLower();
70 Channel *c = channel_list[name];
71
72 if (c)
73 return c;
74
75 channel_list.erase(name);
76 return 0;
77}
78
79void
80ChannelList::clear()
81{
82 Channel *c;
83 std::map<String, Channel *, std::less<String> >::iterator it;
84
85 while (channel_list.size() != 0) {
86 it = channel_list.begin();
87 c = (*it).second;
88 channel_list.erase(it);
89 delete c;
90 }
91}