]> jfr.im git - irc/gameservirc.git/blame - gameserv/toplist.cpp
fixed some compile bugs with newer g++ versions
[irc/gameservirc.git] / gameserv / toplist.cpp
CommitLineData
e248e6be 1#include "toplist.h"
2#include "player.h"
3#include <list>
4
5using namespace std;
6
7toplist::toplist()
8{
9 myList.clear();
10 count = 10;
11}
12
13toplist::toplist(int c)
14{
15 myList.clear();
16 count = c;
17}
18
19toplist::~toplist()
20{
21 myList.clear();
22 count = 10;
23}
24
25void toplist::insertPlayer(Player *p)
26{
27 myList.push_front(*p);
28 sort();
8cd4c581 29
30 // Reverse the list since list::sort() uses the < operator
31 myList.reverse();
e248e6be 32 prune();
33}
34
35void toplist::setCount(int c)
36{
37 count = c;
38}
39
40void toplist::sort()
41{
42 myList.sort();
43}
44
45void toplist::prune()
46{
47 list<Player>::iterator it;
48 it = myList.begin();
49
50 for (int x = 0; it != myList.end(); x++, it++)
51 {
52 if (x > count)
53 {
54 // Delete this player from the top list, because they're over the count
55 myList.erase(it);
56 }
57 }
58}
59
60list<Player>::iterator toplist::top()
61{
62 return myList.begin();
63}