diff options
| author | Thomas Holder <thomas@thomas-holder.de> | 2018-10-28 11:16:46 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-10-29 09:21:30 +0000 |
| commit | e3fc12917d5bcc872cfa010ec4d6a52f553cd78e (patch) | |
| tree | 9f856a153375966dc58da71a2f2f4b46734ce02b /src | |
| parent | Move contents of document-private.h to document.h. (diff) | |
| download | inkscape-e3fc12917d5bcc872cfa010ec4d6a52f553cd78e.tar.gz inkscape-e3fc12917d5bcc872cfa010ec4d6a52f553cd78e.zip | |
cleanup: remove most of uristream.cpp
Replace UriInputStream -> FileInputStream
Replace UriOutputStream -> FileOutputStream
Remove UriReader
Remove UriWriter
UriReader, UriWriter, and the acutal URI-based API of UriInputStream and
UriOutputStream was all unused/dead code.
Diffstat (limited to 'src')
| -rw-r--r-- | src/io/uristream.cpp | 297 | ||||
| -rw-r--r-- | src/io/uristream.h | 103 | ||||
| -rw-r--r-- | src/io/xsltstream.h | 4 | ||||
| -rw-r--r-- | src/xml/repr-io.cpp | 9 |
4 files changed, 38 insertions, 375 deletions
diff --git a/src/io/uristream.cpp b/src/io/uristream.cpp index 9fd0d9c96..dc797472d 100644 --- a/src/io/uristream.cpp +++ b/src/io/uristream.cpp @@ -81,65 +81,18 @@ static FILE *fopen_utf8name( char const *utf8name, int mode ) //######################################################################### -//# U R I I N P U T S T R E A M / R E A D E R +//# F I L E I N P U T S T R E A M //######################################################################### /** * */ -UriInputStream::UriInputStream(Inkscape::URI &source) - : uri(source) +FileInputStream::FileInputStream(FILE *source) + : inf(source) { - //get information from uri - char const *schemestr = uri.getScheme(); - scheme = SCHEME_FILE; - if (!schemestr || strncmp("file", schemestr, 4)==0) - scheme = SCHEME_FILE; - else if (strncmp("data", schemestr, 4)==0) - scheme = SCHEME_DATA; - - gchar *cpath = nullptr; - switch (scheme) { - - case SCHEME_FILE: - cpath = uri.toNativeFilename(); - inf = fopen_utf8name(cpath, FILE_READ); - if (!inf) { - Glib::ustring err = "UriInputStream cannot open file "; - err += cpath; - g_free(cpath); - throw StreamException(err); - } - else{ - g_free(cpath); - } - break; - - case SCHEME_DATA: - data = (unsigned char *) uri.getPath(); - dataPos = 0; - dataLen = strlen((const char *)data); - break; - - } - closed = false; -} - -/** - * - */ -UriInputStream::UriInputStream(FILE *source, Inkscape::URI &uri) - : uri(uri), - inf(source), - data(nullptr), - dataPos(0), - dataLen(0), - closed(false) -{ - scheme = SCHEME_FILE; if (!inf) { - Glib::ustring err = "UriInputStream passed NULL"; + Glib::ustring err = "FileInputStream passed NULL"; throw StreamException(err); } } @@ -147,7 +100,7 @@ UriInputStream::UriInputStream(FILE *source, Inkscape::URI &uri) /** * */ -UriInputStream::~UriInputStream() +FileInputStream::~FileInputStream() { close(); } @@ -157,7 +110,7 @@ UriInputStream::~UriInputStream() * this input stream without blocking by the next caller of a method for * this input stream. */ -int UriInputStream::available() +int FileInputStream::available() { return 0; } @@ -167,41 +120,21 @@ int UriInputStream::available() * Closes this input stream and releases any system resources * associated with the stream. */ -void UriInputStream::close() +void FileInputStream::close() { - if (closed) - return; - - switch (scheme) { - - case SCHEME_FILE: if (!inf) return; fflush(inf); fclose(inf); inf=nullptr; - break; - - case SCHEME_DATA: - //do nothing - break; - - }//switch - - closed = true; } /** * Reads the next byte of data from the input stream. -1 if EOF */ -int UriInputStream::get() +int FileInputStream::get() { int retVal = -1; - if (!closed) - { - switch (scheme) { - - case SCHEME_FILE: if (!inf || feof(inf)) { retVal = -1; @@ -210,87 +143,23 @@ int UriInputStream::get() { retVal = fgetc(inf); } - break; - case SCHEME_DATA: - if (dataPos >= dataLen) - { - retVal = -1; - } - else - { - retVal = data[dataPos++]; - } - break; - }//switch - } return retVal; } - - -/** - * - */ -UriReader::UriReader(Inkscape::URI &uri) - -{ - inputStream = new UriInputStream(uri); -} - -/** - * - */ -UriReader::~UriReader() -{ - delete inputStream; -} - -/** - * - */ -int UriReader::available() -{ - return inputStream->available(); -} - -/** - * - */ -void UriReader::close() -{ - inputStream->close(); -} - -/** - * - */ -char UriReader::get() -{ - char ch = inputStream->get(); - return ch; -} - - //######################################################################### -//# U R I O U T P U T S T R E A M / W R I T E R +//# F I L E O U T P U T S T R E A M //######################################################################### -/** - * Temporary kludge - */ -UriOutputStream::UriOutputStream(FILE* fp, Inkscape::URI &destination) - : closed(false), - ownsFile(false), - outf(fp), - uri(destination), - scheme(SCHEME_FILE) +FileOutputStream::FileOutputStream(FILE *fp) + : ownsFile(false) + , outf(fp) { if (!outf) { - Glib::ustring err = "UriOutputStream given null file "; + Glib::ustring err = "FileOutputStream given null file "; throw StreamException(err); } } @@ -298,52 +167,7 @@ UriOutputStream::UriOutputStream(FILE* fp, Inkscape::URI &destination) /** * */ -UriOutputStream::UriOutputStream(Inkscape::URI &destination) - : closed(false), - ownsFile(true), - outf(nullptr), - uri(destination), - scheme(SCHEME_FILE) -{ - //get information from uri - char const *schemestr = uri.getScheme(); - if (!schemestr || strncmp("file", schemestr, 4)==0) - scheme = SCHEME_FILE; - else if (strncmp("data", schemestr, 4)==0) - scheme = SCHEME_DATA; - //printf("out schemestr:'%s' scheme:'%d'\n", schemestr, scheme); - gchar *cpath = nullptr; - - switch (scheme) { - - case SCHEME_FILE: - cpath = uri.toNativeFilename(); - //printf("out path:'%s'\n", cpath); - outf = fopen_utf8name(cpath, FILE_WRITE); - //outf = fopen(cpath, "wb"); - - if (!outf) { - Glib::ustring err = "UriOutputStream cannot open file "; - err += cpath; - g_free(cpath); - throw StreamException(err); - } else { - g_free(cpath); - } - break; - - case SCHEME_DATA: - data = "data:"; - break; - - }//switch -} - - -/** - * - */ -UriOutputStream::~UriOutputStream() +FileOutputStream::~FileOutputStream() { close(); } @@ -352,68 +176,34 @@ UriOutputStream::~UriOutputStream() * Closes this output stream and releases any system resources * associated with this stream. */ -void UriOutputStream::close() +void FileOutputStream::close() { - if (closed) - return; - - switch (scheme) { - - case SCHEME_FILE: if (!outf) return; fflush(outf); if ( ownsFile ) fclose(outf); outf=nullptr; - break; - - case SCHEME_DATA: - uri = URI(data.raw().c_str()); - break; - - }//switch - - closed = true; } /** * Flushes this output stream and forces any buffered output * bytes to be written out. */ -void UriOutputStream::flush() +void FileOutputStream::flush() { - if (closed) - return; - - switch (scheme) { - - case SCHEME_FILE: if (!outf) return; fflush(outf); - break; - - case SCHEME_DATA: - //nothing - break; - - }//switch - } /** * Writes the specified byte to this output stream. */ -int UriOutputStream::put(char ch) +int FileOutputStream::put(char ch) { - if (closed) - return -1; - unsigned char uch; - switch (scheme) { - case SCHEME_FILE: if (!outf) return -1; uch = (unsigned char)(ch & 0xff); @@ -421,13 +211,7 @@ int UriOutputStream::put(char ch) Glib::ustring err = "ERROR writing to file "; throw StreamException(err); } - break; - case SCHEME_DATA: - data.push_back(ch); - break; - - }//switch return 1; } @@ -435,51 +219,6 @@ int UriOutputStream::put(char ch) -/** - * - */ -UriWriter::UriWriter(Inkscape::URI &uri) - -{ - outputStream = new UriOutputStream(uri); -} - -/** - * - */ -UriWriter::~UriWriter() -{ - delete outputStream; -} - -/** - * - */ -void UriWriter::close() -{ - outputStream->close(); -} - -/** - * - */ -void UriWriter::flush() -{ - outputStream->flush(); -} - -/** - * - */ -void UriWriter::put(char ch) -{ - outputStream->put(ch); -} - - - - - } // namespace IO } // namespace Inkscape @@ -487,3 +226,5 @@ void UriWriter::put(char ch) //######################################################################### //# E N D O F F I L E //######################################################################### + +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/io/uristream.h b/src/io/uristream.h index 4c6f0607c..bcd599012 100644 --- a/src/io/uristream.h +++ b/src/io/uristream.h @@ -29,22 +29,19 @@ namespace IO { //######################################################################### -//# U R I I N P U T S T R E A M / R E A D E R +//# F I L E I N P U T S T R E A M //######################################################################### /** - * This class is for receiving a stream of data from a resource - * defined in a URI + * This class is for receiving a stream of data from a file */ -class UriInputStream : public InputStream +class FileInputStream : public InputStream { public: - UriInputStream(FILE *source, Inkscape::URI &uri); + FileInputStream(FILE *source); - UriInputStream(Inkscape::URI &source); - - ~UriInputStream() override; + ~FileInputStream() override; int available() override; @@ -53,66 +50,28 @@ public: int get() override; private: - Inkscape::URI &uri; FILE *inf; //for file: uris - unsigned char *data; //for data: uris - int dataPos; // current read position in data field - int dataLen; // length of data buffer - bool closed; - int scheme; - - -}; // class UriInputStream - - - - -/** - * This class is for receiving a stream of formatted data from a resource - * defined in a URI - */ -class UriReader : public BasicReader -{ - -public: - UriReader(Inkscape::URI &source); +}; // class FileInputStream - ~UriReader() override; - - int available() override; - - void close() override; - - char get() override; - -private: - - UriInputStream *inputStream; - -}; // class UriReader //######################################################################### -//# U R I O U T P U T S T R E A M / W R I T E R +//# F I L E O U T P U T S T R E A M //######################################################################### /** - * This class is for sending a stream to a destination resource - * defined in a URI - * + * This class is for sending a stream to a destination file */ -class UriOutputStream : public OutputStream +class FileOutputStream : public OutputStream { public: - UriOutputStream(FILE *fp, Inkscape::URI &destination); - - UriOutputStream(Inkscape::URI &destination); + FileOutputStream(FILE *fp); - ~UriOutputStream() override; + ~FileOutputStream() override; void close() override; @@ -122,47 +81,11 @@ public: private: - bool closed; bool ownsFile; FILE *outf; //for file: uris - Glib::ustring data; //for data: uris - - Inkscape::URI &uri; - - int scheme; - -}; // class UriOutputStream - - - - - -/** - * This class is for sending a stream of formatted data to a resource - * defined in a URI - */ -class UriWriter : public BasicWriter -{ - -public: - - UriWriter(Inkscape::URI &source); - - ~UriWriter() override; - - void close() override; - - void flush() override; - - void put(char ch) override; - -private: - - UriOutputStream *outputStream; - -}; // class UriReader +}; // class FileOutputStream @@ -173,3 +96,5 @@ private: #endif // SEEN_INKSCAPE_IO_URISTREAM_H + +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/io/xsltstream.h b/src/io/xsltstream.h index da5068ce2..7ee3f9a9d 100644 --- a/src/io/xsltstream.h +++ b/src/io/xsltstream.h @@ -93,7 +93,7 @@ private: int outsize; int outpos; -}; // class UriInputStream +}; // class XsltInputStream @@ -128,7 +128,7 @@ private: bool flushed; -}; // class UriOutputStream +}; // class XsltOutputStream diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index 877083b81..35a2e3793 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -75,7 +75,6 @@ public: LoadEntities(false), cachedData(), cachedPos(0), - dummy("x"), instr(nullptr), gzin(nullptr) { @@ -112,8 +111,7 @@ private: bool LoadEntities; // Checks for SYSTEM Entities (requires cached data) std::string cachedData; unsigned int cachedPos; - Inkscape::URI dummy; - Inkscape::IO::UriInputStream* instr; + Inkscape::IO::FileInputStream* instr; Inkscape::IO::GzipInputStream* gzin; }; @@ -136,7 +134,7 @@ int XmlSource::setFile(char const *filename, bool load_entities=false) fclose(fp); fp = nullptr; fp = Inkscape::IO::fopen_utf8name(filename, "r"); - instr = new Inkscape::IO::UriInputStream(fp, dummy); + instr = new Inkscape::IO::FileInputStream(fp); gzin = new Inkscape::IO::GzipInputStream(*instr); memset( firstFew, 0, sizeof(firstFew) ); @@ -669,8 +667,7 @@ void sp_repr_save_stream(Document *doc, FILE *fp, gchar const *default_ns, bool gchar const *const old_href_abs_base, gchar const *const new_href_abs_base) { - Inkscape::URI dummy("x"); - Inkscape::IO::UriOutputStream bout(fp, dummy); + Inkscape::IO::FileOutputStream bout(fp); Inkscape::IO::GzipOutputStream *gout = compress ? new Inkscape::IO::GzipOutputStream(bout) : nullptr; Inkscape::IO::OutputStreamWriter *out = compress ? new Inkscape::IO::OutputStreamWriter( *gout ) : new Inkscape::IO::OutputStreamWriter( bout ); |
