Writer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef BASE_WRITER_H
00024 #define BASE_WRITER_H
00025
00026
00027 #include <string>
00028 #include <sstream>
00029 #include <vector>
00030 #include <cassert>
00031
00032 #include <zipios++/zipios-config.h>
00033 #include <zipios++/zipfile.h>
00034 #include <zipios++/zipinputstream.h>
00035 #include <zipios++/zipoutputstream.h>
00036 #include <zipios++/meta-iostreams.h>
00037
00038 #include "FileInfo.h"
00039
00040
00041
00042 namespace Base
00043 {
00044
00045 class Persistence;
00046
00047
00054 class BaseExport Writer
00055 {
00056
00057 public:
00058 Writer(void);
00059 virtual ~Writer();
00060
00062 void setForceXML(bool on);
00064 bool isForceXML(void);
00065
00067 void insertAsciiFile(const char* FileName);
00069 void insertBinFile(const char* FileName);
00070
00073
00074 std::string addFile(const char* Name, const Base::Persistence *Object);
00076 virtual void writeFiles(void)=0;
00078 const std::vector<std::string>& getFilenames() const;
00080
00083
00084 const char* ind(void) const {return indBuf;}
00086 void incInd(void);
00088 void decInd(void);
00090
00091 virtual std::ostream &Stream(void)=0;
00092
00094 std::string ObjectName;
00095
00096 protected:
00097 std::string getUniqueFileName(const char *Name);
00098 struct FileEntry {
00099 std::string FileName;
00100 const Base::Persistence *Object;
00101 };
00102 std::vector<FileEntry> FileList;
00103 std::vector<std::string> FileNames;
00104
00105 short indent;
00106 char indBuf[256];
00107
00108 bool forceXML;
00109 };
00110
00111
00118 class BaseExport ZipWriter : public Writer
00119 {
00120
00121 public:
00122 ZipWriter(const char* FileName);
00123 ZipWriter(std::ostream&);
00124 ~ZipWriter();
00125
00126 virtual void writeFiles(void);
00127
00128 virtual std::ostream &Stream(void){return ZipStream;}
00129
00130 void setComment(const char* str){ZipStream.setComment(str);}
00131 void setLevel(int level){ZipStream.setLevel( level );}
00132 void putNextEntry(const char* str){ZipStream.putNextEntry(str);}
00133
00134 private:
00135 zipios::ZipOutputStream ZipStream;
00136 };
00137
00144 class BaseExport StringWriter : public Writer
00145 {
00146
00147 public:
00148 virtual std::ostream &Stream(void){return StrStream;}
00149 std::string getString(void){return StrStream.str();}
00150 virtual void writeFiles(void){assert(0);}
00151
00152 private:
00153 std::stringstream StrStream;
00154 };
00155
00156
00157 }
00158
00159
00160 #endif // BASE_WRITER_H