Writer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de)          *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
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 }  //namespace Base
00158 
00159 
00160 #endif // BASE_WRITER_H

Generated on Wed Nov 23 19:01:12 2011 for FreeCAD by  doxygen 1.6.1