diff options
| author | Kris De Gussem <kris.degussem@gmail.com> | 2013-02-11 18:32:33 +0000 |
|---|---|---|
| committer | Kris <Kris.De.Gussem@hotmail.com> | 2013-02-11 18:32:33 +0000 |
| commit | 5723519be38287501aa4dd273a7ff907128b3407 (patch) | |
| tree | 1a3f0d69b9c826c9c6febb254e36e6377cdae680 /src | |
| parent | cppcheck (diff) | |
| download | inkscape-5723519be38287501aa4dd273a7ff907128b3407.tar.gz inkscape-5723519be38287501aa4dd273a7ff907128b3407.zip | |
Dropped duplicate code for dom/io and io/ (Bug #1120585 )
(bzr r12118)
Diffstat (limited to 'src')
| -rw-r--r-- | src/dom/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/dom/Makefile_insert | 6 | ||||
| -rw-r--r-- | src/dom/io/base64stream.cpp | 341 | ||||
| -rw-r--r-- | src/dom/io/base64stream.h | 148 | ||||
| -rw-r--r-- | src/dom/io/gzipstream.cpp | 245 | ||||
| -rw-r--r-- | src/dom/io/gzipstream.h | 126 | ||||
| -rw-r--r-- | src/io/base64stream.cpp | 23 | ||||
| -rw-r--r-- | src/io/gzipstream.cpp | 17 |
8 files changed, 35 insertions, 875 deletions
diff --git a/src/dom/CMakeLists.txt b/src/dom/CMakeLists.txt index 15b4ba74d..5d761e649 100644 --- a/src/dom/CMakeLists.txt +++ b/src/dom/CMakeLists.txt @@ -19,10 +19,8 @@ set(dom_SRC xpathparser.cpp xpathtoken.cpp - io/base64stream.cpp io/bufferstream.cpp io/domstream.cpp - io/gzipstream.cpp io/stringstream.cpp io/uristream.cpp @@ -61,10 +59,8 @@ set(dom_SRC xpathparser.h xpathtoken.h - io/base64stream.h io/bufferstream.h io/domstream.h - io/gzipstream.h io/stringstream.h io/uristream.h diff --git a/src/dom/Makefile_insert b/src/dom/Makefile_insert index 17bab94ac..91c91eeac 100644 --- a/src/dom/Makefile_insert +++ b/src/dom/Makefile_insert @@ -50,16 +50,10 @@ dom_libdom_a_SOURCES = \ dom/xpathparser.h \ dom/xpathtoken.h \ dom/xpathtoken.cpp \ - dom/io/base64stream.cpp \ - dom/io/base64stream.h \ dom/io/bufferstream.cpp \ dom/io/bufferstream.h \ dom/io/domstream.cpp \ dom/io/domstream.h \ - dom/io/gzipstream.cpp \ - dom/io/gzipstream.h \ - dom/io/gzipstream.cpp \ - dom/io/gzipstream.h \ dom/io/stringstream.cpp \ dom/io/stringstream.h \ dom/io/uristream.cpp \ diff --git a/src/dom/io/base64stream.cpp b/src/dom/io/base64stream.cpp deleted file mode 100644 index 433675e18..000000000 --- a/src/dom/io/base64stream.cpp +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Phoebe DOM Implementation. - * - * Base64-enabled input and output streams - * - * This class allows easy encoding and decoding - * of Base64 data with a stream interface, hiding - * the implementation from the user. - * - * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2006 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - - -#include "base64stream.h" - - -namespace org -{ -namespace w3c -{ -namespace dom -{ -namespace io -{ - - -//######################################################################### -//# B A S E 6 4 I N P U T S T R E A M -//######################################################################### - -static int base64decode[] = -{ -/*00*/ -1, -1, -1, -1, -1, -1, -1, -1, -/*08*/ -1, -1, -1, -1, -1, -1, -1, -1, -/*10*/ -1, -1, -1, -1, -1, -1, -1, -1, -/*18*/ -1, -1, -1, -1, -1, -1, -1, -1, -/*20*/ -1, -1, -1, -1, -1, -1, -1, -1, -/*28*/ -1, -1, -1, 62, -1, -1, -1, 63, -/*30*/ 52, 53, 54, 55, 56, 57, 58, 59, -/*38*/ 60, 61, -1, -1, -1, -1, -1, -1, -/*40*/ -1, 0, 1, 2, 3, 4, 5, 6, -/*48*/ 7, 8, 9, 10, 11, 12, 13, 14, -/*50*/ 15, 16, 17, 18, 19, 20, 21, 22, -/*58*/ 23, 24, 25, -1, -1, -1, -1, -1, -/*60*/ -1, 26, 27, 28, 29, 30, 31, 32, -/*68*/ 33, 34, 35, 36, 37, 38, 39, 40, -/*70*/ 41, 42, 43, 44, 45, 46, 47, 48, -/*78*/ 49, 50, 51, -1, -1, -1, -1, -1 -}; - - -/** - * - */ -Base64InputStream::Base64InputStream(InputStream &sourceStream) - : BasicInputStream(sourceStream) -{ - outCount = 0; - padCount = 0; - closed = false; - done = false; -} - -/** - * - */ -Base64InputStream::~Base64InputStream() -{ - close(); -} - -/** - * Returns the number of bytes that can be read (or skipped over) from - * this input stream without blocking by the next caller of a method for - * this input stream. - */ -int Base64InputStream::available() -{ - if (closed ) - return 0; - int len = source.available() * 2 / 3; - return len; -} - - -/** - * Closes this input stream and releases any system resources - * associated with the stream. - */ -void Base64InputStream::close() -{ - if (closed) - return; - source.close(); - closed = true; -} - -/** - * Reads the next byte of data from the input stream. -1 if EOF - */ -int Base64InputStream::get() -{ - if (closed) - return -1; - - if (outCount - padCount > 0) - { - return outBytes[3-(outCount--)]; - } - - if (done) - return -1; - - int inBytes[4]; - int inCount = 0; - while (inCount < 4) - { - int ch = source.get(); - if (ch < 0) - { - while (inCount < 4) //pad if needed - { - inBytes[inCount++] = 0; - padCount++; - } - done = true; - break; - } - if (isspace(ch)) //ascii whitespace - { - //nothing - } - else if (ch == '=') //padding - { - inBytes[inCount++] = 0; - padCount++; - } - else - { - int byteVal = base64decode[ch & 0x7f]; - //printf("char:%c %d\n", ch, byteVal); - if (byteVal < 0) - { - //Bad lookup value - } - inBytes[inCount++] = byteVal; - } - } - - outBytes[0] = ((inBytes[0]<<2) & 0xfc) | ((inBytes[1]>>4) & 0x03); - outBytes[1] = ((inBytes[1]<<4) & 0xf0) | ((inBytes[2]>>2) & 0x0f); - outBytes[2] = ((inBytes[2]<<6) & 0xc0) | ((inBytes[3] ) & 0x3f); - - outCount = 3; - - //try again - if (outCount - padCount > 0) - { - return outBytes[3-(outCount--)]; - } - - return -1; - -} - - -//######################################################################### -//# B A S E 6 4 O U T P U T S T R E A M -//######################################################################### - -static char const *base64encode = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -/** - * - */ -Base64OutputStream::Base64OutputStream(OutputStream &destinationStream) - : BasicOutputStream(destinationStream) -{ - column = 0; - columnWidth = 72; - outBuf = 0L; - bitCount = 0; -} - -/** - * - */ -Base64OutputStream::~Base64OutputStream() -{ - close(); -} - -/** - * Closes this output stream and releases any system resources - * associated with this stream. - */ -void Base64OutputStream::close() -{ - if (closed) - return; - - //get any last bytes (1 or 2) out of the buffer - if (bitCount == 16) - { - outBuf <<= 2; //pad to make 18 bits - - int indx = (int)((outBuf & 0x0003f000L) >> 12); - int obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - indx = (int)((outBuf & 0x00000fc0L) >> 6); - obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - indx = (int)((outBuf & 0x0000003fL) ); - obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - putCh('='); - } - else if (bitCount == 8) - { - outBuf <<= 4; //pad to make 12 bits - - int indx = (int)((outBuf & 0x00000fc0L) >> 6); - int obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - indx = (int)((outBuf & 0x0000003fL) ); - obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - putCh('='); - putCh('='); - } - - if (columnWidth > 0) //if <=0, no newlines - destination.put('\n'); - - destination.close(); - closed = true; -} - -/** - * Flushes this output stream and forces any buffered output - * bytes to be written out. - */ -void Base64OutputStream::flush() -{ - if (closed) - return; - //dont flush here. do it on close() - destination.flush(); -} - -/** - * Private. Put a char to the output stream, checking for line length - */ -void Base64OutputStream::putCh(int ch) -{ - destination.put(ch); - column++; - if (columnWidth > 0 && column >= columnWidth) - { - destination.put('\n'); - column = 0; - } -} - - -/** - * Writes the specified byte to this output stream. - */ -int Base64OutputStream::put(XMLCh ch) -{ - if (closed) - { - //probably throw an exception here - return -1; - } - - outBuf <<= 8; - outBuf |= (ch & 0xff); - bitCount += 8; - if (bitCount >= 24) - { - int indx = (int)((outBuf & 0x00fc0000L) >> 18); - int obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - indx = (int)((outBuf & 0x0003f000L) >> 12); - obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - indx = (int)((outBuf & 0x00000fc0L) >> 6); - obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - indx = (int)((outBuf & 0x0000003fL) ); - obyte = (int)base64encode[indx & 63]; - putCh(obyte); - - bitCount = 0; - outBuf = 0L; - } - - return 1; -} - - - -} //namespace io -} //namespace dom -} //namespace w3c -} //namespace org - - -//######################################################################### -//# E N D O F F I L E -//######################################################################### diff --git a/src/dom/io/base64stream.h b/src/dom/io/base64stream.h deleted file mode 100644 index 93bb5c7e5..000000000 --- a/src/dom/io/base64stream.h +++ /dev/null @@ -1,148 +0,0 @@ -#ifndef SEEN_DOM_IO_BASE64STREAM_H -#define SEEN_DOM_IO_BASE64STREAM_H - -/** - * @file - * Phoebe DOM Implementation. - * - * Base64-enabled input and output streams - * - * This class allows easy encoding and decoding - * of Base64 data with a stream interface, hiding - * the implementation from the user. - * - * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html - */ -/* - * Authors: - * Bob Jamison - * - * Copyright (C) 2006 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - - -#include "domstream.h" - - -namespace org -{ -namespace w3c -{ -namespace dom -{ -namespace io -{ - - - -//######################################################################### -//# B A S E 6 4 I N P U T S T R E A M -//######################################################################### - -/** - * This class is for decoding a Base-64 encoded InputStream source - * - */ -class Base64InputStream : public BasicInputStream -{ - -public: - - Base64InputStream(InputStream &sourceStream); - - virtual ~Base64InputStream(); - - virtual int available(); - - virtual void close(); - - virtual int get(); - -private: - - int outBytes[3]; - - int outCount; - - int padCount; - - bool done; - -}; // class Base64InputStream - - - - -//######################################################################### -//# B A S E 6 4 O U T P U T S T R E A M -//######################################################################### - -/** - * This class is for Base-64 encoding data going to the - * destination OutputStream - * - */ -class Base64OutputStream : public BasicOutputStream -{ - -public: - - Base64OutputStream(OutputStream &destinationStream); - - virtual ~Base64OutputStream(); - - virtual void close(); - - virtual void flush(); - - virtual int put(XMLCh ch); - - /** - * Sets the maximum line length for base64 output. If - * set to <=0, then there will be no line breaks; - */ - virtual void setColumnWidth(int val) - { columnWidth = val; } - -private: - - void putCh(int ch); - - int column; - - int columnWidth; - - unsigned long outBuf; - - int bitCount; - -}; // class Base64OutputStream - - - - - - - -} //namespace io -} //namespace dom -} //namespace w3c -} //namespace org - - -#endif // SEEN_DOM_IO_BASE64STREAM_H diff --git a/src/dom/io/gzipstream.cpp b/src/dom/io/gzipstream.cpp deleted file mode 100644 index 2a2f8a5b5..000000000 --- a/src/dom/io/gzipstream.cpp +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Zlib-enabled input and output streams - * - * This is a thin wrapper of libz calls, in order - * to provide a simple interface to our developers - * for gzip input and output. - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2006-2007 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - - -#include "gzipstream.h" - -#include "dom/util/ziptool.h" - - -namespace org -{ -namespace w3c -{ -namespace dom -{ -namespace io -{ - - -//######################################################################### -//# G Z I P I N P U T S T R E A M -//######################################################################### - -/** - * - */ -GzipInputStream::GzipInputStream(InputStream &sourceStream) - : BasicInputStream(sourceStream) -{ - loaded = false; - bufPos = 0; -} - -/** - * - */ -GzipInputStream::~GzipInputStream() -{ - close(); -} - -/** - * Returns the number of bytes that can be read (or skipped over) from - * this input stream without blocking by the next caller of a method for - * this input stream. - */ -int GzipInputStream::available() -{ - if (closed) - return 0; - if (!loaded) - if (!load()) - return 0; - return (int) buffer.size(); -} - - -/** - * Closes this input stream and releases any system resources - * associated with the stream. - */ -void GzipInputStream::close() -{ - if (closed) - return; - - closed = true; -} - -/** - * Reads the next byte of data from the input stream. -1 if EOF - */ -int GzipInputStream::get() -{ - if (closed) - return -1; - - if (!loaded) - if (!load()) - return -1; - - if (bufPos >= buffer.size()) - return -1; - int ch = (int) buffer[bufPos++]; - - return ch; -} - -/** - * Processes input. Fills read buffer. - */ -bool GzipInputStream::load() -{ - if (closed) - return false; - - if (loaded) - return true; - - std::vector<unsigned char> compBuf; - while (true) - { - int ch = source.get(); - if (ch < 0) - break; - compBuf.push_back(ch); - } - GzipFile gz; - if (!gz.readBuffer(compBuf)) - { - return -1; - } - buffer = gz.getData(); - bufPos = 0; - loaded = true; - return true; -} - - - - - - -//######################################################################### -//# G Z I P O U T P U T S T R E A M -//######################################################################### - -/** - * - */ -GzipOutputStream::GzipOutputStream(OutputStream &destinationStream) - : BasicOutputStream(destinationStream) -{ - - closed = false; -} - -/** - * - */ -GzipOutputStream::~GzipOutputStream() -{ - close(); -} - -/** - * Closes this output stream and releases any system resources - * associated with this stream. - */ -void GzipOutputStream::close() -{ - if (closed) - return; - - flush(); - - closed = true; -} - -/** - * Flushes this output stream and forces any buffered output - * bytes to be written out. - */ -void GzipOutputStream::flush() -{ - if (closed || buffer.empty()) - return; - - std::vector<unsigned char> compBuf; - GzipFile gz; - - gz.writeBuffer(buffer); - - std::vector<unsigned char>::iterator iter; - for (iter=compBuf.begin() ; iter!=compBuf.end() ; ++iter) - { - int ch = (int) *iter; - destination.put(ch); - } - - buffer.clear(); - - //printf("done\n"); - -} - - - -/** - * Writes the specified byte to this output stream. - */ -int GzipOutputStream::put(XMLCh ch) -{ - if (closed) - { - //probably throw an exception here - return -1; - } - - //Add char to buffer - buffer.push_back(ch); - return 1; -} - - - -} // namespace io -} // namespace dom -} // namespace w3c -} // namespace org - - - - -//######################################################################### -//# E N D O F F I L E -//######################################################################### - - - diff --git a/src/dom/io/gzipstream.h b/src/dom/io/gzipstream.h deleted file mode 100644 index 6e82c3531..000000000 --- a/src/dom/io/gzipstream.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef SEEN_GZIPSTREAM_H -#define SEEN_GZIPSTREAM_H -/** - * Zlib-enabled input and output streams - * - * This provides a simple mechanism for reading and - * writing Gzip files. We use our own 'ZipTool' class - * to accomplish this, avoiding a zlib dependency. - */ -/* - * Authors: - * Bob Jamison - * - * Copyright (C) 2006-2007 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - - - -#include "domstream.h" - -namespace org -{ -namespace w3c -{ -namespace dom -{ -namespace io -{ - -//######################################################################### -//# G Z I P I N P U T S T R E A M -//######################################################################### - -/** - * This class is for deflating a gzip-compressed InputStream source - * - */ -class GzipInputStream : public BasicInputStream -{ - -public: - - GzipInputStream(InputStream &sourceStream); - - virtual ~GzipInputStream(); - - virtual int available(); - - virtual void close(); - - virtual int get(); - -private: - - bool load(); - - bool loaded; - - std::vector<unsigned char> buffer; - unsigned int bufPos; - - -}; // class GzipInputStream - - - - -//######################################################################### -//# G Z I P O U T P U T S T R E A M -//######################################################################### - -/** - * This class is for gzip-compressing data going to the - * destination OutputStream - * - */ -class GzipOutputStream : public BasicOutputStream -{ - -public: - - GzipOutputStream(OutputStream &destinationStream); - - virtual ~GzipOutputStream(); - - virtual void close(); - - virtual void flush(); - - virtual int put(XMLCh ch); - -private: - - std::vector<unsigned char> buffer; - - -}; // class GzipOutputStream - - - - - - - -} // namespace io -} // namespace dom -} // namespace w3c -} // namespace org - - -#endif // SEEN_GZIPSTREAM_H diff --git a/src/io/base64stream.cpp b/src/io/base64stream.cpp index 0a28a8cc3..667487c35 100644 --- a/src/io/base64stream.cpp +++ b/src/io/base64stream.cpp @@ -5,18 +5,35 @@ * of Base64 data with a stream interface, hiding * the implementation from the user. * + * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html + * * Authors: - * Bob Jamison <rjamison@titan.com> + + * Bob Jamison + * + * Copyright (C) 2006 Bob Jamison * - * Copyright (C) 2004 Inkscape.org + + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * Released under GNU GPL, read the file 'COPYING' for more information + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "base64stream.h" + namespace Inkscape { namespace IO diff --git a/src/io/gzipstream.cpp b/src/io/gzipstream.cpp index cbe29a41e..91b51140b 100644 --- a/src/io/gzipstream.cpp +++ b/src/io/gzipstream.cpp @@ -8,9 +8,22 @@ * Authors: * Bob Jamison <rjamison@titan.com> * - * Copyright (C) 2004 Inkscape.org + * Copyright (C) 2004 * - * Released under GNU GPL, read the file 'COPYING' for more information + + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "gzipstream.h" |
