De-constify piece types.
[tagua/yd.git] / src / core / defaultpool.h
blobaf1cf1d16708cfb20bcb5c8af3f3f9e868e1e54e
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef CORE__DEFAULTPOOL_H
12 #define CORE__DEFAULTPOOL_H
14 #include <QMap>
16 #include "pool.h"
17 #include "export.h"
19 class IColor;
20 class IType;
22 /**
23 * @brief Convenience IPool implementation for shogi-like games.
25 * A DefaultPool holds pieces of the same color. It doesn't
26 * actually contains pieces, but creates them on the fly whenever it
27 * is asked one.
29 * Pieces are maintained using an association type -> number of pieces
30 * of that type. Indexes are computed as if all pieces where ordered by
31 * type.
33 class TAGUA_EXPORT DefaultPool : public IPool {
34 /**
35 * @brief Wrapper of an IType pointer, used to sort types by index.
37 struct Key {
38 public:
39 IType* type;
40 Key(IType* type);
41 bool operator<(const Key& other) const;
43 typedef QMap<Key, int> Data;
44 Data m_data;
45 const IColor* m_owner;
46 public:
47 DefaultPool(const IColor* owner);
48 virtual ~DefaultPool();
50 virtual IPool* clone() const;
51 virtual bool equals(const IPool* other) const;
52 virtual bool empty() const;
53 virtual int size() const;
54 virtual int insert(int index, Piece& piece);
55 virtual Piece get(int index);
56 virtual Piece get(int index) const;
57 virtual Piece take(int index);
58 virtual bool take(Piece& piece);
60 /**
61 * @return The common color of the pieces.
63 virtual const IColor* color() const;
65 /**
66 * @return The number of pieces of the given type.
68 virtual int count(IType* type) const;
70 /**
71 * Add a piece of the given type to the pool.
72 * @return The new number of pieces of the given type.
74 virtual int add(IType* type);
76 /**
77 * Remove a piece of the given type from the pool.
78 * @return The new number of pieces of the given type.
80 virtual int remove(IType* type);
83 #endif // CORE__DEFAULTPOOL_H