1 #ifndef HLVARIANT__POOLCOLLECTION_H
2 #define HLVARIANT__POOLCOLLECTION_H
6 template <typename _Pool
>
11 typedef typename
Pool::Piece Piece
;
12 typedef typename
Piece::Color Color
;
13 typedef std::map
<Color
, Pool
> Pools
;
17 virtual ~PoolCollection();
19 virtual bool operator==(const PoolCollection
<Pool
>& other
) const;
20 virtual bool operator!=(const PoolCollection
<Pool
>& other
) const;
22 virtual Pool
& pool(Color player
);
23 virtual const Pool
& pool(Color player
) const;
28 template <typename Pool
>
29 PoolCollection
<Pool
>::~PoolCollection() { }
31 template <typename Pool
>
32 bool PoolCollection
<Pool
>::operator==(const PoolCollection
<Pool
>& other
) const {
33 typename
Pools::const_iterator i
= m_pools
.begin();
34 typename
Pools::const_iterator j
= other
.m_pools
.begin();
36 while (i
!= m_pools
.end() && j
!= other
.m_pools
.end()) {
37 if (i
->first
< j
->first
) {
38 if (!i
->second
.empty())
43 else if (i
->first
> j
->first
) {
44 if (!j
->second
.empty())
50 // same key, compare values
51 if (i
->second
!= j
->second
)
61 while (i
!= m_pools
.end()) {
62 if (!i
->second
.empty())
66 while (j
!= other
.m_pools
.end()) {
67 if (!j
->second
.empty())
75 template <typename Pool
>
76 bool PoolCollection
<Pool
>::operator!=(const PoolCollection
<Pool
>& other
) const {
77 return !((*this) == other
);
80 template <typename Pool
>
81 Pool
& PoolCollection
<Pool
>::pool(Color player
) {
82 // return pool if it exists
83 typename
Pools::iterator it
= m_pools
.find(player
);
84 if (it
!= m_pools
.end()) {
89 m_pools
.insert(std::make_pair(player
, Pool(player
)));
90 return m_pools
.find(player
)->second
;
93 template <typename Pool
>
94 const Pool
& PoolCollection
<Pool
>::pool(Color player
) const {
95 // here we use const cast, because our semantics of PoolCollection
96 // considers an empty pool the same thing as no pool.
97 return const_cast<PoolCollection
*>(this)->pool(player
);
102 #endif // HLVARIANT__POOLCOLLECTION_H