STOFFInputStream.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 -*- */
/* libstaroffice
* 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 STOFF_INPUT_STREAM_H
#define STOFF_INPUT_STREAM_H
#include <string>
#include <vector>
#include <librevenge/librevenge.h>
#include <librevenge-stream/librevenge-stream.h>
#include "libstaroffice_internal.hxx"
class STOFFInputStream
{
public:
STOFFInputStream(std::shared_ptr<librevenge::RVNGInputStream> input, bool inverted);
STOFFInputStream(librevenge::RVNGInputStream *input, bool inverted);
~STOFFInputStream();
std::shared_ptr<librevenge::RVNGInputStream> input()
{
return m_stream;
}
static std::shared_ptr<STOFFInputStream> 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;
return pos<=m_streamSize;
}
bool isEnd();
//
// get data
//
int peek();
STOFFInputStream &operator>>(bool &res)
{
res=readULong(1)!=0 ? true : false;
return *this;
}
STOFFInputStream &operator>>(uint8_t &res)
{
res=static_cast<uint8_t>(readULong(1));
return *this;
}
STOFFInputStream &operator>>(int8_t &res)
{
res=static_cast<int8_t>(readLong(1));
return *this;
}
STOFFInputStream &operator>>(uint16_t &res)
{
res=static_cast<uint16_t>(readULong(2));
return *this;
}
STOFFInputStream &operator>>(int16_t &res)
{
res=static_cast<int16_t>(readLong(2));
return *this;
}
STOFFInputStream &operator>>(uint32_t &res)
{
res=static_cast<uint32_t>(readULong(4));
return *this;
}
STOFFInputStream &operator>>(int32_t &res)
{
res=static_cast<int32_t>(readLong(4));
return *this;
}
STOFFInputStream &operator>>(double &res)
{
bool isNan;
long pos=tell();
if (!readDoubleReverted8(res, isNan)) {
STOFF_DEBUG_MSG(("STOFFInputStream::operator>>: can not read a double\n"));
seek(pos+8, librevenge::RVNG_SEEK_SET);
res=0;
}
return *this;
}
unsigned long readULong(int num)
{
return readULong(m_stream.get(), num, 0, m_inverseRead);
}
long readLong(int num);
bool readColor(STOFFColor &color);
bool readCompressedLong(long &res);
bool readCompressedULong(unsigned long &res);
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<STOFFInputStream> getSubStreamByName(std::string const &name);
std::shared_ptr<STOFFInputStream> getSubStreamById(unsigned id);
//
// Resource Fork access
//
bool hasDataFork() const
{
return bool(m_stream);
}
protected:
void updateStreamSize();
static uint8_t readU8(librevenge::RVNGInputStream *stream);
private:
STOFFInputStream(STOFFInputStream const &orig);
STOFFInputStream &operator=(STOFFInputStream const &orig);
protected:
std::shared_ptr<librevenge::RVNGInputStream> m_stream;
long m_streamSize;
bool m_inverseRead;
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
STOFFInputStream::operator=
STOFFInputStream & operator=(STOFFInputStream const &orig)
STOFFInputStream::STOFFInputStream
STOFFInputStream(STOFFInputStream const &orig)
STOFFInputStream::input
std::shared_ptr< librevenge::RVNGInputStream > input()
returns the basic librevenge::RVNGInputStream
Definition STOFFInputStream.hxx:71
STOFFInputStream::m_inverseRead
bool m_inverseRead
big or normal endian
Definition STOFFInputStream.hxx:248
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::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::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::readColor
bool readColor(STOFFColor &color)
try to read a color
Definition STOFFInputStream.cxx:222
STOFFInputStream::m_stream
std::shared_ptr< librevenge::RVNGInputStream > m_stream
the initial input
Definition STOFFInputStream.hxx:243
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>>(int32_t &res)
operator>> for int32_t
Definition STOFFInputStream.hxx:155
STOFFInputStream::STOFFInputStream
STOFFInputStream(std::shared_ptr< librevenge::RVNGInputStream > input, bool inverted)
creates a stream with given endian
Definition STOFFInputStream.cxx:47
STOFFInputStream::tell
long tell()
returns actual offset position
Definition STOFFInputStream.cxx:111
STOFFInputStream::m_streamSize
long m_streamSize
the stream size
Definition STOFFInputStream.hxx:245
STOFFInputStream::updateStreamSize
void updateStreamSize()
update the stream size ( must be called in the constructor )
Definition STOFFInputStream.cxx:92
STOFFInputStream::size
long size() const
returns the stream size
Definition STOFFInputStream.hxx:99
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::subStreamName
std::string subStreamName(unsigned id)
returns the name of the i^th substream
Definition STOFFInputStream.cxx:512
STOFFInputStream::operator>>
STOFFInputStream & operator>>(bool &res)
operator>> for bool
Definition STOFFInputStream.hxx:119
STOFFInputStream::readEndDataBlock
bool readEndDataBlock(librevenge::RVNGBinaryData &data)
reads a librevenge::RVNGBinaryData from actPos to the end of the section/file
Definition STOFFInputStream.cxx:590
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::~STOFFInputStream
~STOFFInputStream()
destructor
Definition STOFFInputStream.cxx:68
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::operator>>
STOFFInputStream & operator>>(uint32_t &res)
operator>> for uint32_t
Definition STOFFInputStream.hxx:149
STOFFInputStream::operator>>
STOFFInputStream & operator>>(uint8_t &res)
operator>> for uint8_t
Definition STOFFInputStream.hxx:125
STOFFInputStream::readU8
static uint8_t readU8(librevenge::RVNGInputStream *stream)
internal function used to read a byte
Definition STOFFInputStream.cxx:201
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
STOFFInputStream::readCompressedULong
bool readCompressedULong(unsigned long &res)
read a compressed unsigned long (sw_sw3imp.cxx Sw3IoImp::InULong)
Definition STOFFInputStream.cxx:274
STOFFInputStream::setReadInverted
void setReadInverted(bool newVal)
sets the endian mode
Definition STOFFInputStream.hxx:84
STOFFInputStream::operator>>
STOFFInputStream & operator>>(int8_t &res)
operator>> for int8_t
Definition STOFFInputStream.hxx:131
STOFFInputStream::operator>>
STOFFInputStream & operator>>(uint16_t &res)
operator>> for uint16_t
Definition STOFFInputStream.hxx:137
STOFFInputStream::readCompressedLong
bool readCompressedLong(long &res)
read a compressed long (pstm.cxx:ReadCompressed)
Definition STOFFInputStream.cxx:322
STOFFInputStream::isStructured
bool isStructured()
return true if the stream is ole
Definition STOFFInputStream.cxx:494
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::operator>>
STOFFInputStream & operator>>(int16_t &res)
operator>> for int16_t
Definition STOFFInputStream.hxx:143
STOFFInputStream::getSubStreamByName
std::shared_ptr< STOFFInputStream > getSubStreamByName(std::string const &name)
return a new stream for a ole zone
Definition STOFFInputStream.cxx:526
STOFFInputStream::getSubStreamById
std::shared_ptr< STOFFInputStream > getSubStreamById(unsigned id)
return a new stream for a ole zone
Definition STOFFInputStream.cxx:546
STOFFInputStream::readInverted
bool readInverted() const
returns the endian mode (see constructor)
Definition STOFFInputStream.hxx:79
STOFFInputStream::isEnd
bool isEnd()
returns true if we are at the end of the section/file
Definition STOFFInputStream.cxx:139
STOFFInputStream::readLong
long readLong(int num)
return a int8, int16, int32 readed from actualPos
Definition STOFFInputStream.cxx:183
STOFFInputStream::hasDataFork
bool hasDataFork() const
returns true if the data fork block exists
Definition STOFFInputStream.hxx:226
STOFFInputStream::read
const uint8_t * read(size_t numBytes, unsigned long &numBytesRead)
!
Definition STOFFInputStream.cxx:104
STOFFInputStream::operator>>
STOFFInputStream & operator>>(double &res)
operator>> for double
Definition STOFFInputStream.hxx:161
libstaroffice_internal.hxx
STOFF_DEBUG_MSG
#define STOFF_DEBUG_MSG(M)
Definition libstaroffice_internal.hxx:129
STOFFColor
the class to store a color
Definition libstaroffice_internal.hxx:189