MWAWInputStream.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libmwaw
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
#ifndef MWAW_INPUT_STREAM_H
#define MWAW_INPUT_STREAM_H
#include <string>
#include <vector>
#include <librevenge/librevenge.h>
#include <librevenge-stream/librevenge-stream.h>
#include "libmwaw_internal.hxx"
class MWAWInputStream
{
public:
MWAWInputStream(std::shared_ptr<librevenge::RVNGInputStream> input, bool inverted);
MWAWInputStream(librevenge::RVNGInputStream *input, bool inverted, bool checkCompression=false);
~MWAWInputStream();
std::shared_ptr<librevenge::RVNGInputStream> input()
{
return m_stream;
}
static std::shared_ptr<MWAWInputStream> get(librevenge::RVNGBinaryData const &data, bool inverted);
bool readInverted() const
{
return m_inverseRead;
}
void setReadInverted(bool newVal)
{
m_inverseRead = newVal;
}
//
// Position: access
//
int seek(long offset, librevenge::RVNG_SEEK_TYPE seekType);
long tell();
long size() const
{
return m_streamSize;
}
bool checkPosition(long pos) const
{
if (pos < 0) return false;
if (m_readLimit > 0 && pos > m_readLimit) return false;
return pos<=m_streamSize;
}
bool isEnd();
void pushLimit(long newLimit)
{
m_prevLimits.push_back(m_readLimit);
m_readLimit = newLimit > m_streamSize ? m_streamSize : newLimit;
}
void popLimit()
{
if (!m_prevLimits.empty()) {
m_readLimit = m_prevLimits.back();
m_prevLimits.pop_back();
}
else m_readLimit = -1;
}
void recomputeStreamSize();
//
// get data
//
unsigned long readULong(int num)
{
return readULong(m_stream.get(), num, 0, m_inverseRead);
}
long readLong(int num);
bool readDouble8(double &res, bool &isNotANumber);
bool readDoubleReverted8(double &res, bool &isNotANumber);
bool readDouble10(double &res, bool &isNotANumber);
const uint8_t *read(size_t numBytes, unsigned long &numBytesRead);
static unsigned long readULong(librevenge::RVNGInputStream *stream, int num, unsigned long a, bool inverseRead);
bool readDataBlock(long size, librevenge::RVNGBinaryData &data);
bool readEndDataBlock(librevenge::RVNGBinaryData &data);
//
// OLE/Zip access
//
bool isStructured();
unsigned subStreamCount();
std::string subStreamName(unsigned id);
std::shared_ptr<MWAWInputStream> getSubStreamByName(std::string const &name);
std::shared_ptr<MWAWInputStream> getSubStreamById(unsigned id);
//
// Finder Info access
//
bool getFinderInfo(std::string &type, std::string &creator) const
{
if (!m_fInfoType.length() || !m_fInfoCreator.length()) {
type = creator = "";
return false;
}
type = m_fInfoType;
creator = m_fInfoCreator;
return true;
}
//
// Resource Fork access
//
bool hasDataFork() const
{
return bool(m_stream);
}
bool hasResourceFork() const
{
return bool(m_resourceFork);
}
std::shared_ptr<MWAWInputStream> getResourceForkStream()
{
return m_resourceFork;
}
protected:
void updateStreamSize();
static uint8_t readU8(librevenge::RVNGInputStream *stream);
bool unBinHex();
bool unzipStream();
bool unMacMIME();
bool unMacMIME(MWAWInputStream *input,
std::shared_ptr<librevenge::RVNGInputStream> &dataInput,
std::shared_ptr<librevenge::RVNGInputStream> &rsrcInput) const;
bool unsplitInternalMergeStream();
private:
MWAWInputStream(MWAWInputStream const &orig) = delete;
MWAWInputStream &operator=(MWAWInputStream const &orig) = delete;
protected:
std::shared_ptr<librevenge::RVNGInputStream> m_stream;
long m_streamSize;
long m_readLimit;
std::vector<long> m_prevLimits;
mutable std::string m_fInfoType;
mutable std::string m_fInfoCreator;
std::shared_ptr<MWAWInputStream> m_resourceFork;
bool m_inverseRead;
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWInputStream
Internal class used to read the file stream Internal class used to read the file stream,...
Definition MWAWInputStream.hxx:54
MWAWInputStream::unsplitInternalMergeStream
bool unsplitInternalMergeStream()
check if a stream is an internal merge stream
Definition MWAWInputStream.cxx:572
MWAWInputStream::MWAWInputStream
MWAWInputStream(MWAWInputStream const &orig)=delete
MWAWInputStream::m_fInfoCreator
std::string m_fInfoCreator
finder info type
Definition MWAWInputStream.hxx:260
MWAWInputStream::m_stream
std::shared_ptr< librevenge::RVNGInputStream > m_stream
the initial input
Definition MWAWInputStream.hxx:248
MWAWInputStream::isStructured
bool isStructured()
return true if the stream is ole
Definition MWAWInputStream.cxx:837
MWAWInputStream::getSubStreamByName
std::shared_ptr< MWAWInputStream > getSubStreamByName(std::string const &name)
return a new stream for a ole zone
Definition MWAWInputStream.cxx:869
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:154
MWAWInputStream::getResourceForkStream
std::shared_ptr< MWAWInputStream > getResourceForkStream()
returns the resource fork if find
Definition MWAWInputStream.hxx:217
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:340
MWAWInputStream::checkPosition
bool checkPosition(long pos) const
checks if a position is or not a valid file position
Definition MWAWInputStream.hxx:105
MWAWInputStream::readEndDataBlock
bool readEndDataBlock(librevenge::RVNGBinaryData &data)
reads a librevenge::RVNGBinaryData from actPos to the end of the section/file
Definition MWAWInputStream.cxx:934
MWAWInputStream::unzipStream
bool unzipStream()
unzip the data in the file is a zip file of a mac file
Definition MWAWInputStream.cxx:640
MWAWInputStream::unBinHex
bool unBinHex()
unbinhex the data in the file is a BinHex 4.0 file of a mac file
Definition MWAWInputStream.cxx:390
MWAWInputStream::operator=
MWAWInputStream & operator=(MWAWInputStream const &orig)=delete
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:299
MWAWInputStream::hasDataFork
bool hasDataFork() const
returns true if the data fork block exists
Definition MWAWInputStream.hxx:207
MWAWInputStream::recomputeStreamSize
void recomputeStreamSize()
Definition MWAWInputStream.cxx:122
MWAWInputStream::m_resourceFork
std::shared_ptr< MWAWInputStream > m_resourceFork
the resource fork
Definition MWAWInputStream.hxx:262
MWAWInputStream::m_prevLimits
std::vector< long > m_prevLimits
list of previous limits
Definition MWAWInputStream.hxx:255
MWAWInputStream::size
long size() const
returns the stream size
Definition MWAWInputStream.hxx:100
MWAWInputStream::popLimit
void popLimit()
pops a section defined by pushLimit
Definition MWAWInputStream.hxx:123
MWAWInputStream::get
static std::shared_ptr< MWAWInputStream > get(librevenge::RVNGBinaryData const &data, bool inverted)
returns a new input stream corresponding to a librevenge::RVNGBinaryData
Definition MWAWInputStream.cxx:102
MWAWInputStream::~MWAWInputStream
~MWAWInputStream()
destructor
Definition MWAWInputStream.cxx:98
MWAWInputStream::updateStreamSize
void updateStreamSize()
update the stream size ( must be called in the constructor )
Definition MWAWInputStream.cxx:128
MWAWInputStream::m_streamSize
long m_streamSize
the stream size
Definition MWAWInputStream.hxx:250
MWAWInputStream::m_fInfoType
std::string m_fInfoType
finder info type
Definition MWAWInputStream.hxx:258
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::input
std::shared_ptr< librevenge::RVNGInputStream > input()
returns the basic librevenge::RVNGInputStream
Definition MWAWInputStream.hxx:71
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:257
MWAWInputStream::isEnd
bool isEnd()
returns true if we are at the end of the section/file
Definition MWAWInputStream.cxx:177
MWAWInputStream::readLong
long readLong(int num)
return a int8, int16, int32 readed from actualPos
Definition MWAWInputStream.cxx:229
MWAWInputStream::setReadInverted
void setReadInverted(bool newVal)
sets the endian mode
Definition MWAWInputStream.hxx:84
MWAWInputStream::tell
long tell()
returns actual offset position
Definition MWAWInputStream.cxx:147
MWAWInputStream::subStreamCount
unsigned subStreamCount()
returns the number of substream
Definition MWAWInputStream.cxx:846
MWAWInputStream::m_inverseRead
bool m_inverseRead
big or normal endian
Definition MWAWInputStream.hxx:264
MWAWInputStream::getFinderInfo
bool getFinderInfo(std::string &type, std::string &creator) const
returns the finder info type and creator (if known)
Definition MWAWInputStream.hxx:191
MWAWInputStream::subStreamName
std::string subStreamName(unsigned id)
returns the name of the i^th substream
Definition MWAWInputStream.cxx:855
MWAWInputStream::read
const uint8_t * read(size_t numBytes, unsigned long &numBytesRead)
!
Definition MWAWInputStream.cxx:140
MWAWInputStream::m_readLimit
long m_readLimit
actual section limit (-1 if no limit)
Definition MWAWInputStream.hxx:253
MWAWInputStream::MWAWInputStream
MWAWInputStream(std::shared_ptr< librevenge::RVNGInputStream > input, bool inverted)
creates a stream with given endian
Definition MWAWInputStream.cxx:48
MWAWInputStream::getSubStreamById
std::shared_ptr< MWAWInputStream > getSubStreamById(unsigned id)
return a new stream for a ole zone
Definition MWAWInputStream.cxx:889
MWAWInputStream::hasResourceFork
bool hasResourceFork() const
returns true if the resource fork block exists
Definition MWAWInputStream.hxx:212
MWAWInputStream::readU8
static uint8_t readU8(librevenge::RVNGInputStream *stream)
internal function used to read a byte
Definition MWAWInputStream.cxx:244
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:915
MWAWInputStream::readInverted
bool readInverted() const
returns the endian mode (see constructor)
Definition MWAWInputStream.hxx:79
MWAWInputStream::unMacMIME
bool unMacMIME()
check if some stream are in MacMIME format, if so de MacMIME
Definition MWAWInputStream.cxx:685
MWAWInputStream::readULong
unsigned long readULong(int num)
returns a uint8, uint16, uint32 readed from actualPos
Definition MWAWInputStream.hxx:144
libmwaw_internal.hxx