1
// Copyright (C) 2009, 2010 Ben Asselstine
3
// This program is free software; you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation; either version 3 of the License, or
6
// (at your option) any later version.
8
// This program is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
// GNU Library General Public License for more details.
13
// You should have received a copy of the GNU General Public License
14
// along with this program; if not, write to the Free Software
15
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
#include "stackreflist.h"
20
#include "stacklist.h"
23
StackReflist::StackReflist()
27
StackReflist::StackReflist(Stacklist *sl, bool skip_parked_stacks)
29
for (Stacklist::iterator it = sl->begin(); it != sl->end(); it++)
31
if (skip_parked_stacks == true && (*it)->getParked() == true)
37
StackReflist::StackReflist(std::list<Stack*> s, bool skip_parked_stacks)
39
for (std::list<Stack*>::iterator it = s.begin(); it != s.end(); it++)
41
if (skip_parked_stacks == true && (*it)->getParked() == true)
47
StackReflist::~StackReflist()
51
Stack *StackReflist::getStackById(guint32 id) const
53
IdMap::const_iterator it = d_id.find(id);
60
void StackReflist::addStack(Stack *stack)
63
d_id[stack->getId()] = stack;
66
bool StackReflist::contains(guint32 id) const
68
if (getStackById(id) != NULL)
73
bool StackReflist::removeStack(guint32 id)
75
Stack *s = getStackById(id);
78
d_id.erase(d_id.find(s->getId()));
85
StackReflist::iterator StackReflist::eraseStack(StackReflist::iterator it)
92
typedef std::map<guint32, Stack*> IdMap;
93
IdMap::iterator i = d_id.find(s->getId());
101
StackReflist::iterator StackReflist::eraseStack(StackReflist::iterator it, guint32 id)
105
IdMap::iterator i = d_id.find(id);
112
guint32 StackReflist::countArmies() const
115
for (const_iterator it = begin(); it != end(); it++)
116
count += (*it)->size();
120
void StackReflist::changeOwnership(Player *old_player, Player *new_player)
122
for (IdMap::iterator it = d_id.begin(); it != d_id.end(); it++)
124
guint32 id = (*it).first;
125
Stack *new_stack = new_player->getStacklist()->getStackById(id);
127
(*it).second = new_stack;
131
bool StackReflist::getIdOfStack(Stack *stack, guint32 &id)
133
for (IdMap::iterator it = d_id.begin(); it != d_id.end(); it++)
135
if ((*it).second == stack)