[project @ 2005-07-04 01:48:38 by unknown_lamer]
[clinton/bobotpp.git] / source / ServerList.C
CommitLineData
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
39b022cb 17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
cb21075d 18
19#include "ServerList.H"
20
21ServerList::ServerList()
22 : it(v.end()), current(0), currentNumber(0)
23{ }
24
25ServerList::~ServerList()
26{
27 Server *s;
28 for (it = v.begin(); it != v.end(); ++it) {
29 s = *it;
30 delete s;
31 }
32}
33
34void
35ServerList::addServer(Server *s)
36{
37 v.push_back(s);
38 it = v.end(); // move to end because iterators are invalidated
39}
40
41void
42ServerList::delServer(int n)
43{
44 v.erase(v.begin () + n);
45}
46
47Server *
48ServerList::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
62Server *
63ServerList::currentServer()
64{
65 return current;
66}