Scid  4.6.5
sqset.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////
2 //
3 // FILE: sqset.h
4 // SquareSet class
5 //
6 // Part of: Scid (Shane's Chess Information Database)
7 // Version: 3.4
8 //
9 // Notice: Copyright (c) 2002 Shane Hudson. All rights reserved.
10 //
11 // Author: Shane Hudson (sgh@users.sourceforge.net)
12 //
13 //////////////////////////////////////////////////////////////////////
14 
15 #ifndef SCID_SQSET_H
16 #define SCID_SQSET_H
17 
18 #include "common.h"
19 
20 class SquareSet {
21 private:
22 
23  uint Bits_a1h4;
24  uint Bits_a5h8;
25 
26 public:
27 #ifdef WINCE
28  void* operator new(size_t sz) {
29  void* m = my_Tcl_Alloc(sz);
30  return m;
31  }
32  void operator delete(void* m) {
33  my_Tcl_Free((char*)m);
34  }
35  void* operator new [] (size_t sz) {
36  void* m = my_Tcl_AttemptAlloc(sz);
37  return m;
38  }
39 
40  void operator delete [] (void* m) {
41  my_Tcl_Free((char*)m);
42  }
43 
44 #endif
45 
46  SquareSet() { Bits_a1h4 = Bits_a5h8 = 0; }
47  SquareSet(squareT * squares) {
48  Bits_a1h4 = Bits_a5h8 = 0;
49  AddAll (squares);
50  }
52 
53  inline void Clear (void) { Bits_a1h4 = Bits_a5h8 = 0; }
54  inline void Add (squareT sq);
55  inline void AddAll (void) { Bits_a1h4 = Bits_a5h8 = 0xFFFFFFFFu; }
56  inline void AddAll (squareT * squares);
57  inline bool Contains (squareT sq);
58  inline void Remove (squareT sq);
59 };
60 
61 inline void
63 {
64  ASSERT (sq <= H8);
65  if (sq <= H4) {
66  Bits_a1h4 |= (1 << sq);
67  } else {
68  Bits_a5h8 |= (1 << (sq & 31));
69  }
70 }
71 
72 inline void
74 {
75  while (true) {
76  squareT sq = *squares;
77  if (sq == NULL_SQUARE) { break; }
78  ASSERT (sq <= H8);
79  squares++;
80  if (sq <= H4) {
81  Bits_a1h4 |= (1 << sq);
82  } else {
83  Bits_a5h8 |= (1 << (sq & 31));
84  }
85  }
86 }
87 
88 inline bool
90 {
91  ASSERT (sq <= H8);
92  if (sq <= H4) {
93  return (Bits_a1h4 & (1 << sq)) != 0;
94  } else {
95  return (Bits_a5h8 & (1 << (sq & 31))) != 0;
96  }
97 }
98 
99 inline void
101 {
102  ASSERT (sq <= H8);
103  if (sq <= H4) {
104  Bits_a1h4 &= ~(1 << sq);
105  } else {
106  Bits_a5h8 &= ~(1 << (sq & 31));
107  }
108 }
109 
110 #endif // SCID_SQSET_H
111 
112 //////////////////////////////////////////////////////////////////////
113 // EOF: sqset.h
114 //////////////////////////////////////////////////////////////////////
sqsqname
Definition: board.tcl:292
const squareT NULL_SQUARE
Definition: common.h:352
void Clear(void)
Definition: sqset.h:53
#define ASSERT(f)
Definition: common.h:67
const squareT H4
Definition: common.h:346
SquareSet()
Definition: sqset.h:46
void AddAll(void)
Definition: sqset.h:55
bool Contains(squareT sq)
Definition: sqset.h:89
uint32_t uint
Definition: common.h:99
SquareSet(squareT *squares)
Definition: sqset.h:47
void Remove(squareT sq)
Definition: sqset.h:100
const squareT H8
Definition: common.h:350
void Add(squareT sq)
Definition: sqset.h:62
~SquareSet()
Definition: sqset.h:51
byte squareT
Definition: common.h:113