Scid  4.6.5
sqlist.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////
2 //
3 // FILE: sqlist.h
4 // SquareList 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_SQLIST_H
16 #define SCID_SQLIST_H
17 
18 #include "common.h"
19 
20 const uint MAX_SQUARELIST = 65; // 64 squares plus null square
21 
22 class SquareList {
23 private:
24 
25  uint ListSize;
26  squareT Squares [MAX_SQUARELIST];
27 
28 public:
29 #ifdef WINCE
30  void* operator new(size_t sz) {
31  void* m = my_Tcl_Alloc(sz);
32  return m;
33  }
34  void operator delete(void* m) {
35  my_Tcl_Free((char*)m);
36  }
37  void* operator new [] (size_t sz) {
38  void* m = my_Tcl_AttemptAlloc(sz);
39  return m;
40  }
41 
42  void operator delete [] (void* m) {
43  my_Tcl_Free((char*)m);
44  }
45 
46 #endif
47 
48  SquareList() { ListSize = 0; }
50 
51  inline void Init() { ListSize = 0; }
52  inline void Clear() { ListSize = 0; }
53  inline void Add(squareT sq) { Squares[ListSize] = sq; ListSize++; }
54  inline uint Size() { return ListSize; }
55  inline squareT Get (uint index);
56  inline bool Contains (squareT sq);
57  inline void Remove (uint index);
58 };
59 
60 inline squareT
62 {
63  ASSERT (index < ListSize);
64  return Squares[index];
65 }
66 
67 inline bool
69 {
70  for (uint i=0; i < ListSize; i++) {
71  if (Squares[i] == sq) { return true; }
72  }
73  return false;
74 }
75 
76 inline void
78 {
79  ASSERT (index < ListSize);
80  ListSize--;
81  if (index != ListSize) {
82  Squares[index] = Squares[ListSize];
83  }
84 }
85 
86 #endif // SCID_SQLIST_H
87 
88 //////////////////////////////////////////////////////////////////////
89 // EOF: sqlist.h
90 //////////////////////////////////////////////////////////////////////
sqsqname
Definition: board.tcl:292
#define ASSERT(f)
Definition: common.h:67
void Add(squareT sq)
Definition: sqlist.h:53
SquareList()
Definition: sqlist.h:48
uint Size()
Definition: sqlist.h:54
uint32_t uint
Definition: common.h:99
~SquareList()
Definition: sqlist.h:49
bool Contains(squareT sq)
Definition: sqlist.h:68
const uint MAX_SQUARELIST
Definition: sqlist.h:20
void Remove(uint index)
Definition: sqlist.h:77
void Clear()
Definition: sqlist.h:52
void Init()
Definition: sqlist.h:51
byte squareT
Definition: common.h:113
squareT Get(uint index)
Definition: sqlist.h:61