00001
00002
00003
00004
00005
00006
00007
00008 #ifndef ALLOCATIONPAGE_H_
00009 #define ALLOCATIONPAGE_H_
00010
00011 #include "Common.h"
00012 #include <limits.h>
00013
00017 class AllocationPage {
00018 public:
00019 AllocationPage();
00020 ~AllocationPage();
00021 int getFirstPage(bool isFree);
00022 int getLastPage(bool isFree);
00023 int getNextPage(int pageNo, bool isFree);
00024 int getPrevPage(int pageNo, bool isFree);
00025 bool isPageFree(int pageNo);
00026 ReturnCode markPageFree(int pageNo, bool isFree);
00027 uint getAllocatedPageCount();
00028
00029 ReturnCode serialize(char *buffer);
00030 static ReturnCode deserialize(const char* buffer, AllocationPage* page);
00031
00032 static const uint VERSION = 2;
00033 static const int BITMAP_SIZE = PF_PAGE_SIZE - sizeof(uint);
00034 static const int RANGE_SIZE = BITMAP_SIZE*CHAR_BIT;
00035
00036 private:
00037 bool testBit(int byte, int bitNo, bool isFree);
00038 int getNeighborBit(int bitNo, uchar byte, bool isFree, bool isNext);
00039 int getNeighborPage(int pageNo, bool isFree, bool isNext);
00040 uint versionNo_;
00041 uchar bitmap_[BITMAP_SIZE];
00042 };
00043
00044 #endif