numBitmapEffect.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
numBitmapEffect.h
Go to the documentation of this file.
1 #ifndef _NUM_BITMAP_EFFECT_H
2 #define _NUM_BITMAP_EFFECT_H
3
4 #include "osl/player.h"
5 #include "osl/ptypeTraits.h"
6 #include "osl/container/pieceMask.h"
7 #include "osl/misc/loki.h"
8
9 namespace osl
10 {
11 namespace effect
12 {
29 class NumBitmapEffect : public PieceMask
30 {
31 private:
32 static NumBitmapEffect playerEffect(misc::Int2Type<BLACK>){
33 NumBitmapEffect ret;
34 ret.flip(48);
35 return ret;
36 }
37 static NumBitmapEffect playerEffect(misc::Int2Type<WHITE>){
38 NumBitmapEffect ret;
39 ret.flip(54);
40 return ret;
41 }
42 static mask_t playerEffectMask(misc::Int2Type<BLACK>){
43 mask_t mask1=numToMask(54);
44 mask1-=numToMask(48);
45 return mask1;
46 }
47 static mask_t playerEffectMask(misc::Int2Type<WHITE>){
48 mask_t mask1=numToMask(60);
49 mask1-=numToMask(54);
50 return mask1;
51 }
52
53 public:
54 NumBitmapEffect(){
55 resetAll();
56 }
57 template<Player P>
58 static NumBitmapEffect playerEffect(){
59 return playerEffect(misc::Int2Type<P>());
60 }
61 static NumBitmapEffect playerEffect(Player pl){
62 mask_t mask1=numToMask(54);
63 mask1-=numToMask(48);
64 mask1&=mask_t::makeDirect(pl);
65 mask1+=numToMask(48);
66 NumBitmapEffect ret;
67 ret.setMask(1,mask1);
68 assert((pl==BLACK && ret==playerEffect<BLACK>()) ||
69 (pl==WHITE && ret==playerEffect<WHITE>()));
70 return ret;
71 }
72 template<Player P>
73 static mask_t playerEffectMask(){
74 return playerEffectMask(misc::Int2Type<P>());
75 }
76 static mask_t playerEffectMask(Player pl){
77 mask_t mask1=numToMask(60);
78 mask1-=numToMask(48);
79 mask1&=mask_t::makeDirect(pl);
80 // pl==BLACK -> mask1 = 0
81 // pl==WHITE -> mask1 = 0x0fff0000(32bit), 0x0fff000000000000(64bit)
82 mask_t mask2=numToMask(54);
83 mask2-=numToMask(48);
84 // mask2 = 0x3f0000(32bit), 0x3f000000000000(64bit)
85 mask1^=mask2;
86 // pl==BLACK -> mask1 = 0x3f0000(32bit), 0x3f000000000000(64bit)
87 // pl==WHITE -> mask2 = 0x0fc00000(32bit), 0x0fc0000000000000(64bit)
88 assert((pl==BLACK && mask1==playerEffectMask<BLACK>()) ||
89 (pl==WHITE && mask1==playerEffectMask<WHITE>()));
90 return mask1;
91 }
92 int countEffect(Player pl) const {
93 int shift=48+(6&pl);
94 mask_t mask=getMask(1);
95 mask>>=numToOffset(shift);
96 mask&=mask_t::makeDirect(0x3f);
97 return static_cast<int>(mask.value());
98 }
99
100 template<Player P>
101 static NumBitmapEffect makeEffect(int num){
102 NumBitmapEffect effect=playerEffect<P>();
103 effect.flip(num);
104 return effect;
105 }
106 enum Op{
107 Add,Sub,
108 };
109 NumBitmapEffect& opEqual(NumBitmapEffect const& rhs,
110 misc::Int2Type<Add>){
111 *this+=rhs;
112 return *this;
113 }
114 NumBitmapEffect& opEqual(NumBitmapEffect const& rhs,
115 misc::Int2Type<Sub>){
116 *this-=rhs;
117 return *this;
118 }
119 template<Op OP>
120 NumBitmapEffect& opEqual(NumBitmapEffect const& rhs){
121 return opEqual(rhs,misc::Int2Type<OP>());
122 }
123
124 static const mask_t longEffectMask() {
125 #if OSL_WORDSIZE == 64
126 return mask_t::makeDirect(0xff0000000000uLL);
127 #elif OSL_WORDSIZE == 32
128 return mask_t::makeDirect(0xff00u);
129 #endif
130 }
131 #if OSL_WORDSIZE == 64
132 static const int longToNumOffset=-8;
133 #elif OSL_WORDSIZE == 32
134 static const int longToNumOffset=32-8;
135 #endif
136 static const mask_t makeLongMask(int num)
137 {
138 return mask_t::makeDirect(0x101) << PieceMask::numToOffset(num);
139 }
140 template<Player P>
141 static NumBitmapEffect makeLongEffect(int num){
142 assert(32<=num && num<=39);
143 NumBitmapEffect effect=NumBitmapEffect::playerEffect<P>();
144 effect.orMask(1,makeLongMask(num));
145 return effect;
146 }
147 static NumBitmapEffect makeLongEffect(Player pl,int num){
148 assert(32<=num && num<=39);
149 NumBitmapEffect effect=NumBitmapEffect::playerEffect(pl);
150 effect.orMask(1,makeLongMask(num));
151 return effect;
152 }
153
154 // utility methods
155 const mask_t selectLong() const
156 {
157 return (getMask(1) & longEffectMask());
158 }
159 bool hasLong() const
160 {
161 return selectLong().any();
162 }
163 template <Ptype PTYPE> const mask_t selectLong() const
164 {
165 return selectLong()
166 & mask_t::makeDirect(PtypeFuns<PTYPE>::indexMask << 8);
167 }
168 template <Ptype PTYPE> bool hasLong() const
169 {
170 return selectLong<PTYPE>().any();
171 }
172 template <Ptype PTYPE> bool hasAny() const
173 {
174 return (getMask(PtypeFuns<PTYPE>::indexNum)
175 & mask_t::makeDirect(PtypeFuns<PTYPE>::indexMask)).any();
176 }
177 };
178 } // namespace effect
179 } // namespace osl
180 #endif // _NUM_BITMAP_EFFECT_H
181 // ;;; Local Variables:
182 // ;;; mode:c++
183 // ;;; c-basic-offset:2
184 // ;;; End: