Remove String->const char* conversion operator in favor of c_str method
[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"
cfa82921 24#include "ServerConnection.H"
25
cb21075d 26#ifdef USESCRIPTS
27#include "Interp.H"
28#endif
29
30ChannelList::ChannelList()
31{
32#ifdef HAVE_STL_CLEAR
33 channel_list.clear();
34#endif
35}
36
37ChannelList::~ChannelList()
38{
39 Channel *c;
40 std::map<String, Channel *, std::less<String> >::iterator it;
41
42 while (channel_list.size()!=0) {
43 it = channel_list.begin();
44 c = (*it).second;
45 channel_list.erase(it);
46 delete c;
47 }
48}
49
50void
51ChannelList::addChannel(ServerConnection *cnx, String name, String wantedModes)
52{
53 name = name.toLower();
54 channel_list[name] = new Channel(cnx, name, wantedModes);
55}
56
57void
58ChannelList::delChannel(String name)
59{
60 name = name.toLower();
61 Channel *c = channel_list[name];
62 if (c != 0) {
63 channel_list.erase(name);
64 delete c;
65 }
66}
67
68Channel *
69ChannelList::getChannel(String name)
70{
71 name = name.toLower();
72 Channel *c = channel_list[name];
73
74 if (c)
75 return c;
76
77 channel_list.erase(name);
78 return 0;
79}
80
81void
82ChannelList::clear()
83{
84 Channel *c;
85 std::map<String, Channel *, std::less<String> >::iterator it;
86
87 while (channel_list.size() != 0) {
88 it = channel_list.begin();
89 c = (*it).second;
90 channel_list.erase(it);
91 delete c;
92 }
93}