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 <libwpd-stream/libwpd-stream.h>
41 #include "libmwaw_internal.hxx"
42 
43 namespace libmwawOLE
44 {
45 class Storage;
46 }
47 
48 class WPXBinaryData;
49 
60 {
61 public:
66  MWAWInputStream(shared_ptr<WPXInputStream> inp, bool inverted);
67 
72  MWAWInputStream(WPXInputStream *input, bool inverted, bool checkCompression=false);
75 
77  shared_ptr<WPXInputStream> input() {
78  return m_stream;
79  }
81  bool readInverted() const {
82  return m_inverseRead;
83  }
85  void setReadInverted(bool newVal) {
86  m_inverseRead = newVal;
87  }
88  //
89  // Position: access
90  //
91 
96  int seek(long offset, WPX_SEEK_TYPE seekType);
98  long tell();
100  bool atEOS();
101 
105  void pushLimit(long newLimit) {
106  m_prevLimits.push_back(m_readLimit);
107  m_readLimit = newLimit;
108  }
110  void popLimit() {
111  if (m_prevLimits.size()) {
112  m_readLimit = m_prevLimits.back();
113  m_prevLimits.pop_back();
114  } else m_readLimit = -1;
115  }
116 
117  //
118  // get data
119  //
120 
122  unsigned long readULong(int num) {
123  return readULong(m_stream.get(), num, 0, m_inverseRead);
124  }
126  long readLong(int num);
127 
131  const uint8_t *read(size_t numBytes, unsigned long &numBytesRead);
135  static unsigned long readULong(WPXInputStream *stream, int num, unsigned long a, bool inverseRead);
136 
138  bool readDataBlock(long size, WPXBinaryData &data);
140  bool readEndDataBlock(WPXBinaryData &data);
141 
142  //
143  // OLE access
144  //
145 
147  bool isOLEStream();
149  std::vector<std::string> getOLENames();
151  shared_ptr<MWAWInputStream> getDocumentOLEStream(std::string name);
152 
153  //
154  // Finder Info access
155  //
157  bool getFinderInfo(std::string &type, std::string &creator) const {
158  if (!m_fInfoType.length() || !m_fInfoCreator.length()) {
159  type = creator = "";
160  return false;
161  }
162  type = m_fInfoType;
163  creator = m_fInfoCreator;
164  return true;
165  }
166 
167  //
168  // Resource Fork access
169  //
170 
172  bool hasDataFork() const {
173  return bool(m_stream);
174  }
176  bool hasResourceFork() const {
177  return bool(m_resourceFork);
178  }
180  shared_ptr<MWAWInputStream> getResourceForkStream() {
181  return m_resourceFork;
182  }
183 
184 
185 protected:
187  static uint8_t readU8(WPXInputStream *stream);
188 
190  bool createStorageOLE();
191 
193  bool unBinHex();
195  bool unzipStream();
197  bool unMacMIME();
199  bool unMacMIME(MWAWInputStream *input,
200  shared_ptr<WPXInputStream> &dataInput,
201  shared_ptr<WPXInputStream> &rsrcInput) const;
202 
203 private:
204  MWAWInputStream(MWAWInputStream const &orig);
206 
207 protected:
209  shared_ptr<WPXInputStream> m_stream;
212 
216  std::vector<long> m_prevLimits;
217 
219  mutable std::string m_fInfoType;
221  mutable std::string m_fInfoCreator;
223  shared_ptr<MWAWInputStream> m_resourceFork;
225  shared_ptr<libmwawOLE::Storage> m_storageOLE;
226 };
227 
229 typedef shared_ptr<MWAWInputStream> MWAWInputStreamPtr;
230 
232 class MWAWStringStream: public WPXInputStream
233 {
234 public:
235  MWAWStringStream(const unsigned char *data, const unsigned long dataSize);
237 
238  const unsigned char *read(unsigned long numBytes, unsigned long &numBytesRead);
239  long tell() {
240  return m_offset;
241  }
242  int seek(long offset, WPX_SEEK_TYPE seekType);
243  bool atEOS() {
244  return ((long)m_offset >= (long)m_buffer.size());
245  }
246 
247  bool isOLEStream() {
248  return false;
249  }
250  WPXInputStream *getDocumentOLEStream(const char *) {
251  return 0;
252  };
253 
254 private:
255  std::vector<unsigned char> m_buffer;
256  volatile long m_offset;
259 };
260 
261 #endif
262 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Tue Apr 30 2013 06:16:19 for libmwaw by doxygen 1.8.3.1