00001 /* 00002 * BLOB.h 00003 * 00004 * Created on: 15.12.2009 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef BLOB_H_ 00009 #define BLOB_H_ 00010 00011 #include "ibrcommon/thread/Mutex.h" 00012 #include "ibrcommon/data/File.h" 00013 #include <iostream> 00014 #include <sstream> 00015 #include <fstream> 00016 00017 #ifdef __GNUC__ 00018 #define DEPRECATED(func) func __attribute__ ((deprecated)) 00019 #elif defined(_MSC_VER) 00020 #define DEPRECATED(func) __declspec(deprecated) func 00021 #else 00022 #pragma message("WARNING: You need to implement DEPRECATED for this compiler") 00023 #define DEPRECATED(func) func 00024 #endif 00025 00026 namespace ibrcommon 00027 { 00028 class CanNotOpenFileException : public ibrcommon::IOException 00029 { 00030 public: 00031 CanNotOpenFileException(ibrcommon::File f) throw() : IOException("Could not open file " + f.getPath() + ".") 00032 { 00033 }; 00034 }; 00035 00036 class BLOB : public Mutex 00037 { 00038 public: 00043 static File tmppath; 00044 00045 virtual ~BLOB(); 00046 00047 virtual void clear() = 0; 00048 00049 class Reference : public Mutex 00050 { 00051 public: 00052 Reference(BLOB *blob); 00053 Reference(const Reference &ref); 00054 virtual ~Reference(); 00055 00056 std::iostream& operator* (); 00057 00058 void enter(); 00059 void leave(); 00060 00061 void clear(); 00062 00063 size_t getSize() const; 00064 00065 private: 00066 BLOB *_blob; 00067 }; 00068 00069 protected: 00070 BLOB(std::iostream &stream); 00071 void increment(); 00072 void decrement(); 00073 bool isUnbound(); 00074 00075 virtual size_t getSize() const; 00076 00077 std::iostream &_stream; 00078 00079 private: 00080 BLOB(const BLOB &ref); // forbidden copy constructor 00081 size_t _refcount; 00082 Mutex _reflock; 00083 }; 00084 00085 class StringBLOB : public BLOB 00086 { 00087 public: 00088 static BLOB::Reference create(); 00089 virtual ~StringBLOB(); 00090 00091 virtual void clear(); 00092 00093 private: 00094 StringBLOB(); 00095 std::stringstream _stringstream; 00096 }; 00097 00098 class FileBLOB : public BLOB 00099 { 00100 public: 00101 static BLOB::Reference create(const File &f); 00102 virtual ~FileBLOB(); 00103 00104 virtual void clear(); 00105 00106 private: 00107 FileBLOB(const File &f); 00108 std::fstream _filestream; 00109 File _file; 00110 }; 00111 00112 class TmpFileBLOB : public BLOB 00113 { 00114 public: 00115 static BLOB::Reference create(); 00116 virtual ~TmpFileBLOB(); 00117 00118 virtual void clear(); 00119 00120 private: 00121 TmpFileBLOB(); 00122 File getTmpFile(); 00123 std::fstream _filestream; 00124 File _tmpfile; 00125 }; 00126 } 00127 00128 #endif /* BLOB_H_ */
1.5.6