MWAWInputStream.hxx Source File documentation

MWAWInputStream.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33
34 #ifndef MWAW_INPUT_STREAM_H
35 #define MWAW_INPUT_STREAM_H
36
37 #include <string>
38 #include <vector>
39
40 #include <librevenge/librevenge.h>
41 #include <librevenge-stream/librevenge-stream.h>
42 #include "libmwaw_internal.hxx"
43
53 class MWAWInputStream
54 {
55 public:
60 MWAWInputStream(std::shared_ptr<librevenge::RVNGInputStream> input, bool inverted);
61
66 MWAWInputStream(librevenge::RVNGInputStream *input, bool inverted, bool checkCompression=false);
68 ~MWAWInputStream();
69
71 std::shared_ptr<librevenge::RVNGInputStream> input()
72 {
73 return m_stream;
74 }
76 static std::shared_ptr<MWAWInputStream> get(librevenge::RVNGBinaryData const &data, bool inverted);
77
79 bool readInverted() const
80 {
81 return m_inverseRead;
82 }
84 void setReadInverted(bool newVal)
85 {
86 m_inverseRead = newVal;
87 }
88 //
89 // Position: access
90 //
91
96 int seek(long offset, librevenge::RVNG_SEEK_TYPE seekType);
98 long tell();
100 long size() const
101 {
102 return m_streamSize;
103 }
105 bool checkPosition(long pos) const
106 {
107 if (pos < 0) return false;
108 if (m_readLimit > 0 && pos > m_readLimit) return false;
109 return pos<=m_streamSize;
110 }
112 bool isEnd();
113
117 void pushLimit(long newLimit)
118 {
119 m_prevLimits.push_back(m_readLimit);
120 m_readLimit = newLimit > m_streamSize ? m_streamSize : newLimit;
121 }
123 void popLimit()
124 {
125 if (!m_prevLimits.empty()) {
126 m_readLimit = m_prevLimits.back();
127 m_prevLimits.pop_back();
128 }
129 else m_readLimit = -1;
130 }
131
132 //
133 // get data
134 //
135
137 unsigned long readULong(int num)
138 {
139 return readULong(m_stream.get(), num, 0, m_inverseRead);
140 }
142 long readLong(int num);
144 bool readDouble8(double &res, bool &isNotANumber);
146 bool readDoubleReverted8(double &res, bool &isNotANumber);
148 bool readDouble10(double &res, bool &isNotANumber);
149
153 const uint8_t *read(size_t numBytes, unsigned long &numBytesRead);
157 static unsigned long readULong(librevenge::RVNGInputStream *stream, int num, unsigned long a, bool inverseRead);
158
160 bool readDataBlock(long size, librevenge::RVNGBinaryData &data);
162 bool readEndDataBlock(librevenge::RVNGBinaryData &data);
163
164 //
165 // OLE/Zip access
166 //
167
169 bool isStructured();
171 unsigned subStreamCount();
173 std::string subStreamName(unsigned id);
174
176 std::shared_ptr<MWAWInputStream> getSubStreamByName(std::string const &name);
178 std::shared_ptr<MWAWInputStream> getSubStreamById(unsigned id);
179
180 //
181 // Finder Info access
182 //
184 bool getFinderInfo(std::string &type, std::string &creator) const
185 {
186 if (!m_fInfoType.length() || !m_fInfoCreator.length()) {
187 type = creator = "";
188 return false;
189 }
190 type = m_fInfoType;
191 creator = m_fInfoCreator;
192 return true;
193 }
194
195 //
196 // Resource Fork access
197 //
198
200 bool hasDataFork() const
201 {
202 return bool(m_stream);
203 }
205 bool hasResourceFork() const
206 {
207 return bool(m_resourceFork);
208 }
210 std::shared_ptr<MWAWInputStream> getResourceForkStream()
211 {
212 return m_resourceFork;
213 }
214
215
216 protected:
218 void updateStreamSize();
220 static uint8_t readU8(librevenge::RVNGInputStream *stream);
221
223 bool unBinHex();
225 bool unzipStream();
227 bool unMacMIME();
229 bool unMacMIME(MWAWInputStream *input,
230 std::shared_ptr<librevenge::RVNGInputStream> &dataInput,
231 std::shared_ptr<librevenge::RVNGInputStream> &rsrcInput) const;
233 bool unsplitInternalMergeStream();
234
235 private:
236 MWAWInputStream(MWAWInputStream const &orig) = delete;
237 MWAWInputStream &operator=(MWAWInputStream const &orig) = delete;
238
239 protected:
241 std::shared_ptr<librevenge::RVNGInputStream> m_stream;
243 long m_streamSize;
244
246 long m_readLimit;
248 std::vector<long> m_prevLimits;
249
251 mutable std::string m_fInfoType;
253 mutable std::string m_fInfoCreator;
255 std::shared_ptr<MWAWInputStream> m_resourceFork;
257 bool m_inverseRead;
258 };
259
260 #endif
261 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWInputStream::MWAWInputStream
MWAWInputStream(std::shared_ptr< librevenge::RVNGInputStream > input, bool inverted)
creates a stream with given endian
Definition: MWAWInputStream.cxx:48
MWAWInputStream::unMacMIME
bool unMacMIME()
check if some stream are in MacMIME format, if so de MacMIME
Definition: MWAWInputStream.cxx:680
MWAWInputStream::tell
long tell()
returns actual offset position
Definition: MWAWInputStream.cxx:141
MWAWInputStream::subStreamName
std::string subStreamName(unsigned id)
returns the name of the i^th substream
Definition: MWAWInputStream.cxx:850
MWAWInputStream::readDoubleReverted8
bool readDoubleReverted8(double &res, bool &isNotANumber)
try to read a double of size 8: 6.5 bytes mantisse, 1.5 bytes exponent
Definition: MWAWInputStream.cxx:334
MWAWInputStream::readDouble10
bool readDouble10(double &res, bool &isNotANumber)
try to read a double of size 10: 2 bytes exponent, 8 bytes mantisse
Definition: MWAWInputStream.cxx:293
MWAWInputStream::seek
int seek(long offset, librevenge::RVNG_SEEK_TYPE seekType)
seeks to a offset position, from actual, beginning or ending position
Definition: MWAWInputStream.cxx:148
libmwaw_internal.hxx
MWAWInputStream::popLimit
void popLimit()
pops a section defined by pushLimit
Definition: MWAWInputStream.hxx:123
MWAWInputStream::unBinHex
bool unBinHex()
unbinhex the data in the file is a BinHex 4.0 file of a mac file
Definition: MWAWInputStream.cxx:384
MWAWInputStream::readDataBlock
bool readDataBlock(long size, librevenge::RVNGBinaryData &data)
reads a librevenge::RVNGBinaryData with a given size in the actual section/file
Definition: MWAWInputStream.cxx:910
MWAWInputStream::setReadInverted
void setReadInverted(bool newVal)
sets the endian mode
Definition: MWAWInputStream.hxx:84
MWAWInputStream::size
long size() const
returns the stream size
Definition: MWAWInputStream.hxx:100
MWAWInputStream::m_readLimit
long m_readLimit
actual section limit (-1 if no limit)
Definition: MWAWInputStream.hxx:246
MWAWInputStream::readDouble8
bool readDouble8(double &res, bool &isNotANumber)
try to read a double of size 8: 1.5 bytes exponent, 6.5 bytes mantisse
Definition: MWAWInputStream.cxx:251
MWAWInputStream::m_inverseRead
bool m_inverseRead
big or normal endian
Definition: MWAWInputStream.hxx:257
MWAWInputStream
Internal class used to read the file stream Internal class used to read the file stream, this class adds some usefull functions to the basic librevenge::RVNGInputStream:
Definition: MWAWInputStream.hxx:53
MWAWInputStream::m_fInfoCreator
std::string m_fInfoCreator
finder info type
Definition: MWAWInputStream.hxx:253
MWAWInputStream::m_resourceFork
std::shared_ptr< MWAWInputStream > m_resourceFork
the resource fork
Definition: MWAWInputStream.hxx:255
MWAWInputStream::getSubStreamById
std::shared_ptr< MWAWInputStream > getSubStreamById(unsigned id)
return a new stream for a ole zone
Definition: MWAWInputStream.cxx:884
MWAWInputStream::hasDataFork
bool hasDataFork() const
returns true if the data fork block exists
Definition: MWAWInputStream.hxx:200
MWAWInputStream::unzipStream
bool unzipStream()
unzip the data in the file is a zip file of a mac file
Definition: MWAWInputStream.cxx:635
MWAWInputStream::readInverted
bool readInverted() const
returns the endian mode (see constructor)
Definition: MWAWInputStream.hxx:79
MWAWInputStream::isEnd
bool isEnd()
returns true if we are at the end of the section/file
Definition: MWAWInputStream.cxx:171
MWAWInputStream::readLong
long readLong(int num)
return a int8, int16, int32 readed from actualPos
Definition: MWAWInputStream.cxx:223
MWAWInputStream::readU8
static uint8_t readU8(librevenge::RVNGInputStream *stream)
internal function used to read a byte
Definition: MWAWInputStream.cxx:238
MWAWInputStream::m_streamSize
long m_streamSize
the stream size
Definition: MWAWInputStream.hxx:243
MWAWInputStream::isStructured
bool isStructured()
return true if the stream is ole
Definition: MWAWInputStream.cxx:832
MWAWInputStream::m_prevLimits
std::vector< long > m_prevLimits
list of previous limits
Definition: MWAWInputStream.hxx:248
MWAWInputStream::readEndDataBlock
bool readEndDataBlock(librevenge::RVNGBinaryData &data)
reads a librevenge::RVNGBinaryData from actPos to the end of the section/file
Definition: MWAWInputStream.cxx:929
MWAWInputStream::getFinderInfo
bool getFinderInfo(std::string &type, std::string &creator) const
returns the finder info type and creator (if known)
Definition: MWAWInputStream.hxx:184
MWAWInputStream::getResourceForkStream
std::shared_ptr< MWAWInputStream > getResourceForkStream()
returns the resource fork if find
Definition: MWAWInputStream.hxx:210
MWAWInputStream::m_fInfoType
std::string m_fInfoType
finder info type
Definition: MWAWInputStream.hxx:251
MWAWInputStream::m_stream
std::shared_ptr< librevenge::RVNGInputStream > m_stream
the initial input
Definition: MWAWInputStream.hxx:241
MWAWInputStream::read
const uint8_t * read(size_t numBytes, unsigned long &numBytesRead)
! reads numbytes data, WITHOUT using any endian or section consideration
Definition: MWAWInputStream.cxx:134
MWAWInputStream::hasResourceFork
bool hasResourceFork() const
returns true if the resource fork block exists
Definition: MWAWInputStream.hxx:205
MWAWInputStream::pushLimit
void pushLimit(long newLimit)
defines a new section in the file (from actualPos to newLimit) next call of seek, tell...
Definition: MWAWInputStream.hxx:117
MWAWInputStream::unsplitInternalMergeStream
bool unsplitInternalMergeStream()
check if a stream is an internal merge stream
Definition: MWAWInputStream.cxx:567
MWAWInputStream::updateStreamSize
void updateStreamSize()
update the stream size ( must be called in the constructor )
Definition: MWAWInputStream.cxx:122
MWAWInputStream::getSubStreamByName
std::shared_ptr< MWAWInputStream > getSubStreamByName(std::string const &name)
return a new stream for a ole zone
Definition: MWAWInputStream.cxx:864
MWAWInputStream::subStreamCount
unsigned subStreamCount()
returns the number of substream
Definition: MWAWInputStream.cxx:841
MWAWInputStream::input
std::shared_ptr< librevenge::RVNGInputStream > input()
returns the basic librevenge::RVNGInputStream
Definition: MWAWInputStream.hxx:71
MWAWInputStream::checkPosition
bool checkPosition(long pos) const
checks if a position is or not a valid file position
Definition: MWAWInputStream.hxx:105
MWAWInputStream::~MWAWInputStream
~MWAWInputStream()
destructor
Definition: MWAWInputStream.cxx:98
MWAWInputStream::readULong
unsigned long readULong(int num)
returns a uint8, uint16, uint32 readed from actualPos
Definition: MWAWInputStream.hxx:137
MWAWInputStream::operator=
MWAWInputStream & operator=(MWAWInputStream const &orig)=delete