From: Fridrich S. <str...@us...> - 2006-06-21 12:06:11
|
Update of /cvsroot/libwpg/libwpg/src/lib In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv30939/src/lib Modified Files: WPGHeader.cpp WPGStreamImplementation.cpp WPGStreamImplementation.h Log Message: Add Memory stream implementation; make wpg2foo ole2 ready; modify some indents Index: WPGStreamImplementation.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGStreamImplementation.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- WPGStreamImplementation.cpp 18 Jun 2006 14:43:57 -0000 1.1 +++ WPGStreamImplementation.cpp 21 Jun 2006 12:06:00 -0000 1.2 @@ -26,6 +26,8 @@ #include "WPGStreamImplementation.h" #include <fstream> +#include <sstream> +#include <string> namespace libwpg { @@ -36,10 +38,22 @@ std::fstream file; }; +class WPGMemoryStreamPrivate +{ +public: + WPGMemoryStreamPrivate(const std::string str); + std::stringstream buffer; +}; + } // namespace libwpg using namespace libwpg; +WPGMemoryStreamPrivate::WPGMemoryStreamPrivate(const std::string str) : + buffer(str, std::ios::binary | std::ios::in) +{ +} + WPGFileStream::WPGFileStream(const char* filename) { @@ -87,3 +101,87 @@ { return d->file.eof(); } + +bool WPGFileStream::isOle() +{ +/* TODO: Here we should use basically pole to check whether + the d->file is an ole2 document and return true if + it is so +*/ + return false; +} + +WPGInputStream* WPGFileStream::getWPGOleStream() +{ +/* TODO: Here we should look for the "PerfectOffice_MAIN" stream + and constuct a new WPGMemoryStream from the data contained + and return pointer to that stream. If the stream is not present, + we should return null pointer +*/ + return 0; +} + + +WPGMemoryStream::WPGMemoryStream(const char *data, const unsigned int dataSize) +{ + d = new WPGMemoryStreamPrivate(std::string(data, dataSize)); +} + +WPGMemoryStream::~WPGMemoryStream() +{ + delete d; +} + +unsigned char WPGMemoryStream::getc() +{ + return d->buffer.get(); +} + +long WPGMemoryStream::read(long nbytes, char* buffer) +{ + long nread = 0; + + if(d->buffer.good()) + { + long curpos = d->buffer.tellg(); + d->buffer.read(buffer, nbytes); + nread = (long)d->buffer.tellg() - curpos; + } + + return nread; +} + +long WPGMemoryStream::tell() +{ + return d->buffer.good() ? (long)d->buffer.tellg() : -1L; +} + +void WPGMemoryStream::seek(long offset) +{ + if(d->buffer.good()) + d->buffer.seekg(offset); +} + +bool WPGMemoryStream::atEnd() +{ + return d->buffer.eof(); +} + +bool WPGMemoryStream::isOle() +{ +/* TODO: Here we should use basically pole to check whether + the d->buffer is an ole2 document and return true if + it is so +*/ + return false; +} + +WPGInputStream* WPGMemoryStream::getWPGOleStream() +{ +/* TODO: Here we should look for the "PerfectOffice_MAIN" stream + and constuct a new WPGMemoryStream from the data contained + and return pointer to that stream. If the stream is not present, + we should return null pointer +*/ + return 0; +} Index: WPGStreamImplementation.h =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGStreamImplementation.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- WPGStreamImplementation.h 18 Jun 2006 14:43:57 -0000 1.1 +++ WPGStreamImplementation.h 21 Jun 2006 12:06:00 -0000 1.2 @@ -45,8 +45,8 @@ virtual void seek(long offset); virtual bool atEnd(); - virtual bool isOle() { return false; }; - virtual WPGInputStream *getWPGOleStream() { return 0; }; + virtual bool isOle(); + virtual WPGInputStream *getWPGOleStream(); private: WPGFileStreamPrivate* d; @@ -54,6 +54,29 @@ WPGFileStream& operator=(const WPGFileStream&); // assignment is not allowed }; +class WPGMemoryStreamPrivate; + +class WPGMemoryStream: public WPGInputStream +{ +public: + WPGMemoryStream(const char *data, const unsigned int dataSize); + ~WPGMemoryStream(); + + virtual unsigned char getc(); + virtual long read(long n, char* buffer); + virtual long tell(); + virtual void seek(long offset); + virtual bool atEnd(); + + virtual bool isOle(); + virtual WPGInputStream *getWPGOleStream(); + +private: + WPGMemoryStreamPrivate* d; + WPGMemoryStream(const WPGMemoryStream&); // copy is not allowed + WPGMemoryStream& operator=(const WPGMemoryStream&); // assignment is not allowed +}; + } // namespace wpg #endif // __WPGSTREAMIMPLEMENTATION_H__ Index: WPGHeader.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGHeader.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- WPGHeader.cpp 17 Jun 2006 08:11:53 -0000 1.1 +++ WPGHeader.cpp 21 Jun 2006 12:06:00 -0000 1.2 @@ -87,7 +87,7 @@ m_startOfPacketData = readU16(prefix+14); WPG_DEBUG_MSG(("Header Identifier = %c%c%c\n", m_identifier[1], - m_identifier[2],m_identifier[3])); + m_identifier[2], m_identifier[3])); WPG_DEBUG_MSG(("Product type = 0x%x\n", m_productType)); WPG_DEBUG_MSG(("File type = 0x%x\n", m_fileType)); WPG_DEBUG_MSG(("Major version = 0x%x\n", m_majorVersion)); |