cb21075d |
1 | // ServerList.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 |
17 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
18 | |
19 | #include "ServerList.H" |
20 | |
21 | ServerList::ServerList() |
22 | : it(v.end()), current(0), currentNumber(0) |
23 | { } |
24 | |
25 | ServerList::~ServerList() |
26 | { |
27 | Server *s; |
28 | for (it = v.begin(); it != v.end(); ++it) { |
29 | s = *it; |
30 | delete s; |
31 | } |
32 | } |
33 | |
34 | void |
35 | ServerList::addServer(Server *s) |
36 | { |
37 | v.push_back(s); |
38 | it = v.end(); // move to end because iterators are invalidated |
39 | } |
40 | |
41 | void |
42 | ServerList::delServer(int n) |
43 | { |
44 | v.erase(v.begin () + n); |
45 | } |
46 | |
47 | Server * |
48 | ServerList::nextServer() |
49 | { |
50 | if (v.empty()) |
51 | return 0; |
52 | |
53 | if (it == v.end()) { |
54 | it = v.begin(); |
55 | currentNumber = 0; |
56 | } else |
57 | currentNumber++; |
58 | |
59 | return current = *(it++); |
60 | } |
61 | |
62 | Server * |
63 | ServerList::currentServer() |
64 | { |
65 | return current; |
66 | } |