STOFFInputStream.hxx Source File documentation

STOFFInputStream.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 /* libstaroffice
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 STOFF_INPUT_STREAM_H
35 #define STOFF_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 "libstaroffice_internal.hxx"
43
53 class STOFFInputStream
54 {
55 public:
60 STOFFInputStream(std::shared_ptr<librevenge::RVNGInputStream> input, bool inverted);
61
66 STOFFInputStream(librevenge::RVNGInputStream *input, bool inverted);
68 ~STOFFInputStream();
69
71 std::shared_ptr<librevenge::RVNGInputStream> input()
72 {
73 return m_stream;
74 }
76 static std::shared_ptr<STOFFInputStream> 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
95 int seek(long offset, librevenge::RVNG_SEEK_TYPE seekType);
97 long tell();
99 long size() const
100 {
101 return m_streamSize;
102 }
104 bool checkPosition(long pos) const
105 {
106 if (pos < 0) return false;
107 return pos<=m_streamSize;
108 }
110 bool isEnd();
111
112 //
113 // get data
114 //
115
117 int peek();
119 STOFFInputStream &operator>>(bool &res)
120 {
121 res=readULong(1)!=0 ? true : false;
122 return *this;
123 }
125 STOFFInputStream &operator>>(uint8_t &res)
126 {
127 res=static_cast<uint8_t>(readULong(1));
128 return *this;
129 }
131 STOFFInputStream &operator>>(int8_t &res)
132 {
133 res=static_cast<int8_t>(readLong(1));
134 return *this;
135 }
137 STOFFInputStream &operator>>(uint16_t &res)
138 {
139 res=static_cast<uint16_t>(readULong(2));
140 return *this;
141 }
143 STOFFInputStream &operator>>(int16_t &res)
144 {
145 res=static_cast<int16_t>(readLong(2));
146 return *this;
147 }
149 STOFFInputStream &operator>>(uint32_t &res)
150 {
151 res=static_cast<uint32_t>(readULong(4));
152 return *this;
153 }
155 STOFFInputStream &operator>>(int32_t &res)
156 {
157 res=static_cast<int32_t>(readLong(4));
158 return *this;
159 }
161 STOFFInputStream &operator>>(double &res)
162 {
163 bool isNan;
164 long pos=tell();
165 if (!readDoubleReverted8(res, isNan)) {
166 STOFF_DEBUG_MSG(("STOFFInputStream::operator>>: can not read a double\n"));
167 seek(pos+8, librevenge::RVNG_SEEK_SET);
168 res=0;
169 }
170 return *this;
171 }
173 unsigned long readULong(int num)
174 {
175 return readULong(m_stream.get(), num, 0, m_inverseRead);
176 }
178 long readLong(int num);
180 bool readColor(STOFFColor &color);
182 bool readCompressedLong(long &res);
184 bool readCompressedULong(unsigned long &res);
186 bool readDouble8(double &res, bool &isNotANumber);
188 bool readDoubleReverted8(double &res, bool &isNotANumber);
190 bool readDouble10(double &res, bool &isNotANumber);
194 const uint8_t *read(size_t numBytes, unsigned long &numBytesRead);
198 static unsigned long readULong(librevenge::RVNGInputStream *stream, int num, unsigned long a, bool inverseRead);
199
201 bool readDataBlock(long size, librevenge::RVNGBinaryData &data);
203 bool readEndDataBlock(librevenge::RVNGBinaryData &data);
204
205 //
206 // OLE/Zip access
207 //
208
210 bool isStructured();
212 unsigned subStreamCount();
214 std::string subStreamName(unsigned id);
215
217 std::shared_ptr<STOFFInputStream> getSubStreamByName(std::string const &name);
219 std::shared_ptr<STOFFInputStream> getSubStreamById(unsigned id);
220
221 //
222 // Resource Fork access
223 //
224
226 bool hasDataFork() const
227 {
228 return bool(m_stream);
229 }
230
231 protected:
233 void updateStreamSize();
235 static uint8_t readU8(librevenge::RVNGInputStream *stream);
236
237 private:
238 STOFFInputStream(STOFFInputStream const &orig);
239 STOFFInputStream &operator=(STOFFInputStream const &orig);
240
241 protected:
243 std::shared_ptr<librevenge::RVNGInputStream> m_stream;
245 long m_streamSize;
246
248 bool m_inverseRead;
249 };
250
251 #endif
252 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
STOFFInputStream::get
static std::shared_ptr< STOFFInputStream > get(librevenge::RVNGBinaryData const &data, bool inverted)
returns a new input stream corresponding to a librevenge::RVNGBinaryData
Definition: STOFFInputStream.cxx:72
STOFFInputStream::m_streamSize
long m_streamSize
the stream size
Definition: STOFFInputStream.hxx:245
STOFFInputStream::getSubStreamById
std::shared_ptr< STOFFInputStream > getSubStreamById(unsigned id)
return a new stream for a ole zone
Definition: STOFFInputStream.cxx:546
STOFFInputStream::readLong
long readLong(int num)
return a int8, int16, int32 readed from actualPos
Definition: STOFFInputStream.cxx:183
STOFFInputStream::readDouble10
bool readDouble10(double &res, bool &isNotANumber)
try to read a double of size 10: 2 bytes exponent, 8 bytes mantisse
Definition: STOFFInputStream.cxx:404
libstoff::FileException
Definition: libstaroffice_internal.hxx:139
STOFFInputStream::operator>>
STOFFInputStream & operator>>(uint8_t &res)
operator>> for uint8_t
Definition: STOFFInputStream.hxx:125
STOFF_DEBUG_MSG
#define STOFF_DEBUG_MSG(M)
Definition: libstaroffice_internal.hxx:129
STOFFInputStream::subStreamCount
unsigned subStreamCount()
returns the number of substream
Definition: STOFFInputStream.cxx:503
STOFFInputStream::readULong
unsigned long readULong(int num)
returns a uint8, uint16, uint32 readed from actualPos
Definition: STOFFInputStream.hxx:173
STOFFInputStream::operator>>
STOFFInputStream & operator>>(uint16_t &res)
operator>> for uint16_t
Definition: STOFFInputStream.hxx:137
STOFFInputStream::read
const uint8_t * read(size_t numBytes, unsigned long &numBytesRead)
! reads numbytes data, WITHOUT using any endian or section consideration
Definition: STOFFInputStream.cxx:104
STOFFInputStream::operator>>
STOFFInputStream & operator>>(int32_t &res)
operator>> for int32_t
Definition: STOFFInputStream.hxx:155
STOFFInputStream::isStructured
bool isStructured()
return true if the stream is ole
Definition: STOFFInputStream.cxx:494
STOFFColor
the class to store a color
Definition: libstaroffice_internal.hxx:189
STOFFInputStream::~STOFFInputStream
~STOFFInputStream()
destructor
Definition: STOFFInputStream.cxx:68
STOFFInputStream::readCompressedLong
bool readCompressedLong(long &res)
read a compressed long (pstm.cxx:ReadCompressed)
Definition: STOFFInputStream.cxx:322
STOFFInputStream::operator>>
STOFFInputStream & operator>>(double &res)
operator>> for double
Definition: STOFFInputStream.hxx:161
STOFFInputStream::operator>>
STOFFInputStream & operator>>(int16_t &res)
operator>> for int16_t
Definition: STOFFInputStream.hxx:143
libstaroffice_internal.hxx
STOFFInputStream::readDouble8
bool readDouble8(double &res, bool &isNotANumber)
try to read a double of size 8: 1.5 bytes exponent, 6.5 bytes mantisse
Definition: STOFFInputStream.cxx:363
STOFFInputStream::readColor
bool readColor(STOFFColor &color)
try to read a color
Definition: STOFFInputStream.cxx:222
STOFFInputStream::tell
long tell()
returns actual offset position
Definition: STOFFInputStream.cxx:111
STOFFInputStream::setReadInverted
void setReadInverted(bool newVal)
sets the endian mode
Definition: STOFFInputStream.hxx:84
STOFFInputStream::readDoubleReverted8
bool readDoubleReverted8(double &res, bool &isNotANumber)
try to read a double of size 8: 6.5 bytes mantisse, 1.5 bytes exponent
Definition: STOFFInputStream.cxx:444
STOFFInputStream::operator>>
STOFFInputStream & operator>>(bool &res)
operator>> for bool
Definition: STOFFInputStream.hxx:119
STOFFInputStream::readU8
static uint8_t readU8(librevenge::RVNGInputStream *stream)
internal function used to read a byte
Definition: STOFFInputStream.cxx:201
STOFFInputStream::m_stream
std::shared_ptr< librevenge::RVNGInputStream > m_stream
the initial input
Definition: STOFFInputStream.hxx:243
STOFFInputStream::hasDataFork
bool hasDataFork() const
returns true if the data fork block exists
Definition: STOFFInputStream.hxx:226
STOFFInputStream::STOFFInputStream
STOFFInputStream(std::shared_ptr< librevenge::RVNGInputStream > input, bool inverted)
creates a stream with given endian
Definition: STOFFInputStream.cxx:47
STOFFInputStream::operator=
STOFFInputStream & operator=(STOFFInputStream const &orig)
STOFFInputStream::operator>>
STOFFInputStream & operator>>(int8_t &res)
operator>> for int8_t
Definition: STOFFInputStream.hxx:131
STOFFInputStream::m_inverseRead
bool m_inverseRead
big or normal endian
Definition: STOFFInputStream.hxx:248
STOFFInputStream::peek
int peek()
returns the value of the next caracters or -1, but does not increment the position counter
Definition: STOFFInputStream.cxx:214
STOFFInputStream::getSubStreamByName
std::shared_ptr< STOFFInputStream > getSubStreamByName(std::string const &name)
return a new stream for a ole zone
Definition: STOFFInputStream.cxx:526
STOFFInputStream::readInverted
bool readInverted() const
returns the endian mode (see constructor)
Definition: STOFFInputStream.hxx:79
STOFFInputStream::seek
int seek(long offset, librevenge::RVNG_SEEK_TYPE seekType)
seeks to a offset position, from actual, beginning or ending position
Definition: STOFFInputStream.cxx:118
STOFFInputStream::checkPosition
bool checkPosition(long pos) const
checks if a position is or not a valid file position
Definition: STOFFInputStream.hxx:104
STOFFInputStream::operator>>
STOFFInputStream & operator>>(uint32_t &res)
operator>> for uint32_t
Definition: STOFFInputStream.hxx:149
STOFFInputStream::readCompressedULong
bool readCompressedULong(unsigned long &res)
read a compressed unsigned long (sw_sw3imp.cxx Sw3IoImp::InULong)
Definition: STOFFInputStream.cxx:274
STOFFInputStream::updateStreamSize
void updateStreamSize()
update the stream size ( must be called in the constructor )
Definition: STOFFInputStream.cxx:92
STOFFDebug.hxx
STOFF_N_ELEMENTS
#define STOFF_N_ELEMENTS(m)
Definition: libstaroffice_internal.hxx:119
STOFFInputStream::size
long size() const
returns the stream size
Definition: STOFFInputStream.hxx:99
STOFFInputStream::input
std::shared_ptr< librevenge::RVNGInputStream > input()
returns the basic librevenge::RVNGInputStream
Definition: STOFFInputStream.hxx:71
STOFFInputStream
Internal class used to read the file stream Internal class used to read the file stream,...
Definition: STOFFInputStream.hxx:53
STOFFInputStream::subStreamName
std::string subStreamName(unsigned id)
returns the name of the i^th substream
Definition: STOFFInputStream.cxx:512
STOFFInputStream::readDataBlock
bool readDataBlock(long size, librevenge::RVNGBinaryData &data)
reads a librevenge::RVNGBinaryData with a given size in the actual section/file
Definition: STOFFInputStream.cxx:572
STOFFInputStream::isEnd
bool isEnd()
returns true if we are at the end of the section/file
Definition: STOFFInputStream.cxx:139
STOFFInputStream.hxx
STOFFInputStream::readEndDataBlock
bool readEndDataBlock(librevenge::RVNGBinaryData &data)
reads a librevenge::RVNGBinaryData from actPos to the end of the section/file
Definition: STOFFInputStream.cxx:590
STOFF_shared_ptr_noop_deleter
an noop deleter used to transform a libwpd pointer in a false std::shared_ptr
Definition: libstaroffice_internal.hxx:100