]> jfr.im git - irc/gameservirc.git/blame - gameserv/toplist.cpp
Added code for the start of the DataLayer format as well as a basic FilePlayerDAO...
[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)
71a1182a 26{\r
27 PlayerWrapper *pw;\r
28 pw = new PlayerWrapper(p);
29 myList.push_front(*pw);
30 sort();
8cd4c581 31
71a1182a 32 // Reverse the list since list::sort() uses the < operator
33 reverse();
34 prune();
e248e6be 35}
36
37void toplist::setCount(int c)
38{
39 count = c;
40}
41
42void toplist::sort()
43{
44 myList.sort();
45}
71a1182a 46\r
47void toplist::reverse()\r
48{\r
49 myList.reverse();\r
50}
e248e6be 51void toplist::prune()
52{
71a1182a 53 list<PlayerWrapper>::iterator it;
e248e6be 54 it = myList.begin();
55
56 for (int x = 0; it != myList.end(); x++, it++)
57 {
58 if (x > count)
59 {
60 // Delete this player from the top list, because they're over the count
61 myList.erase(it);
62 }
63 }
64}
65
71a1182a 66list<PlayerWrapper>::iterator toplist::begin()
e248e6be 67{
68 return myList.begin();
69}
abb0a0b9 70\r
71\r
71a1182a 72list<PlayerWrapper>::iterator toplist::end()\r
abb0a0b9 73{\r
74 return myList.end();\r
75}\r
71a1182a 76\r
77bool toplist::empty()\r
78{\r
79 return myList.empty();\r
80}\r
81\r
82bool PlayerWrapper::operator < (PlayerWrapper &right)\r
83{\r
84 return (*p < *right.p);\r
85}\r
86\r
87PlayerWrapper::PlayerWrapper()\r
88{\r
89 p = NULL;\r
90}\r
91\r
92PlayerWrapper::PlayerWrapper(Player *pl)\r
93{\r
94 p = pl;\r
95}\r
96\r
97PlayerWrapper::~PlayerWrapper()\r
98{\r
99 p = NULL;\r
100}\r
101\r
102void PlayerWrapper::setPlayer(Player *pl)\r
103{\r
104 p = pl;\r
105}\r
106\r