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 00051 virtual void clear() = 0; 00052 00053 class Reference : public Mutex 00054 { 00055 public: 00056 Reference(BLOB *blob); 00057 Reference(const Reference &ref); 00058 virtual ~Reference(); 00059 00064 std::iostream& operator* (); 00065 00070 void enter(); 00071 00075 void leave(); 00076 00081 void clear(); 00082 00087 size_t getSize() const; 00088 00089 private: 00090 BLOB *_blob; 00091 }; 00092 00093 protected: 00094 BLOB(std::iostream &stream); 00095 void increment(); 00096 void decrement(); 00097 bool isUnbound(); 00098 00099 virtual size_t getSize() const; 00100 00101 std::iostream &_stream; 00102 00103 private: 00104 BLOB(const BLOB &ref); // forbidden copy constructor 00105 size_t _refcount; 00106 Mutex _reflock; 00107 }; 00108 00113 class StringBLOB : public BLOB 00114 { 00115 public: 00116 static BLOB::Reference create(); 00117 virtual ~StringBLOB(); 00118 00119 virtual void clear(); 00120 00121 private: 00122 StringBLOB(); 00123 std::stringstream _stringstream; 00124 }; 00125 00130 class FileBLOB : public BLOB 00131 { 00132 public: 00133 static BLOB::Reference create(const File &f); 00134 virtual ~FileBLOB(); 00135 00136 virtual void clear(); 00137 00138 private: 00139 FileBLOB(const File &f); 00140 std::fstream _filestream; 00141 File _file; 00142 }; 00143 00149 class TmpFileBLOB : public BLOB 00150 { 00151 public: 00152 static BLOB::Reference create(); 00153 virtual ~TmpFileBLOB(); 00154 00155 virtual void clear(); 00156 00157 private: 00158 TmpFileBLOB(); 00159 File getTmpFile(); 00160 std::fstream _filestream; 00161 File _tmpfile; 00162 }; 00163 } 00164 00165 #endif /* BLOB_H_ */
1.6.3