Column-oriented GPU-accelerated Database Management System
CoGaDB
/home/sebastian/gpudbms/trunk/cogadb/include/persistence/page.hpp
Go to the documentation of this file.
00001 #pragma once
00002 #include <iostream>
00003 #include <fstream>
00004 #include <core/global_definitions.hpp>
00005 
00006 #define VARCHAR_LENGTH_BYTES 2; // Number of Bytes for decoding the length of a string
00007 #define BIT_COMPRESSED 0;       // C -> Is page content compressed?
00008 #define BIT_TYPE_LOW 1;         // T -> datatype of page content
00009 #define BIT_TYPE_HIGH 2;        // T 
00010 #define BIT_DIRTY 3;            // D -> Page modified?
00011 #define BIT_USAGE 4;            // U -> Is Page in usage?
00012 #define BIT_LENGTH 5;           // L -> Count of size-byte's
00013 #define DATA_OFFSET 1;          // Number of bytes where data starts in file
00014 
00015 namespace CoGaDB
00016 {
00032 struct Header
00033 {
00035         char Status;
00037         unsigned short Size;  
00039         int Offset;       
00041     unsigned short Count;    
00042 };
00044         class Page
00045         {
00046         private:   
00048             Header _header; 
00050                 char* _data;  
00051         bool _isFull; 
00052         std::vector<unsigned int> _value_offsets;               
00053         public:     
00054             /* Use for new columns */
00055             Page(bool, AttributeType, bool);
00056                 Page(const Page&);
00057                 Page& operator=(const Page&);
00058                 /* Use for loading columns from hdd */
00059                 Page(std::ifstream&, char);
00060                 virtual ~Page();
00061             bool isCompressed() const;
00062             AttributeType getType() const;
00063             bool isDirty() const;
00064             bool isInUsage() const;
00066             unsigned short getDataSize() const;
00067         int getFileOffset() const;      
00069                 unsigned short getMaxDataSize() const;
00070                 void printStatus() const;               
00071                 int getSizeOfOneValue() const;          
00072                 void print() const;
00073                 bool isFull() const;
00074                 char* getData();                
00075                 unsigned short count() const;
00076                 char* getStringByIndex(unsigned int index, unsigned short& valueSize);
00077                 char* getValueByIndex(unsigned int index, unsigned short& valueSize);
00078         protected:
00079             bool appendData(std::ifstream&);
00080             char getStatusBitAt(char) const;
00081                 bool append(std::ifstream&);
00082                 bool appendVarchar(std::ifstream&);
00083                 void setStatusBit(char, bool);          
00084                 void printInt(unsigned short) const;
00085                 void printFloat(unsigned short) const;
00086                 void printBool(unsigned short) const;
00087                 int printVarchar(unsigned short) const;         
00088         }; 
00089         
00091 typedef shared_pointer_namespace::shared_ptr<Page> PagePtr;
00092 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines