summaryrefslogtreecommitdiff
path: root/include/grail-bits.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/grail-bits.h')
-rw-r--r--include/grail-bits.h65
1 files changed, 65 insertions, 0 deletions
diff --git a/include/grail-bits.h b/include/grail-bits.h
new file mode 100644
index 0000000..ca04c3f
--- /dev/null
+++ b/include/grail-bits.h
@@ -0,0 +1,65 @@
1/*****************************************************************************
2 *
3 * grail - Gesture Recognition And Instantiation Library
4 *
5 * Copyright (C) 2010 Canonical Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authors:
21 * Henrik Rydberg <rydberg@bitmath.org>
22 *
23 ****************************************************************************/
24
25#ifndef _GRAIL_BITS_H
26#define _GRAIL_BITS_H
27
28typedef unsigned char grail_mask_t;
29
30static inline void grail_mask_set(grail_mask_t *mask, int i)
31{
32 mask[i >> 3] |= (1 << (i & 7));
33}
34
35static inline void grail_mask_clear(grail_mask_t *mask, int i)
36{
37 mask[i >> 3] &= ~(1 << (i & 7));
38}
39
40static inline void grail_mask_modify(grail_mask_t *mask, int i, int v)
41{
42 if (v)
43 grail_mask_set(mask, i);
44 else
45 grail_mask_clear(mask, i);
46}
47
48static inline int grail_mask_get(const grail_mask_t *mask, int i)
49{
50 return (mask[i >> 3] >> (i & 7)) & 1;
51}
52
53void grail_mask_set_mask(grail_mask_t *a, const grail_mask_t *b, int bytes);
54void grail_mask_clear_mask(grail_mask_t *a, const grail_mask_t *b, int bytes);
55
56int grail_mask_count(const grail_mask_t *mask, int bytes);
57int grail_mask_get_first(const grail_mask_t *mask, int bytes);
58int grail_mask_get_next(int i, const grail_mask_t *mask, int bytes);
59
60#define grail_mask_foreach(i, mask, bytes) \
61 for (i = grail_mask_get_first(mask, bytes); \
62 i >= 0; \
63 i = grail_mask_get_next(i, mask, bytes))
64
65#endif