/usr/include/ucommon/bitmap.h is in libucommon-dev 6.0.7-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
//
// This file is part of GNU uCommon C++.
//
// GNU uCommon C++ is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU uCommon C++ is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
/**
* A simple class to perform bitmap manipulation.
* Bitmaps are used to manage bit-aligned objects, such as network cidr
* addresses. This header introduces a common bitmap management class
* for the ucommon library.
* @file ucommon/bitmap.h
*/
#ifndef _UCOMMON_BITMAP_H_
#define _UCOMMON_BITMAP_H_
#ifndef _UCOMMON_CONFIG_H_
#include <ucommon/platform.h>
#endif
NAMESPACE_UCOMMON
/**
* A class to access bit fields in external bitmaps. The actual bitmap this
* object manipulates may not be stored in the object. Bitmaps may be
* referenced on special memory mapped or i/o bus based devices or other
* structures that have varying data word sizes which may differ from the
* default cpu bus size. The bitmap class can be set to the preferred memory
* bus size of the specific external bitmap being used. Bitmap size may also
* be relevant when accessing individual bits in memory mapped device registers
* where performing reference and manipulations may change the state of the
* device and hence must be aligned with the device register being effected.
*
* This class offers only the most basic bit manipulations, getting and
* setting individual bits in the bitmap. More advanced bit manipulations
* and other operations can be created in derived classes.
* @author David Sugar <dyfet@gnutelephony.org>
*/
class __EXPORT bitmap
{
protected:
size_t size;
typedef union
{
void *a;
uint8_t *b;
uint16_t *w;
uint32_t *l;
uint64_t *d;
} addr_t;
addr_t addr;
public:
/**
* Specify data word size to use in accessing a bitmap.
*/
typedef enum {
BMALLOC, /**< Use default cpu size */
B8, /**< Accessing a bitmap on 8 bit bus device */
B16, /**< Accessing a bitmap on a 16 bit device */
B32, /**< Accessing a bitmap on a 32 bit device */
B64, /**< Accessing a bitmap on a 64 bit device */
BMIN = BMALLOC,
BMAX = B64
} bus_t;
protected:
bus_t bus;
unsigned memsize(void) const;
public:
/**
* Create an object to reference the specified bitmap.
* @param addr of the bitmap in mapped memory.
* @param length of the bitmap being accessed in bits.
* @param size of the memory bus or manipulation to use.
*/
bitmap(void *addr, size_t length, bus_t size = B8);
/**
* Create a bitmap to manipulate locally. This bitmap is created
* as part of the object itself, and uses the BMALLOC bus mode.
* @param length of bitmap to create in bits.
*/
bitmap(size_t length);
/**
* Destroy bitmap manipulation object. If a bitmap was locally
* created with the alternate constructor, that bitmap will also be
* removed from memory.
*/
~bitmap();
/**
* Clear (zero) all the bits in the bitmap.
*/
void clear(void);
/**
* Get the value of a "bit" in the bitmap.
* @param offset to bit in map to get.
* @return true if bit is set.
*/
bool get(size_t offset) const;
/**
* Set an individual bit in the bitmask.
* @param offset to bit in map to change.
* @param value to change specified bit to.
*/
void set(size_t offset, bool value);
};
END_NAMESPACE
#endif
|