2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 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.
17 * A specialization of Grid useful for containing pointers.
18 * It is used only to contain pointers to Piece and derived classes.
21 class PointerGrid
: public Grid
<T
*> {
23 using Grid
<T
*>::board
; // why???
24 PointerGrid(int sizeX
, int sizeY
);
25 PointerGrid(const PointerGrid
<T
>& other
);
26 template <typename T1
>
27 PointerGrid(const PointerGrid
<T1
>& other
);
29 bool operator==(const PointerGrid
<T
>& other
) const;
31 Point
find(const T
& x
) const {
32 for (Point i
= this->first(); i
<= this->last(); i
= this->next(i
)) {
33 if ((*this)[i
] && *(*this)[i
] == x
)
36 return Point::invalid();
39 virtual ~PointerGrid();
43 //BEGIN Implementation
46 PointerGrid
<T
>::PointerGrid(int sizeX
, int sizeY
) : Grid
<T
*>(sizeX
, sizeY
, 0) {}
49 PointerGrid
<T
>::PointerGrid(const PointerGrid
<T
>& other
)
51 for (uint i
= 0; i
< board
.size(); ++i
) {
52 T
* p
= other
.board
[i
];
61 template <typename T1
>
62 PointerGrid
<T
>::PointerGrid(const PointerGrid
<T1
>& other
)
63 : Grid
<T
*>(other
.getSize().x
, other
.getSize().y
) {
64 for (uint i
= 0; i
< board
.size(); ++i
) {
65 T1
* p
= other
.board
[i
];
74 PointerGrid
<T
>::~PointerGrid() {
75 for (uint i
= 0; i
< board
.size(); ++i
)
80 bool PointerGrid
<T
>::operator==(const PointerGrid
<T
>& other
) const {
81 for (uint i
= 0; i
< board
.size(); ++i
) {
83 if (other
.board
[i
]) return false;
86 if (! board
[i
]->equals(other
.board
[i
])) return false;