]> jfr.im git - irc/gameservirc.git/blame - gameserv/pouch.cpp
Added to the changelog
[irc/gameservirc.git] / gameserv / pouch.cpp
CommitLineData
09e1f7a2 1#include "pouch.h"
2#include "item.h"
23f22a79 3#include <list>
4#include <algorithm>
09e1f7a2 5
6pouch::pouch()
7{
8}
9
10pouch::~pouch()
11{
12 clear();
13}
14
15void pouch::sort()
16{
17 items.sort();
18}
19
20void pouch::clear()
21{
22 items.clear();
23}
24
25bool pouch::isEmpty()
26{
27 return items.empty();
28}
29
e696687e 30itemContainer *pouch::Find(char *n)
09e1f7a2 31{
e696687e 32 list<itemContainer>::iterator item_iter;
09e1f7a2 33 item_iter = items.begin();
34
35 while (item_iter != items.end())
36 {
e696687e 37 if ((*item_iter).getItem()->getName() == n)
09e1f7a2 38 {
e696687e 39 return &(*item_iter);
09e1f7a2 40 }
41 item_iter++;
42 }
43 return NULL;
44}
45
e696687e 46itemContainer *pouch::Find(string &n)
09e1f7a2 47{
e696687e 48 list<itemContainer>::iterator item_iter;
09e1f7a2 49 item_iter = items.begin();
50
51 while (item_iter != items.end())
52 {
e696687e 53 if ((*item_iter).getItem()->getName() == n)
09e1f7a2 54 {
e696687e 55 return &(*item_iter);
09e1f7a2 56 }
57 item_iter++;
58 }
59
60 return NULL;
61}
62
63void pouch::addItem(item *i)
64{
e696687e 65 itemContainer it(i);
66 items.push_front(it);
09e1f7a2 67}
68
69void pouch::deleteItem(item *i)
70{
e696687e 71 list<itemContainer>::iterator item_iter;
09e1f7a2 72
73 item_iter = find(items.begin(), items.end(), i);
74
75 if (item_iter != items.end())
76 items.erase(item_iter);
77}
78
79const pouch &pouch::operator=(const pouch &right)
80{
81 if (&right != this)
82 {
83 items.clear();
84 items = right.items;
85 }
86 return *this;
87}