00001 /****************************************************************************** 00002 * 00003 * $Id: $ 00004 * 00005 * Copyright (C) 1997-2008 by Dimitri van Heesch. 00006 * 00007 * Permission to use, copy, modify, and distribute this software and its 00008 * documentation under the terms of the GNU General Public License is hereby 00009 * granted. No representations are made about the suitability of this software 00010 * for any purpose. It is provided "as is" without express or implied warranty. 00011 * See the GNU General Public License for more details. 00012 * 00013 * Documents produced by Doxygen are derivative works derived from the 00014 * input used in their production; they are not affected by this license. 00015 * 00016 */ 00017 00018 #ifndef STORE_H 00019 #define STORE_H 00020 00021 #include <qglobal.h> 00022 #include <stdio.h> 00023 00024 #include "portable.h" 00025 00027 class StorageIntf 00028 { 00029 public: 00031 virtual ~StorageIntf() {} 00033 virtual int read(char *buf,uint size) = 0; 00035 virtual int write(const char *buf,uint size) = 0; 00036 }; 00037 00052 class Store : public StorageIntf 00053 { 00054 public: 00056 Store(); 00057 00059 ~Store(); 00060 00064 int open(const char *name); 00065 00067 portable_off_t alloc(); 00068 00073 int write(const char *buf,uint size); 00074 00079 void end(); 00080 00082 void release(portable_off_t handle); 00083 00085 void close(); 00086 00088 void seek(portable_off_t handle); 00089 00093 int read(char *buf,uint size); 00094 00095 void printStats(); 00096 00097 private: 00098 enum State 00099 { 00100 Init, 00101 Reading, 00102 Writing 00103 }; 00104 struct Node 00105 { 00106 portable_off_t pos; 00107 struct Node *next; 00108 }; 00109 void printFreeList(); 00110 FILE *m_file; 00111 portable_off_t m_front; 00112 Node *m_head; 00113 State m_state; 00114 int m_reads; 00115 int m_writes; 00116 }; 00117 00118 #endif