UCommon
bitmap.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
2 //
3 // This file is part of GNU uCommon C++.
4 //
5 // GNU uCommon C++ is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // GNU uCommon C++ is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
17 
26 #ifndef _UCOMMON_BITMAP_H_
27 #define _UCOMMON_BITMAP_H_
28 
29 #ifndef _UCOMMON_CONFIG_H_
30 #include <ucommon/platform.h>
31 #endif
32 
33 NAMESPACE_UCOMMON
34 
51 class __EXPORT bitmap
52 {
53 protected:
54  size_t size;
55 
56  typedef union
57  {
58  void *a;
59  uint8_t *b;
60  uint16_t *w;
61  uint32_t *l;
62  uint64_t *d;
63  } addr_t;
64 
65  addr_t addr;
66 
67 public:
71  typedef enum {
73  B8,
74  B16,
75  B32,
76  B64,
77  BMIN = BMALLOC,
78  BMAX = B64
79  } bus_t;
80 
81 protected:
82  bus_t bus;
83 
84  unsigned memsize(void) const;
85 
86 public:
93  bitmap(void *addr, size_t length, bus_t size = B8);
94 
100  bitmap(size_t length);
101 
107  ~bitmap();
108 
112  void clear(void);
113 
119  bool get(size_t offset) const;
120 
126  void set(size_t offset, bool value);
127 };
128 
129 END_NAMESPACE
130 
131 #endif