00001 /* 00002 * Copyright (C) 2009, Edmundo Albuquerque de Souza e Silva. 00003 * 00004 * This file may be distributed under the terms of the Q Public License 00005 * as defined by Trolltech AS of Norway and appearing in the file 00006 * LICENSE.QPL included in the packaging of this file. 00007 * 00008 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING 00009 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00010 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 00011 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 00012 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00013 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00014 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 * 00016 * Thanks: Jose Renato Santos 00017 * 00018 */ 00019 00020 /////////////////////////////////////////////////////////////////////////////// 00021 // BitMap.h: interface for the BitMap class. 00022 /////////////////////////////////////////////////////////////////////////////// 00023 00024 #include <fstream> 00025 #include <iostream> 00026 using namespace std; 00027 00028 /////////////////////////////////////////////////////////////////////////////// 00029 class BitMap 00030 { 00031 private: 00032 char *m_FileName; 00033 unsigned int m_nBits; 00034 unsigned int m_nFree; 00035 unsigned int m_nFreeConfirmed; 00036 unsigned int m_nBytes; 00037 unsigned char *m_BitMap; 00038 00039 int m_handle; 00040 ostream *m_log; 00041 bool m_changed; 00042 00043 void ifreestg(); 00044 int iclose(); 00045 unsigned int CountnFree(); 00046 bool TestBit(const unsigned int Bit); 00047 void SetBit (const unsigned int Bit); 00048 void ClearBit (const unsigned int Bit); 00049 unsigned int CountFreeBits (const int Byte); 00050 00051 public: 00052 BitMap(); 00053 ~BitMap(); 00054 int Initialize( char *BitMapFileName, 00055 unsigned int nBits, 00056 ostream *LogStream ); 00057 int Format(); 00058 int Load(); 00059 int Reset(); 00060 int Confirm(); 00061 int Close(); 00062 int AllocSeq( unsigned int Startbit, unsigned int *Bit ); 00063 void Free( unsigned int Bit ); 00064 unsigned int nFree() { return m_nFree; }; 00065 };