WiscDB
buffer.cpp
00001 
00009 #include <memory>
00010 #include <iostream>
00011 #include "buffer.h"
00012 #include "exceptions/buffer_exceeded_exception.h"
00013 #include "exceptions/page_not_pinned_exception.h"
00014 #include "exceptions/page_pinned_exception.h"
00015 #include "exceptions/bad_buffer_exception.h"
00016 #include "exceptions/hash_not_found_exception.h"
00017 
00018 namespace wiscdb { 
00019 // Frame class implementation
00020 
00021 void Frame::Frame(){
00022   reset();
00023 }
00024 
00025 void Frame::reset(){
00026   //TODO: reset all member variables
00027 }
00028 
00029 void Frame::load(File* filePtr, PageId pageNum){
00030   //TODO: set all member variables for a newly loaded page
00031 }
00032 
00033 void Frame::print(){
00034   if(file){
00035     std::cout << "file:" << file->filename() << " ";
00036     std::cout << "pageNo:" << pageNo << " ";
00037   }
00038   else
00039     std::cout << "file:NULL ";
00040 
00041   std::cout << "valid:" << valid << " ";
00042   std::cout << "pinCnt:" << pinCnt << " ";
00043   std::cout << "dirty:" << dirty << " ";
00044   std::cout << "refbit:" << refbit << "\n";
00045 }
00046 
00047 //----------------------------------------
00048 // class BufferManager
00049 //----------------------------------------
00050 
00051 BufferManager::BufferManager(std::uint32_t bufs) : numBufs(bufs) {
00052   frameTable = new Frame[bufs];
00053 
00054   for (FrameId i = 0; i < bufs; i++) 
00055   {
00056     frameTable[i].frameNo = i;
00057     frameTable[i].valid = false;
00058   }
00059 
00060   bufPool = new Page[bufs];
00061 
00062   int htsize = ((((int) (bufs * 1.2))*2)/2)+1;
00063   hashTable = new BufferHashTable (htsize);  // allocate the buffer hash table
00064 
00065   clockHand = bufs - 1;
00066 }
00067 
00068 
00069 BufferManager::~BufferManager() {
00070 }
00071 
00072 void BufferManager::allocateFrame(FrameId & frame) {
00073 }
00074 
00075   
00076 void BufferManager::readPage(File* file, const PageId pageNo, Page*& page){
00077 }
00078 
00079 
00080 void BufferManager::unPinPage(File* file, const PageId pageNo, const bool dirty){
00081 }
00082 
00083 void BufferManager::flushFile(const File* file) {
00084 }
00085 
00086 void BufferManager::disposePage(File* file, const PageId pageNo) {
00087 }
00088 
00089 
00090 void BufferManager::allocatePage(File* file, PageId &pageNo, Page*& page) {
00091 }
00092 
00093 void BufferManager::printSelf() 
00094 {
00095   Frame* tmpFrame;
00096   int validFrames = 0;
00097   
00098   for (std::uint32_t i = 0; i < numBufs; i++)
00099   {
00100     tmpFrame = &(frameTable[i]);
00101     std::cout << "FrameNo:" << i << " ";
00102     tmpFrame->print();
00103 
00104     if (tmpFrame->valid == true)
00105       validFrames++;
00106   }
00107 
00108   std::cout << "Total Number of Valid Frames:" << validFrames << "\n";
00109 }
00110 
00111 void BufferManager::advanceClock(){
00112 }
00113 
00114 }
 All Classes Functions Variables Friends