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>
43
54{
55public:
60 STOFFInputStream(shared_ptr<librevenge::RVNGInputStream> input, bool inverted);
61
66 STOFFInputStream(librevenge::RVNGInputStream *input, bool inverted);
69
71 shared_ptr<librevenge::RVNGInputStream> input()
72 {
73 return m_stream;
74 }
76 static 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
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.size()) {
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 int peek();
140 {
141 res=readULong(1)!=0 ? true : false;
142 return *this;
143 }
146 {
147 res=static_cast<uint8_t>(readULong(1));
148 return *this;
149 }
152 {
153 res=static_cast<int8_t>(readLong(1));
154 return *this;
155 }
158 {
159 res=static_cast<uint16_t>(readULong(2));
160 return *this;
161 }
164 {
165 res=static_cast<int16_t>(readLong(2));
166 return *this;
167 }
170 {
171 res=static_cast<uint32_t>(readULong(4));
172 return *this;
173 }
176 {
177 res=static_cast<int32_t>(readLong(4));
178 return *this;
179 }
182 {
183 bool isNan;
184 long pos=tell();
185 if (!readDoubleReverted8(res, isNan)) {
186 STOFF_DEBUG_MSG(("STOFFInputStream::operator>>: can not read a double\n"));
187 seek(pos+8, librevenge::RVNG_SEEK_SET);
188 res=0;
189 }
190 return *this;
191 }
193 unsigned long readULong(int num)
194 {
195 return readULong(m_stream.get(), num, 0, m_inverseRead);
196 }
198 long readLong(int num);
200 bool readColor(STOFFColor &color);
202 bool readCompressedLong(long &res);
204 bool readCompressedULong(unsigned long &res);
206 bool readDouble8(double &res, bool &isNotANumber);
208 bool readDoubleReverted8(double &res, bool &isNotANumber);
210 bool readDouble10(double &res, bool &isNotANumber);
214 const uint8_t *read(size_t numBytes, unsigned long &numBytesRead);
218 static unsigned long readULong(librevenge::RVNGInputStream *stream, int num, unsigned long a, bool inverseRead);
219
221 bool readDataBlock(long size, librevenge::RVNGBinaryData &data);
223 bool readEndDataBlock(librevenge::RVNGBinaryData &data);
224
225 //
226 // OLE/Zip access
227 //
228
230 bool isStructured();
232 unsigned subStreamCount();
234 std::string subStreamName(unsigned id);
235
237 shared_ptr<STOFFInputStream> getSubStreamByName(std::string const &name);
239 shared_ptr<STOFFInputStream> getSubStreamById(unsigned id);
240
241 //
242 // Resource Fork access
243 //
244
246 bool hasDataFork() const
247 {
248 return bool(m_stream);
249 }
250
251protected:
253 void updateStreamSize();
255 static uint8_t readU8(librevenge::RVNGInputStream *stream);
256
257private:
260
261protected:
263 shared_ptr<librevenge::RVNGInputStream> m_stream;
266
269
273 std::vector<long> m_prevLimits;
274};
275
276#endif
277// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
Internal class used to read the file stream Internal class used to read the file stream,...
Definition STOFFInputStream.hxx:54
long m_readLimit
actual section limit (-1 if no limit)
Definition STOFFInputStream.hxx:271
STOFFInputStream & operator=(STOFFInputStream const &orig)
shared_ptr< STOFFInputStream > getSubStreamByName(std::string const &name)
return a new stream for a ole zone
Definition STOFFInputStream.cxx:529
std::vector< long > m_prevLimits
list of previous limits
Definition STOFFInputStream.hxx:273
STOFFInputStream(STOFFInputStream const &orig)
bool m_inverseRead
big or normal endian
Definition STOFFInputStream.hxx:268
bool readDataBlock(long size, librevenge::RVNGBinaryData &data)
reads a librevenge::RVNGBinaryData with a given size in the actual section/file
Definition STOFFInputStream.cxx:575
shared_ptr< STOFFInputStream > getSubStreamById(unsigned id)
return a new stream for a ole zone
Definition STOFFInputStream.cxx:549
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
int seek(long offset, librevenge::RVNG_SEEK_TYPE seekType)
seeks to a offset position, from actual, beginning or ending position
Definition STOFFInputStream.cxx:114
bool readColor(STOFFColor &color)
try to read a color
Definition STOFFInputStream.cxx:221
bool checkPosition(long pos) const
checks if a position is or not a valid file position
Definition STOFFInputStream.hxx:105
shared_ptr< librevenge::RVNGInputStream > m_stream
the initial input
Definition STOFFInputStream.hxx:263
STOFFInputStream & operator>>(int32_t &res)
operator>> for int32_t
Definition STOFFInputStream.hxx:175
long tell()
returns actual offset position
Definition STOFFInputStream.cxx:107
long m_streamSize
the stream size
Definition STOFFInputStream.hxx:265
void updateStreamSize()
update the stream size ( must be called in the constructor )
Definition STOFFInputStream.cxx:88
long size() const
returns the stream size
Definition STOFFInputStream.hxx:100
unsigned subStreamCount()
returns the number of substream
Definition STOFFInputStream.cxx:506
unsigned long readULong(int num)
returns a uint8, uint16, uint32 readed from actualPos
Definition STOFFInputStream.hxx:193
std::string subStreamName(unsigned id)
returns the name of the i^th substream
Definition STOFFInputStream.cxx:515
STOFFInputStream & operator>>(bool &res)
operator>> for bool
Definition STOFFInputStream.hxx:139
void popLimit()
pops a section defined by pushLimit
Definition STOFFInputStream.hxx:123
bool readEndDataBlock(librevenge::RVNGBinaryData &data)
reads a librevenge::RVNGBinaryData from actPos to the end of the section/file
Definition STOFFInputStream.cxx:594
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:446
~STOFFInputStream()
destructor
Definition STOFFInputStream.cxx:64
static shared_ptr< STOFFInputStream > get(librevenge::RVNGBinaryData const &data, bool inverted)
returns a new input stream corresponding to a librevenge::RVNGBinaryData
Definition STOFFInputStream.cxx:68
STOFFInputStream & operator>>(uint32_t &res)
operator>> for uint32_t
Definition STOFFInputStream.hxx:169
STOFFInputStream & operator>>(uint8_t &res)
operator>> for uint8_t
Definition STOFFInputStream.hxx:145
static uint8_t readU8(librevenge::RVNGInputStream *stream)
internal function used to read a byte
Definition STOFFInputStream.cxx:200
bool readDouble10(double &res, bool &isNotANumber)
try to read a double of size 10: 2 bytes exponent, 8 bytes mantisse
Definition STOFFInputStream.cxx:405
bool readCompressedULong(unsigned long &res)
read a compressed unsigned long (sw_sw3imp.cxx Sw3IoImp::InULong)
Definition STOFFInputStream.cxx:273
void setReadInverted(bool newVal)
sets the endian mode
Definition STOFFInputStream.hxx:84
STOFFInputStream & operator>>(int8_t &res)
operator>> for int8_t
Definition STOFFInputStream.hxx:151
STOFFInputStream & operator>>(uint16_t &res)
operator>> for uint16_t
Definition STOFFInputStream.hxx:157
bool readCompressedLong(long &res)
read a compressed long (pstm.cxx:ReadCompressed)
Definition STOFFInputStream.cxx:321
void pushLimit(long newLimit)
defines a new section in the file (from actualPos to newLimit) next call of seek, tell,...
Definition STOFFInputStream.hxx:117
bool isStructured()
return true if the stream is ole
Definition STOFFInputStream.cxx:497
int peek()
returns the value of the next caracters or -1, but does not increment the position counter
Definition STOFFInputStream.cxx:213
STOFFInputStream & operator>>(int16_t &res)
operator>> for int16_t
Definition STOFFInputStream.hxx:163
bool readInverted() const
returns the endian mode (see constructor)
Definition STOFFInputStream.hxx:79
bool isEnd()
returns true if we are at the end of the section/file
Definition STOFFInputStream.cxx:137
long readLong(int num)
return a int8, int16, int32 readed from actualPos
Definition STOFFInputStream.cxx:182
bool hasDataFork() const
returns true if the data fork block exists
Definition STOFFInputStream.hxx:246
const uint8_t * read(size_t numBytes, unsigned long &numBytesRead)
! reads numbytes data, WITHOUT using any endian or section consideration
Definition STOFFInputStream.cxx:100
shared_ptr< librevenge::RVNGInputStream > input()
returns the basic librevenge::RVNGInputStream
Definition STOFFInputStream.hxx:71
STOFFInputStream & operator>>(double &res)
operator>> for double
Definition STOFFInputStream.hxx:181
#define STOFF_DEBUG_MSG(M)
Definition libstaroffice_internal.hxx:127
the class to store a color
Definition libstaroffice_internal.hxx:179

Generated on Wed Nov 29 2023 18:59:40 for libstaroffice by doxygen 1.9.8