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
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef MWAW_INPUT_STREAM_H
00035 #define MWAW_INPUT_STREAM_H
00036
00037 #include <string>
00038 #include <vector>
00039
00040 #include <librevenge/librevenge.h>
00041 #include <librevenge-stream/librevenge-stream.h>
00042 #include "libmwaw_internal.hxx"
00043
00053 class MWAWInputStream
00054 {
00055 public:
00060 MWAWInputStream(shared_ptr<librevenge::RVNGInputStream> input, bool inverted);
00061
00066 MWAWInputStream(librevenge::RVNGInputStream *input, bool inverted, bool checkCompression=false);
00068 ~MWAWInputStream();
00069
00071 shared_ptr<librevenge::RVNGInputStream> input()
00072 {
00073 return m_stream;
00074 }
00076 static shared_ptr<MWAWInputStream> get(librevenge::RVNGBinaryData const &data, bool inverted);
00077
00079 bool readInverted() const
00080 {
00081 return m_inverseRead;
00082 }
00084 void setReadInverted(bool newVal)
00085 {
00086 m_inverseRead = newVal;
00087 }
00088
00089
00090
00091
00096 int seek(long offset, librevenge::RVNG_SEEK_TYPE seekType);
00098 long tell();
00100 long size() const
00101 {
00102 return m_streamSize;
00103 }
00105 bool checkPosition(long pos) const
00106 {
00107 if (pos < 0) return false;
00108 if (m_readLimit > 0 && pos > m_readLimit) return false;
00109 return pos<=m_streamSize;
00110 }
00112 bool isEnd();
00113
00117 void pushLimit(long newLimit)
00118 {
00119 m_prevLimits.push_back(m_readLimit);
00120 m_readLimit = newLimit > m_streamSize ? m_streamSize : newLimit;
00121 }
00123 void popLimit()
00124 {
00125 if (m_prevLimits.size()) {
00126 m_readLimit = m_prevLimits.back();
00127 m_prevLimits.pop_back();
00128 }
00129 else m_readLimit = -1;
00130 }
00131
00132
00133
00134
00135
00137 unsigned long readULong(int num)
00138 {
00139 return readULong(m_stream.get(), num, 0, m_inverseRead);
00140 }
00142 long readLong(int num);
00144 bool readDouble8(double &res, bool &isNotANumber);
00146 bool readDoubleReverted8(double &res, bool &isNotANumber);
00148 bool readDouble10(double &res, bool &isNotANumber);
00149
00153 const uint8_t *read(size_t numBytes, unsigned long &numBytesRead);
00157 static unsigned long readULong(librevenge::RVNGInputStream *stream, int num, unsigned long a, bool inverseRead);
00158
00160 bool readDataBlock(long size, librevenge::RVNGBinaryData &data);
00162 bool readEndDataBlock(librevenge::RVNGBinaryData &data);
00163
00164
00165
00166
00167
00169 bool isStructured();
00171 unsigned subStreamCount();
00173 std::string subStreamName(unsigned id);
00174
00176 shared_ptr<MWAWInputStream> getSubStreamByName(std::string const &name);
00178 shared_ptr<MWAWInputStream> getSubStreamById(unsigned id);
00179
00180
00181
00182
00184 bool getFinderInfo(std::string &type, std::string &creator) const
00185 {
00186 if (!m_fInfoType.length() || !m_fInfoCreator.length()) {
00187 type = creator = "";
00188 return false;
00189 }
00190 type = m_fInfoType;
00191 creator = m_fInfoCreator;
00192 return true;
00193 }
00194
00195
00196
00197
00198
00200 bool hasDataFork() const
00201 {
00202 return bool(m_stream);
00203 }
00205 bool hasResourceFork() const
00206 {
00207 return bool(m_resourceFork);
00208 }
00210 shared_ptr<MWAWInputStream> getResourceForkStream()
00211 {
00212 return m_resourceFork;
00213 }
00214
00215
00216 protected:
00218 void updateStreamSize();
00220 static uint8_t readU8(librevenge::RVNGInputStream *stream);
00221
00223 bool unBinHex();
00225 bool unzipStream();
00227 bool unMacMIME();
00229 bool unMacMIME(MWAWInputStream *input,
00230 shared_ptr<librevenge::RVNGInputStream> &dataInput,
00231 shared_ptr<librevenge::RVNGInputStream> &rsrcInput) const;
00232
00233 private:
00234 MWAWInputStream(MWAWInputStream const &orig);
00235 MWAWInputStream &operator=(MWAWInputStream const &orig);
00236
00237 protected:
00239 shared_ptr<librevenge::RVNGInputStream> m_stream;
00241 long m_streamSize;
00242
00244 bool m_inverseRead;
00245
00247 long m_readLimit;
00249 std::vector<long> m_prevLimits;
00250
00252 mutable std::string m_fInfoType;
00254 mutable std::string m_fInfoCreator;
00256 shared_ptr<MWAWInputStream> m_resourceFork;
00257 };
00258
00259 #endif
00260