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