CPP   30

public DB

Guest on 22nd August 2022 01:40:57 PM

  1.  
  2. DB-MANAGER HEADER FILE
  3. ----------------------
  4.  
  5. #ifndef _DB_H
  6. #define _DB_H
  7.  
  8. #include <string.h>
  9. #include <stdlib.h>
  10.  
  11. #include "page.h"
  12.  
  13.  
  14. // Each database is basically a UNIX file and consists of several relations
  15. // (viewed as heapfiles and their indexes) within it.
  16.  
  17. // Class definition for DB which manages a database.
  18.  
  19.  
  20.   // This is the maximum length of the name of a "file" within a database.
  21. const int MAX_NAME = 50;
  22.  
  23.  
  24. enum dbErrCodes {
  25.     DB_FULL,
  26.     DUPLICATE_ENTRY,
  27.     UNIX_ERROR,
  28.     BAD_PAGE_NO,
  29.     FILE_IO_ERROR,
  30.     FILE_NOT_FOUND,
  31.     FILE_NAME_TOO_LONG,
  32.     NEG_RUN_SIZE,
  33. };
  34.  
  35. // oooooooooooooooooooooooooooooooooooooo
  36.  
  37. class DB {
  38.  
  39.   public:
  40.     // Constructors
  41.     // Create a database with the specified number of pages where the page
  42.     // size is the default page size.
  43.     DB( const char* name, unsigned num_pages, Status& status );
  44.  
  45.     // Open the database with the given name.
  46.     DB( const char* name, Status& status );
  47.  
  48.     // Destructor: closes the database
  49.    ~DB();
  50.  
  51.     // Destroy the database, removing the file that stores it.
  52.     Status db_destroy();
  53.  
  54.     // Read the contents of the specified page into the given memory area.
  55.     Status read_page(PageId pageno, Page* pageptr);
  56.  
  57.     // Write the contents of the specified page.
  58.     Status write_page(PageId pageno, Page* pageptr);
  59.  
  60.     // Allocate a set of pages where the run size is taken to be 1 by default.
  61.     // Gives back the page number of the first page of the allocated run.
  62.     Status allocate_page(PageId& start_page_num, int run_size = 1);
  63.  
  64.     // Deallocate a set of pages starting at the specified page number and
  65.     // a run size can be specified.
  66.     Status deallocate_page(PageId start_page_num, int run_size = 1);
  67.  
  68.  
  69.     // oooooooooooooooooooooooooooooooooooooo
  70.  
  71.     // Adds a file entry to the header page(s).
  72.     Status add_file_entry(const char* fname, PageId start_page_num);
  73.  
  74.     // Delete the entry corresponding to a file from the header page(s).
  75.     Status delete_file_entry(const char* fname);
  76.  
  77.     // Get the entry corresponding to the given file.
  78.     Status get_file_entry(const char* name, PageId& start_pg);
  79.  
  80.     // Functions to return some characteristics of the database.
  81.     const char* db_name() const;
  82.     int db_num_pages() const;
  83.     int db_page_size() const;
  84.  
  85.     // Print out the space map of the database.
  86.     // The space map is a bitmap showing which
  87.     // pages of the db are currently allocated.
  88.     Status dump_space_map();
  89. };
  90.  
  91. // oooooooooooooooooooooooooooooooooooooo
  92.  
  93. #endif    // _DB_H

Raw Paste


Login or Register to edit or fork this paste. It's free.