threatmateState.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
threatmateState.h
Go to the documentation of this file.
1 /* threatmateState.h
2 */
3 #ifndef SEARCH_THREATMATESTATE_H
4 #define SEARCH_THREATMATESTATE_H
5
6 #include "osl/misc/carray.h"
7 #include "osl/move.h"
8 #ifdef OSL_SMP
9 # include "osl/misc/lightMutex.h"
10 #endif
11 #include <iosfwd>
12 namespace osl
13 {
14 namespace search
15 {
16 struct ThreatmateStateData
17 {
18 char current_status;
19 };
20 class DualThreatmateState;
29 class ThreatmateState : protected ThreatmateStateData
30 {
31 friend class DualThreatmateState;
32 public:
33 enum Status {
34 UNKNOWN = 0,
36 THREATMATE,
38 MAYBE_THREATMATE,
40 CHECK_AFTER_THREATMATE,
42 MAY_HAVE_CHECKMATE,
43 };
44 private:
45 static const CArray<Status,5*2> transition;
46 public:
47 ThreatmateState(Status s=UNKNOWN)
48 {
49 current_status = s;
50 }
51 void setThreatmate(Status s) {
52 current_status = s;
53 }
54 bool isUnknown() const {
55 return current_status == UNKNOWN;
56 }
57 bool isThreatmate() const {
58 return current_status == THREATMATE;
59 }
60 bool maybeThreatmate() const {
61 return (current_status == THREATMATE)
62 || (current_status == MAYBE_THREATMATE);
63 }
64 bool mayHaveCheckmate() const {
65 return current_status == MAY_HAVE_CHECKMATE;
66 }
67 Status status() const {
68 return static_cast<Status>(current_status);
69 }
70 const ThreatmateState newStatus(bool is_check) const
71 {
72 return transition[current_status*2+is_check];
73 }
74
75 void update(const ThreatmateState *parent, bool in_check)
76 {
77 if (maybeThreatmate() || ! parent)
78 return;
79 const ThreatmateState new_status = parent->newStatus(in_check);
80 *this = new_status;
81 }
82 };
83 std::ostream& operator<<(std::ostream&, ThreatmateState);
84 } // namespace search
85 } // osl
86
87 #endif /* SEARCH_THREATMATESTATE_H */
88 // ;;; Local Variables:
89 // ;;; mode:c++
90 // ;;; c-basic-offset:2
91 // ;;; End: