[Scummvm-cvs-logs] CVS: scummvm/scumm/smush chunk.cpp,1.13,1.14 chunk.h,1.8,1.9 imuse_channel.cpp,1.15,1.16 saud_channel.cpp,1.12,1.13
Max Horn
fingolfin at users.sourceforge.net
Sun May 25 04:40:02 CEST 2003
Update of /cvsroot/scummvm/scummvm/scumm/smush
In directory sc8-pr-cvs1:/tmp/cvs-serv11493
Modified Files:
chunk.cpp chunk.h imuse_channel.cpp saud_channel.cpp
Log Message:
renamed ContChunk -> MemoryChunk; avoid code duplication by introducing BaseChunk
Index: chunk.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/chunk.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- chunk.cpp 21 May 2003 18:16:01 -0000 1.13
+++ chunk.cpp 25 May 2003 11:39:08 -0000 1.14
@@ -84,61 +84,29 @@
return data;
}
-FileChunk::FileChunk() :
- _data(0),
+BaseChunk::BaseChunk() :
_type(0),
_size(0),
_curPos(0) {
}
-FileChunk::~FileChunk() {
- if(_data)
- _data->decRef();
+bool BaseChunk::eof() const {
+ return _curPos >= _size;
}
-FileChunk::FileChunk(const char *fname, const char *directory) {
- _data = new FilePtr(fname, directory);
- _data->read(&_type, 4);
- _type = TO_BE_32(_type);
- _data->read(&_size, 4);
- _size = TO_BE_32(_size);
- _offset = _data->tell();
- _curPos = 0;
+uint32 BaseChunk::tell() const {
+ return _curPos;
}
-Chunk::type FileChunk::getType() const {
+Chunk::type BaseChunk::getType() const {
return _type;
}
-uint32 FileChunk::getSize() const {
+uint32 BaseChunk::getSize() const {
return _size;
}
-Chunk *FileChunk::subBlock() {
- FileChunk *ptr = new FileChunk;
- ptr->_data = _data;
- _data->incRef();
- _data->seek(_offset + _curPos);
- uint32 temp;
- _data->read(&temp, 4);
- ptr->_type = TO_BE_32(temp);
- _data->read(&temp, 4);
- ptr->_size = TO_BE_32(temp);
- ptr->_offset = _offset + _curPos + 8;
- ptr->_curPos = 0;
- seek(8 + ptr->getSize());
- return ptr;
-}
-
-bool FileChunk::eof() const {
- return _curPos >= _size;
-}
-
-uint32 FileChunk::tell() const {
- return _curPos;
-}
-
-bool FileChunk::seek(int32 delta, seek_type dir) {
+bool BaseChunk::seek(int32 delta, seek_type dir) {
switch(dir) {
case seek_cur:
_curPos += delta;
@@ -162,6 +130,41 @@
return true;
}
+FileChunk::FileChunk() :
+ _data(0) {
+}
+
+FileChunk::FileChunk(const char *fname, const char *directory) {
+ _data = new FilePtr(fname, directory);
+ _data->read(&_type, 4);
+ _type = TO_BE_32(_type);
+ _data->read(&_size, 4);
+ _size = TO_BE_32(_size);
+ _offset = _data->tell();
+ _curPos = 0;
+}
+
+FileChunk::~FileChunk() {
+ if(_data)
+ _data->decRef();
+}
+
+Chunk *FileChunk::subBlock() {
+ FileChunk *ptr = new FileChunk();
+ ptr->_data = _data;
+ _data->incRef();
+ _data->seek(_offset + _curPos);
+ uint32 temp;
+ _data->read(&temp, 4);
+ ptr->_type = TO_BE_32(temp);
+ _data->read(&temp, 4);
+ ptr->_size = TO_BE_32(temp);
+ ptr->_offset = _offset + _curPos + 8;
+ ptr->_curPos = 0;
+ seek(8 + ptr->getSize());
+ return ptr;
+}
+
bool FileChunk::read(void *buffer, uint32 size) {
if(size <= 0 || (_curPos + size) > _size)
error("invalid buffer read request");
@@ -221,7 +224,7 @@
return TO_LE_32(buffer);
}
-ContChunk::ContChunk(byte *data) {
+MemoryChunk::MemoryChunk(byte *data) {
if(data == 0)
error("Chunk() called with NULL pointer");
@@ -231,49 +234,13 @@
_curPos = 0;
}
-Chunk::type ContChunk::getType() const {
- return _type;
-}
-
-uint32 ContChunk::getSize() const {
- return _size;
-}
-
-Chunk *ContChunk::subBlock() {
- ContChunk *ptr = new ContChunk(_data + _curPos);
+Chunk *MemoryChunk::subBlock() {
+ MemoryChunk *ptr = new MemoryChunk(_data + _curPos);
seek(sizeof(Chunk::type) + sizeof(uint32) + ptr->getSize());
return ptr;
}
-bool ContChunk::eof() const {
- return _curPos >= _size;
-}
-
-uint32 ContChunk::tell() const {
- return _curPos;
-}
-
-bool ContChunk::seek(int32 delta, seek_type dir) {
- switch(dir) {
- case seek_cur:
- _curPos += delta;
- break;
- case seek_start:
- if(delta < 0) error("invalid seek request");
- _curPos = (uint32)delta;
- break;
- case seek_end:
- if(delta > 0 || _size < (uint32)-delta) error("invalid seek request");
- _curPos = (uint32)(_size + delta);
- break;
- }
- if(_curPos > _size) {
- error("invalid seek request : %d > %d (delta == %d)", _curPos, _size, delta);
- }
- return true;
-}
-
-bool ContChunk::read(void *buffer, uint32 size) {
+bool MemoryChunk::read(void *buffer, uint32 size) {
if(size <= 0 || (_curPos + size) > _size)
error("invalid buffer read request");
@@ -282,14 +249,14 @@
return true;
}
-int8 ContChunk::getChar() {
+int8 MemoryChunk::getChar() {
if(_curPos >= _size)
error("invalid char read request");
return _data[_curPos++];
}
-byte ContChunk::getByte() {
+byte MemoryChunk::getByte() {
if(_curPos >= _size)
error("invalid byte read request");
@@ -298,7 +265,7 @@
return *ptr;
}
-int16 ContChunk::getShort() {
+int16 MemoryChunk::getShort() {
if(_curPos >= _size - 1)
error("invalid int16 read request");
@@ -306,7 +273,7 @@
return *((int16 *)&buffer);
}
-uint16 ContChunk::getWord() {
+uint16 MemoryChunk::getWord() {
if(_curPos >= _size - 1)
error("invalid word read request");
@@ -315,7 +282,7 @@
return READ_LE_UINT16(ptr);
}
-uint32 ContChunk::getDword() {
+uint32 MemoryChunk::getDword() {
if(_curPos >= _size - 3)
error("invalid dword read request");
Index: chunk.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/chunk.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- chunk.h 17 Mar 2003 12:28:49 -0000 1.8
+++ chunk.h 25 May 2003 11:39:08 -0000 1.9
@@ -26,7 +26,6 @@
class Chunk {
public:
-
virtual ~Chunk() {};
enum seek_type { seek_start, seek_end, seek_cur };
typedef uint32 type;
@@ -47,28 +46,35 @@
class FilePtr;
-class FileChunk : public Chunk {
+// Common functionality for concrete chunks (FileChunk, MemoryChunk)
+class BaseChunk : public Chunk {
+protected:
+ Chunk::type _type;
+ uint32 _size;
+ uint32 _curPos;
+
+ BaseChunk();
+
+public:
+ Chunk::type getType() const;
+ uint32 getSize() const;
+ bool eof() const;
+ uint32 tell() const;
+ bool seek(int32 delta, seek_type dir = seek_cur);
+};
+
+class FileChunk : public BaseChunk {
private:
FilePtr *_data;
- type _type;
- uint32 _size;
uint32 _offset;
- uint32 _curPos;
protected:
-
FileChunk();
public:
-
FileChunk(const char *fname, const char *directory);
virtual ~FileChunk();
- type getType() const;
- uint32 getSize() const;
Chunk *subBlock();
- bool eof() const;
- uint32 tell() const;
- bool seek(int32 delta, seek_type dir = seek_cur);
bool read(void *buffer, uint32 size);
int8 getChar();
byte getByte();
@@ -77,23 +83,13 @@
uint32 getDword();
};
-class ContChunk : public Chunk {
+class MemoryChunk : public BaseChunk {
private:
-
byte *_data;
- Chunk::type _type;
- uint32 _size;
- uint32 _curPos;
public:
-
- ContChunk(byte *data);
- Chunk::type getType() const;
- uint32 getSize() const;
+ MemoryChunk(byte *data);
Chunk *subBlock();
- bool eof() const;
- uint32 tell() const;
- bool seek(int32 delta, seek_type dir = seek_cur);
bool read(void *buffer, uint32 size);
int8 getChar();
byte getByte();
Index: imuse_channel.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/imuse_channel.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- imuse_channel.cpp 30 Apr 2003 11:26:36 -0000 1.15
+++ imuse_channel.cpp 25 May 2003 11:39:08 -0000 1.16
@@ -216,7 +216,7 @@
case TYPE_MAP_:
_inData = false;
if(available_size >= (size + 8)) {
- ContChunk c((byte *)_tbuffer + offset);
+ MemoryChunk c((byte *)_tbuffer + offset);
handleMap(c);
}
break;
Index: saud_channel.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/saud_channel.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- saud_channel.cpp 30 Apr 2003 11:26:36 -0000 1.12
+++ saud_channel.cpp 25 May 2003 11:39:08 -0000 1.13
@@ -52,7 +52,7 @@
case TYPE_STRK:
_inData = false;
if(available_size >= (size + 8)) {
- ContChunk c((byte *)_tbuffer + offset);
+ MemoryChunk c((byte *)_tbuffer + offset);
handleStrk(c);
}
else
@@ -61,7 +61,7 @@
case TYPE_SMRK:
_inData = false;
if(available_size >= (size + 8)) {
- ContChunk c((byte *)_tbuffer + offset);
+ MemoryChunk c((byte *)_tbuffer + offset);
handleSmrk(c);
}
else
@@ -70,7 +70,7 @@
case TYPE_SHDR:
_inData = false;
if(available_size >= (size + 8)) {
- ContChunk c((byte *)_tbuffer + offset);
+ MemoryChunk c((byte *)_tbuffer + offset);
handleShdr(c);
}
else
More information about the Scummvm-git-logs
mailing list