XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
Bmp.hxx
浏览该文件的文档.
1
13#ifndef __xwos_cxx_Bmp_hxx__
14#define __xwos_cxx_Bmp_hxx__
15
16extern "C" {
17#include <xwos/lib/xwbop.h>
18#include <string.h>
19}
20
21namespace xwos {
22
36template<xwsz_t TNum>
37class Bmp
38{
39 public:
40 class Bit
41 {
42 private:
45
46 public:
47 explicit Bit(Bmp & bmp, xwsq_t index)
48 : mBmp(&bmp)
49 , mBit(index)
50 {
51 }
52 explicit Bit(Bmp * bmp, xwsq_t index)
53 : mBmp(bmp)
54 , mBit(index)
55 {
56 }
57 explicit Bit(const Bit & other)
58 : mBit(other.mBmp, other.mBit)
59 {
60 }
61 explicit Bit(const Bit && other)
62 : mBit(other.mBmp, other.mBit)
63 {
64 }
66 {
67 }
68 Bit & operator=(bool x)
69 {
70 if (x) {
71 mBmp->set(mBit);
72 } else {
73 mBmp->clear(mBit);
74 }
75 return *this;
76 }
77 Bit & operator=(const Bit & other)
78 {
79 if (this != &other) {
80 mBmp = other.mBmp;
81 mBit = other.mBit;
82 }
83 return *this;
84 }
85 Bit & operator=(const Bit && other)
86 {
87 if (this != &other) {
88 mBmp = other.mBmp;
89 mBit = other.mBit;
90 }
91 return *this;
92 }
94 {
95 mBmp->flip(mBit);
96 return *this;
97 }
98 explicit operator bool()
99 {
100 bool ret;
101 if ((xwsq_t)mBit < TNum) {
102 ret = xwbmpop_t1i(mBmp->mData, mBit);
103 } else {
104 ret = false;
105 }
106 return ret;
107 }
108 void flip() { mBmp->flip(mBit); }
109 };
110
111 public:
113
114 public:
115 Bmp(const Bmp & other)
116 {
117 xwbmpop_assign(mData, other.mData, TNum);
118 }
119 Bmp(const Bmp && other)
120 {
121 xwbmpop_assign(mData, other.mData, TNum);
122 }
124 {
125 xwbmpop_c0all(mData, TNum);
126 }
128 {
129 xwbmpop_c0all(mData, TNum);
130 if (sz < sizeof(mData)) {
131 memcpy(mData, x, sz);
132 } else {
133 memcpy(mData, x, sizeof(mData));
134 }
135 }
136 Bmp(unsigned long long x)
137 {
138 xwbmpop_c0all(mData, TNum);
139 if (sizeof(x) < sizeof(mData)) {
140 memcpy(mData, &x, sizeof(x));
141 } else {
142 memcpy(mData, &x, sizeof(mData));
143 }
144 }
145 Bmp(unsigned long x)
146 {
147 xwbmpop_c0all(mData, TNum);
148 if (sizeof(x) < sizeof(mData)) {
149 memcpy(mData, &x, sizeof(x));
150 } else {
151 memcpy(mData, &x, sizeof(mData));
152 }
153 }
154 Bmp(unsigned int x)
155 {
156 xwbmpop_c0all(mData, TNum);
157 if (sizeof(x) < sizeof(mData)) {
158 memcpy(mData, &x, sizeof(x));
159 } else {
160 memcpy(mData, &x, sizeof(mData));
161 }
162 }
163 Bmp(long long x)
164 {
165 xwbmpop_c0all(mData, TNum);
166 if (sizeof(x) < sizeof(mData)) {
167 memcpy(mData, &x, sizeof(x));
168 } else {
169 memcpy(mData, &x, sizeof(mData));
170 }
171 }
172 Bmp(long x)
173 {
174 xwbmpop_c0all(mData, TNum);
175 if (sizeof(x) < sizeof(mData)) {
176 memcpy(mData, &x, sizeof(x));
177 } else {
178 memcpy(mData, &x, sizeof(mData));
179 }
180 }
181 Bmp(int x)
182 {
183 xwbmpop_c0all(mData, TNum);
184 if (sizeof(x) < sizeof(mData)) {
185 memcpy(mData, &x, sizeof(x));
186 } else {
187 memcpy(mData, &x, sizeof(mData));
188 }
189 }
191 {
192 }
193 void set()
194 {
195 xwbmpop_s1all(mData, TNum);
196 }
197 void set(xwsq_t pos)
198 {
199 if ((xwsq_t)pos < TNum) {
200 xwbmpop_s1i(mData, pos);
201 }
202 }
203 void set(Bmp<TNum> * msk)
204 {
205 xwbmpop_s1m(mData, msk->mData, TNum);
206 }
207 void set(Bmp<TNum> & msk)
208 {
209 xwbmpop_s1m(mData, msk.mData, TNum);
210 }
211 void clear()
212 {
213 xwbmpop_c0all(mData, TNum);
214 }
215 void clear(xwsq_t pos)
216 {
217 if ((xwsq_t)pos < TNum) {
218 xwbmpop_c0i(mData, pos);
219 }
220 }
221 void clear(Bmp<TNum> * msk)
222 {
223 xwbmpop_c0m(mData, msk->mData, TNum);
224 }
225 void clear(Bmp<TNum> & msk)
226 {
227 xwbmpop_c0m(mData, msk.mData, TNum);
228 }
229 void flip()
230 {
231 xwbmpop_not(mData, TNum);
232 }
233 void flip(xwsq_t pos)
234 {
235 if ((xwsq_t)pos < TNum) {
236 xwbmpop_x1i(mData, pos);
237 }
238 }
239 void flip(Bmp<TNum> * msk)
240 {
241 xwbmpop_x1m(mData, msk->mData, TNum);
242 }
243 void flip(Bmp<TNum> & msk)
244 {
245 xwbmpop_x1m(mData, msk.mData, TNum);
246 }
248 {
249 return xwbmpop_ffs(mData, TNum);
250 }
252 {
253 return xwbmpop_fls(mData, TNum);
254 }
256 {
257 return xwbmpop_ffz(mData, TNum);
258 }
260 {
261 return xwbmpop_flz(mData, TNum);
262 }
264 {
265 return xwbmpop_weight(mData, TNum);
266 }
267
268 bool all()
269 {
270 return xwbmpop_t1ma(mData);
271 }
272 bool any()
273 {
274 return xwbmpop_t1mo(mData);
275 }
276 bool none()
277 {
278 return xwbmpop_t0ma(mData);
279 }
280
282 {
283 if (this != &other) {
284 xwbmpop_assign(mData, other.mData, TNum);
285 }
286 return *this;
287 }
288 Bmp<TNum> & operator=(const Bmp<TNum> && other)
289 {
290 if (this != &other) {
291 xwbmpop_assign(mData, other.mData, TNum);
292 }
293 return *this;
294 }
296 {
297 Bmp tmp(*this);
298 xwbmpop_and(tmp.mData, other.mData, TNum);
299 return tmp;
300 }
302 {
303 Bmp tmp(*this);
304 xwbmpop_and(tmp.mData, other.mData, TNum);
305 return tmp;
306 }
308 {
309 Bmp tmp(*this);
310 xwbmpop_or(tmp.mData, other.mData, TNum);
311 return tmp;
312 }
314 {
315 Bmp tmp(*this);
316 xwbmpop_or(tmp.mData, other.mData, TNum);
317 return tmp;
318 }
320 {
321 Bmp tmp(*this);
322 xwbmpop_xor(tmp.mData, other.mData, TNum);
323 return tmp;
324 }
326 {
327 Bmp tmp(*this);
328 xwbmpop_xor(tmp.mData, other.mData, TNum);
329 return tmp;
330 }
332 {
333 xwbmpop_and(mData, other.mData, TNum);
334 return *this;
335 }
337 {
338 xwbmpop_and(mData, other.mData, TNum);
339 return *this;
340 }
342 {
343 xwbmpop_or(mData, other.mData, TNum);
344 return *this;
345 }
347 {
348 xwbmpop_or(mData, other.mData, TNum);
349 return *this;
350 }
352 {
353 xwbmpop_xor(mData, other.mData, TNum);
354 return *this;
355 }
357 {
358 xwbmpop_xor(mData, other.mData, TNum);
359 return *this;
360 }
362 {
363 xwbmpop_not(mData, TNum);
364 return *this;
365 }
366 bool operator==(const Bmp<TNum> & other)
367 {
368 return (0 == xwbmpop_cmp(mData, other.mData, TNum));
369 }
370 bool operator==(const Bmp<TNum> && other)
371 {
372 return (0 == xwbmpop_cmp(mData, other.mData, TNum));
373 }
374 bool operator!=(const Bmp<TNum> & other)
375 {
376 return (0 != xwbmpop_cmp(mData, other.mData, TNum));
377 }
378 bool operator!=(const Bmp<TNum> && other)
379 {
380 return (0 != xwbmpop_cmp(mData, other.mData, TNum));
381 }
382 bool operator>(const Bmp<TNum> & other)
383 {
384 return (xwbmpop_cmp(mData, other.mData, TNum) > 0);
385 }
386 bool operator>(const Bmp<TNum> && other)
387 {
388 return (xwbmpop_cmp(mData, other.mData, TNum) > 0);
389 }
390 bool operator<(const Bmp<TNum> & other)
391 {
392 return (xwbmpop_cmp(mData, other.mData, TNum) < 0);
393 }
394 bool operator<(const Bmp<TNum> && other)
395 {
396 return (xwbmpop_cmp(mData, other.mData, TNum) < 0);
397 }
398 bool operator>=(const Bmp<TNum> & other)
399 {
400 return (xwbmpop_cmp(mData, other.mData, TNum) >= 0);
401 }
402 bool operator>=(const Bmp<TNum> && other)
403 {
404 return (xwbmpop_cmp(mData, other.mData, TNum) >= 0);
405 }
406 bool operator<=(const Bmp<TNum> & other)
407 {
408 return (xwbmpop_cmp(mData, other.mData, TNum) <= 0);
409 }
410 bool operator<=(const Bmp<TNum> && other)
411 {
412 return (xwbmpop_cmp(mData, other.mData, TNum) <= 0);
413 }
414 explicit operator bool()
415 {
416 return any();
417 }
419 {
420 return Bit(this, pos);
421 }
422};
423
428} // namespace xwos
429
430#endif /* xwos/cxx/Bmp.hxx */
Bit(Bmp *bmp, xwsq_t index)
Definition Bmp.hxx:52
Bit & operator~()
Definition Bmp.hxx:93
Bit(const Bit &&other)
Definition Bmp.hxx:61
Bmp * mBmp
Definition Bmp.hxx:43
void flip()
Definition Bmp.hxx:108
Bit & operator=(bool x)
Definition Bmp.hxx:68
Bit(Bmp &bmp, xwsq_t index)
Definition Bmp.hxx:47
Bit & operator=(const Bit &&other)
Definition Bmp.hxx:85
xwsq_t mBit
Definition Bmp.hxx:44
Bit & operator=(const Bit &other)
Definition Bmp.hxx:77
Bit(const Bit &other)
Definition Bmp.hxx:57
bool all()
Definition Bmp.hxx:268
Bmp< TNum > & operator^=(const Bmp< TNum > &&other)
Definition Bmp.hxx:356
xwssq_t ffs()
Definition Bmp.hxx:247
bool operator>(const Bmp< TNum > &other)
Definition Bmp.hxx:382
Bmp(unsigned long long x)
Definition Bmp.hxx:136
bool operator<=(const Bmp< TNum > &&other)
Definition Bmp.hxx:410
Bmp< TNum > operator|(const Bmp< TNum > &other)
Definition Bmp.hxx:307
void clear()
Definition Bmp.hxx:211
xwssq_t ffz()
Definition Bmp.hxx:255
Bmp< TNum > operator^(const Bmp< TNum > &&other)
Definition Bmp.hxx:325
Bmp(unsigned int x)
Definition Bmp.hxx:154
Bmp(long long x)
Definition Bmp.hxx:163
void flip(Bmp< TNum > *msk)
Definition Bmp.hxx:239
bool operator<(const Bmp< TNum > &other)
Definition Bmp.hxx:390
bool operator<(const Bmp< TNum > &&other)
Definition Bmp.hxx:394
Bmp< TNum > & operator^=(const Bmp< TNum > &other)
Definition Bmp.hxx:351
bool operator==(const Bmp< TNum > &other)
Definition Bmp.hxx:366
Bmp< TNum > & operator=(const Bmp< TNum > &other)
Definition Bmp.hxx:281
bool none()
Definition Bmp.hxx:276
Bmp< TNum > & operator&=(const Bmp< TNum > &&other)
Definition Bmp.hxx:336
xwssq_t flz()
Definition Bmp.hxx:259
void set(Bmp< TNum > *msk)
Definition Bmp.hxx:203
xwbmp_t mData[(((TNum)+(8U *sizeof(xwbmp_t)) - 1U)/(8U *sizeof(xwbmp_t)))]
Definition Bmp.hxx:112
Bmp< TNum > operator&(const Bmp< TNum > &other)
Definition Bmp.hxx:295
Bmp< TNum > & operator&=(const Bmp< TNum > &other)
Definition Bmp.hxx:331
void set(xwsq_t pos)
Definition Bmp.hxx:197
bool operator>(const Bmp< TNum > &&other)
Definition Bmp.hxx:386
Bmp< TNum > & operator~()
Definition Bmp.hxx:361
Bmp(const Bmp &other)
Definition Bmp.hxx:115
void flip(Bmp< TNum > &msk)
Definition Bmp.hxx:243
Bmp(unsigned long x)
Definition Bmp.hxx:145
Bmp(const Bmp &&other)
Definition Bmp.hxx:119
Bmp< TNum > & operator=(const Bmp< TNum > &&other)
Definition Bmp.hxx:288
bool operator>=(const Bmp< TNum > &other)
Definition Bmp.hxx:398
void flip()
Definition Bmp.hxx:229
xwssq_t fls()
Definition Bmp.hxx:251
bool operator<=(const Bmp< TNum > &other)
Definition Bmp.hxx:406
Bmp< TNum > & operator|=(const Bmp< TNum > &&other)
Definition Bmp.hxx:346
Bmp< TNum > operator|(const Bmp< TNum > &&other)
Definition Bmp.hxx:313
void clear(Bmp< TNum > &msk)
Definition Bmp.hxx:225
bool operator!=(const Bmp< TNum > &&other)
Definition Bmp.hxx:378
Bmp(int x)
Definition Bmp.hxx:181
void flip(xwsq_t pos)
Definition Bmp.hxx:233
void set()
Definition Bmp.hxx:193
bool operator>=(const Bmp< TNum > &&other)
Definition Bmp.hxx:402
xwsz_t weight()
Definition Bmp.hxx:263
bool operator!=(const Bmp< TNum > &other)
Definition Bmp.hxx:374
Bmp(long x)
Definition Bmp.hxx:172
Bmp(xwu8_t x[], xwsz_t sz)
Definition Bmp.hxx:127
Bmp< TNum > & operator|=(const Bmp< TNum > &other)
Definition Bmp.hxx:341
void set(Bmp< TNum > &msk)
Definition Bmp.hxx:207
void clear(xwsq_t pos)
Definition Bmp.hxx:215
Bmp< TNum > operator^(const Bmp< TNum > &other)
Definition Bmp.hxx:319
Bit operator[](xwsq_t pos)
Definition Bmp.hxx:418
Bmp< TNum > operator&(const Bmp< TNum > &&other)
Definition Bmp.hxx:301
bool operator==(const Bmp< TNum > &&other)
Definition Bmp.hxx:370
bool any()
Definition Bmp.hxx:272
void clear(Bmp< TNum > *msk)
Definition Bmp.hxx:221
unsigned long xwsz_t
Definition type.h:339
uint8_t xwu8_t
Definition type.h:194
unsigned long xwsq_t
Definition type.h:445
signed long xwssq_t
Definition type.h:461
xwu32_t xwbmp_t
Definition type.h:574
xwssq_t xwbmpop_ffs(xwbmp_t *bmp, xwsz_t num)
在位图中从最低位起查找第一个被置1的位
xwssq_t xwbmpop_fls(xwbmp_t *bmp, xwsz_t num)
在位图中从最高位起查找第一个被置1的位
bool xwbmpop_t0ma(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
测试位图中掩码部分是否全部为0
Definition xwbop.c:828
bool xwbmpop_t1mo(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
测试位图中掩码部分是否至少有一位为1
Definition xwbop.c:787
void xwbmpop_xor(xwbmp_t *bmp, const xwbmp_t opd[], xwsz_t num)
将位图与操作数进行逐位“异或”运算
Definition xwbop.c:946
bool xwbmpop_t1i(xwbmp_t *bmp, xwsq_t n)
测试位图中的单个位是否为1
Definition xwbop.c:732
#define BITS_TO_XWBMP_T(n)
Definition xwbop.h:35
void xwbmpop_or(xwbmp_t *bmp, const xwbmp_t opd[], xwsz_t num)
将位图与操作数进行逐位“或”运算
Definition xwbop.c:934
xwssq_t xwbmpop_flz(xwbmp_t *bmp, xwsz_t num)
在位图中从最高位起查找第一个被清0的位
void xwbmpop_c0all(xwbmp_t *bmp, xwsq_t num)
将位图中所有位清0
Definition xwbop.c:658
bool xwbmpop_t1ma(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
测试位图中掩码部分是否全部为1
Definition xwbop.c:746
void xwbmpop_c0m(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
将位图中掩码部分清0
Definition xwbop.c:699
void xwbmpop_s1i(xwbmp_t *bmp, xwsq_t n)
将位图中单个位置1
void xwbmpop_x1m(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
将位图中掩码部分翻转
Definition xwbop.c:720
void xwbmpop_s1all(xwbmp_t *bmp, xwsq_t num)
将位图中所有位置1
Definition xwbop.c:647
xwssq_t xwbmpop_cmp(xwbmp_t *bmp, const xwbmp_t opd[], xwsz_t num)
从数组最高元素开始比较两个位图的数值大小
Definition xwbop.c:625
void xwbmpop_assign(xwbmp_t *bmp, const xwbmp_t opd[], xwsz_t num)
赋值操作数到位图
Definition xwbop.c:614
void xwbmpop_x1i(xwbmp_t *bmp, xwsq_t n)
将位图中单个位翻转
void xwbmpop_not(xwbmp_t *bmp, xwsz_t num)
将位图按位取反
Definition xwbop.c:910
void xwbmpop_c0i(xwbmp_t *bmp, xwsq_t n)
将位图中单个位清0
xwssq_t xwbmpop_ffz(xwbmp_t *bmp, xwsz_t num)
在位图中从最低位起查找第一个被清0的位
xwsz_t xwbmpop_weight(xwbmp_t *bmp, xwsz_t num)
在位图中统计被置1的位的个数
Definition xwbop.c:1068
void xwbmpop_s1m(xwbmp_t *bmp, const xwbmp_t msk[], xwsz_t num)
将位图中掩码部分置1
Definition xwbop.c:678
void xwbmpop_and(xwbmp_t *bmp, const xwbmp_t opd[], xwsz_t num)
将位图与操作数进行逐位“与”运算
Definition xwbop.c:922
Definition Bmp.hxx:21
XWOS通用库:位操作