00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef _SOCKETS_MemFile_H
00033 #define _SOCKETS_MemFile_H
00034
00035 #include "sockets-config.h"
00036 #include <map>
00037 #include "File.h"
00038 #include "Mutex.h"
00039
00040 #define BLOCKSIZE 32768
00041
00042 #ifdef SOCKETS_NAMESPACE
00043 namespace SOCKETS_NAMESPACE {
00044 #endif
00045
00046
00049 class MemFile : public IFile
00050 {
00051 public:
00054 struct block_t {
00055 block_t() : next(NULL) {}
00056 struct block_t *next;
00057 char data[BLOCKSIZE];
00058 };
00059 public:
00061 MemFile();
00063 MemFile(MemFile& );
00065 MemFile(File& f);
00066 ~MemFile();
00067
00068 bool fopen(const std::string& path, const std::string& mode);
00069 void fclose() const;
00070
00071 size_t fread(char *ptr, size_t size, size_t nmemb) const;
00072 size_t fwrite(const char *ptr, size_t size, size_t nmemb);
00073
00074 char *fgets(char *s, int size) const;
00075 void fprintf(const char *format, ...);
00076
00077 off_t size() const;
00078 bool eof() const;
00079
00080 void reset_read() const;
00081 void reset_write();
00082
00084 int RefCount() const;
00085 void Increase();
00086 void Decrease();
00087
00088 const std::string& Path() const;
00089
00090 private:
00091 MemFile& operator=(const MemFile& ) { return *this; }
00092
00093 MemFile& m_src;
00094 bool m_src_valid;
00095 block_t *m_base;
00096 mutable block_t *m_current_read;
00097 block_t *m_current_write;
00098 int m_current_write_nr;
00099 mutable size_t m_read_ptr;
00100 size_t m_write_ptr;
00101 mutable bool m_b_read_caused_eof;
00102 int m_ref_count;
00103 mutable bool m_ref_decreased;
00104 std::string m_path;
00105 };
00106
00107
00108
00109
00110 #ifdef SOCKETS_NAMESPACE
00111 }
00112 #endif
00113
00114 #endif // _SOCKETS_MemFile_H
00115