UCommon
ucommon/bitmap.h
Go to the documentation of this file.
00001 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
00002 //
00003 // This file is part of GNU uCommon C++.
00004 //
00005 // GNU uCommon C++ is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published
00007 // by the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // GNU uCommon C++ is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with GNU uCommon C++.  If not, see <http://www.gnu.org/licenses/>.
00017 
00026 #ifndef _UCOMMON_BITMAP_H_
00027 #define _UCOMMON_BITMAP_H_
00028 
00029 #ifndef _UCOMMON_CONFIG_H_
00030 #include <ucommon/platform.h>
00031 #endif
00032 
00033 NAMESPACE_UCOMMON
00034 
00051 class __EXPORT bitmap
00052 {
00053 protected:
00054     size_t size;
00055 
00056     typedef union
00057     {
00058         void *a;
00059         uint8_t *b;
00060         uint16_t *w;
00061         uint32_t *l;
00062         uint64_t *d;
00063     }   addr_t;
00064 
00065     addr_t addr;
00066 
00067 public:
00071     typedef enum {
00072         BMALLOC,    
00073         B8,         
00074         B16,        
00075         B32,        
00076         B64,        
00077         BMIN = BMALLOC,
00078         BMAX = B64
00079     } bus_t;
00080 
00081 protected:
00082     bus_t bus;
00083 
00084     unsigned memsize(void) const;
00085 
00086 public:
00093     bitmap(void *addr, size_t length, bus_t size = B8);
00094 
00100     bitmap(size_t length);
00101 
00107     ~bitmap();
00108 
00112     void clear(void);
00113 
00119     bool get(size_t offset) const;
00120 
00126     void set(size_t offset, bool value);
00127 };
00128 
00129 END_NAMESPACE
00130 
00131 #endif