scummvm/scumm/smush/chunk.h

122 lines
3.6 KiB
C
Raw Normal View History

2002-08-24 15:31:37 +00:00
/* ScummVM - Scumm Interpreter
* Copyright (C) 2001/2002 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*
*/
2002-08-24 23:22:10 +00:00
#ifndef CHUNK_H
#define CHUNK_H
2002-08-24 15:31:37 +00:00
#include "config.h"
/*! @brief Interface for Chunk handling
2002-08-24 15:31:37 +00:00
This class is an interface for reading from a Chunk.
2002-08-24 15:31:37 +00:00
\todo handle big endian system.
*/
class Chunk {
2002-08-24 15:31:37 +00:00
public:
enum seek_type { seek_start, seek_end, seek_cur };
virtual ~Chunk() {};
2002-08-30 07:24:45 +00:00
typedef uint32 type; //!< type of a Chunk (i.e. The first 4byte field of the Chunk structure).
2002-08-24 15:31:37 +00:00
/*! @brief convert a type to a string
Utility function that convert a type to a string.
@param t the type to convert to a string
@return the converted string
*/
static const char * ChunkString(type t);
2002-08-24 15:31:37 +00:00
virtual type getType() const = 0; //!< return the type of the Chunk
2002-08-30 07:24:45 +00:00
virtual uint32 getSize() const = 0; //!< return the size of the Chunk
virtual Chunk * subBlock() = 0; //!< extract a subChunk from the current read position
virtual bool eof() const = 0; //!< is the Chunk completely read ?
2002-08-30 07:24:45 +00:00
virtual uint32 tell() const = 0; //!< get the Chunk current read position
virtual bool seek(int32 delta, seek_type dir = seek_cur) = 0; //!< move the current read position inside the Chunk
virtual bool read(void * buffer, uint32 size) = 0; //!< read some data for the current read position
virtual int8 getChar() = 0; //!< extract the character at the current read position
2002-08-30 07:24:45 +00:00
virtual byte getByte() = 0; //!< extract the byte at the current read position
virtual int16 getShort() = 0; //!< extract the short at the current read position
virtual uint16 getWord() = 0; //!< extract the word at the current read position
virtual uint32 getDword()= 0; //!< extract the dword at the current read position
2002-08-24 15:31:37 +00:00
};
class FilePtr;
/*! @brief file based ::Chunk
2002-08-24 15:31:37 +00:00
This class is an implementation of ::Chunk that handles file.
2002-08-24 15:31:37 +00:00
*/
class FileChunk : public Chunk {
2002-08-24 15:31:37 +00:00
private:
FilePtr * _data;
type _type;
2002-08-30 07:24:45 +00:00
uint32 _size;
uint32 _offset;
uint32 _curPos;
2002-08-24 15:31:37 +00:00
protected:
FileChunk();
2002-08-24 15:31:37 +00:00
public:
FileChunk(const char * fname, const char * directory);
virtual ~FileChunk();
2002-08-24 15:31:37 +00:00
type getType() const;
2002-08-30 07:24:45 +00:00
uint32 getSize() const;
Chunk * subBlock();
2002-08-24 15:31:37 +00:00
bool eof() const;
2002-08-30 07:24:45 +00:00
uint32 tell() const;
bool seek(int32 delta, seek_type dir = seek_cur);
bool read(void * buffer, uint32 size);
int8 getChar();
2002-08-30 07:24:45 +00:00
byte getByte();
2002-08-24 15:31:37 +00:00
short getShort();
2002-08-30 07:24:45 +00:00
uint16 getWord();
uint32 getDword();
2002-08-24 15:31:37 +00:00
};
/*! @brief memory based ::Chunk
2002-08-24 15:31:37 +00:00
This class is an implementation of ::Chunk that handles a memory buffer.
2002-08-24 15:31:37 +00:00
*/
class ContChunk : public Chunk {
2002-08-24 15:31:37 +00:00
private:
2002-08-30 07:24:45 +00:00
byte * _data;
Chunk::type _type;
2002-08-30 07:24:45 +00:00
uint32 _size;
uint32 _curPos;
2002-08-24 15:31:37 +00:00
public:
2002-08-30 07:24:45 +00:00
ContChunk(byte * data);
Chunk::type getType() const;
2002-08-30 07:24:45 +00:00
uint32 getSize() const;
Chunk * subBlock();
2002-08-24 15:31:37 +00:00
bool eof() const;
2002-08-30 07:24:45 +00:00
uint32 tell() const;
bool seek(int32 delta, seek_type dir = seek_cur);
bool read(void * buffer, uint32 size);
int8 getChar();
2002-08-30 07:24:45 +00:00
byte getByte();
int16 getShort();
uint16 getWord();
uint32 getDword();
2002-08-24 15:31:37 +00:00
};
#endif