nearMask.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
nearMask.h
Go to the documentation of this file.
1 #ifndef _NEARMASKE_H
2 #define _NEARMASKE_H
3 #include "osl/state/numEffectState.h"
4 #include "osl/misc/bitOp.h"
5 #include "osl/ptypeTraits.h"
6 #include <iosfwd>
7
8 namespace osl
9 {
10 namespace container
11 {
20 class NearMask
21 {
22 unsigned int mask;
23 explicit NearMask(unsigned int value) : mask(value) {}
24 public:
25 NearMask() : mask(0) {}
26 static const NearMask makeDirect(unsigned int value)
27 {
28 return NearMask(value);
29 }
39 template<Player P,Direction Dir>
40 static const NearMask make(NumEffectState const& state,Square target) {
42 Square pos=target-DirectionPlayerTraits<Dir,P>::offset();
43 Piece p=state.pieceAt(pos);
44 if(p.canMoveOn<P>()){
45 if(p.isEmpty())
46 return NearMask(0x10001<<static_cast<int>(Dir));
47 return NearMask(1<<static_cast<int>(Dir));
48 }
49 return NearMask(0);
50 }
51 template<Player P>
52 static const NearMask make(NumEffectState const& state,Square target) {
53 NearMask nearMask;
59 nearMask=NearMask::make<P,U>(state,target);
60 nearMask|=NearMask::make<P,UL>(state,target);
61 nearMask|=NearMask::make<P,UR>(state,target);
62 nearMask|=NearMask::make<P,L>(state,target);
63 nearMask|=NearMask::make<P,R>(state,target);
64 nearMask|=NearMask::make<P,DL>(state,target);
65 nearMask|=NearMask::make<P,D>(state,target);
66 nearMask|=NearMask::make<P,DR>(state,target);
67 nearMask|=NearMask::make<P,UUL>(state,target);
68 nearMask|=NearMask::make<P,UUR>(state,target);
69 return nearMask;
70 }
71
72 NearMask& operator|=(NearMask r) { mask |= r.mask; return *this; }
73 NearMask& operator&=(NearMask r) { mask &= r.mask; return *this; }
74
75 unsigned int spaceMask() const { return mask >> 16; }
76 bool isSet(int n) const
77 {
78 return mask & (1<<n);
79 }
83 int takeOneBit()
84 {
85 return misc::BitOp::takeOneBit(mask);
86 }
87 bool any() const { return mask; }
88 unsigned int uintValue() const { return mask; }
89 };
90
91 inline const NearMask operator|(NearMask l, NearMask r) {
92 NearMask result = l;
93 return result |= r;
94 }
95 inline const NearMask operator&(NearMask l, NearMask r) {
96 NearMask result = l;
97 return result &= r;
98 }
99 inline bool operator==(NearMask l, NearMask r)
100 {
101 return l.uintValue() == r.uintValue();
102 }
103 inline bool operator!=(NearMask l, NearMask r)
104 {
105 return ! (l == r);
106 }
107 inline bool operator<(NearMask l, NearMask r)
108 {
109 return l.uintValue() < r.uintValue();
110 }
111
112 std::ostream& operator<<(std::ostream&, NearMask);
113 } // namespace container
114 using container::NearMask;
115 } // namespace osl
116 #endif /* _NEARMASK_H */
117 // ;;; Local Variables:
118 // ;;; mode:c++
119 // ;;; c-basic-offset:2
120 // ;;; End: