[Scummvm-cvs-logs] SF.net SVN: scummvm: [22902] scummvm/trunk/engines/kyra

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sat Jun 3 20:30:14 CEST 2006


Revision: 22902
Author:   lordhoto
Date:     2006-06-03 11:30:07 -0700 (Sat, 03 Jun 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22902&view=rev

Log Message:
-----------
Changes some char* usage to Common::String.

Modified Paths:
--------------
    scummvm/trunk/engines/kyra/resource.cpp
    scummvm/trunk/engines/kyra/resource.h
Modified: scummvm/trunk/engines/kyra/resource.cpp
===================================================================
--- scummvm/trunk/engines/kyra/resource.cpp	2006-06-03 18:23:36 UTC (rev 22901)
+++ scummvm/trunk/engines/kyra/resource.cpp	2006-06-03 18:30:07 UTC (rev 22902)
@@ -148,9 +148,7 @@
 		PAKFile *file = new PAKFile(usedFilelist[tmp], (_engine->features() & GF_AMIGA) != 0);
 		assert(file);
 
-		PakFileEntry newPak;
-		newPak._file = file;
-		strncpy(newPak._filename, usedFilelist[tmp], 32);
+		PakFileEntry newPak(file, usedFilelist[tmp]);
 		if (file->isOpen() && file->isValid()) {
 			_pakfiles.push_back(newPak);
 		} else {
@@ -169,25 +167,23 @@
 	}
 }
 
-bool Resource::loadPakFile(const char *filename) {
+bool Resource::loadPakFile(const Common::String &filename) {
 	if (isInPakList(filename))
 		return true;
-	PAKFile *file = new PAKFile(filename);
+	PAKFile *file = new PAKFile(filename.c_str());
 	if (!file) {
-		warning("couldn't load file: '%s'", filename);
+		warning("couldn't load file: '%s'", filename.c_str());
 		return false;
 	}
-	PakFileEntry newPak;
-	newPak._file = file;
-	strncpy(newPak._filename, filename, 32);
+	PakFileEntry newPak(file, filename);
 	_pakfiles.push_back(newPak);
 	return true;
 }
 
-void Resource::unloadPakFile(const char *filename) {
+void Resource::unloadPakFile(const Common::String &filename) {
 	Common::List<PakFileEntry>::iterator start = _pakfiles.begin();
 	for (;start != _pakfiles.end(); ++start) {
-		if (scumm_stricmp(start->_filename, filename) == 0) {
+		if (scumm_stricmp(start->_filename.c_str(), filename.c_str()) == 0) {
 			delete start->_file;
 			_pakfiles.erase(start);
 			break;
@@ -196,10 +192,10 @@
 	return;
 }
 
-bool Resource::isInPakList(const char *filename) {
+bool Resource::isInPakList(const Common::String &filename) {
 	Common::List<PakFileEntry>::iterator start = _pakfiles.begin();
 	for (;start != _pakfiles.end(); ++start) {
-		if (scumm_stricmp(start->_filename, filename) == 0)
+		if (scumm_stricmp(start->_filename.c_str(), filename.c_str()) == 0)
 			return true;
 	}
 	return false;
@@ -266,8 +262,7 @@
 ///////////////////////////////////////////
 // Pak file manager
 #define PAKFile_Iterate Common::List<PakChunk>::iterator start=_files.begin();start != _files.end(); ++start
-PAKFile::PAKFile(const Common::String& file, bool isAmiga) {
-	_filename = 0;
+PAKFile::PAKFile(const char *file, bool isAmiga) {
 	_isAmiga = isAmiga;
 
 	Common::File pakfile;
@@ -275,7 +270,7 @@
 	_open = false;
 
 	if (!pakfile.open(file)) {
-		debug(3, "couldn't open pakfile '%s'\n", file.c_str());
+		debug(3, "couldn't open pakfile '%s'\n", file);
 		return;
 	}
 
@@ -300,11 +295,9 @@
 		PakChunk chunk;
 
 		// saves the name
-		int strLen = strlen((const char*)buffer + pos) + 1;
-		assert(ARRAYSIZE(chunk._name) > strLen);
-		strncpy(chunk._name, (const char*)buffer + pos, ARRAYSIZE(chunk._name));
-		pos += strlen(chunk._name) + 1;
-		if (!(*chunk._name))
+		chunk._name = (const char*)buffer + pos;
+		pos += strlen(chunk._name.c_str()) + 1;
+		if (!(chunk._name[0]))
 			break;
 
 		if (!_isAmiga) {
@@ -331,14 +324,11 @@
 	_open = true;
 	delete [] buffer;
 	
-	_filename = new char[file.size()+1];
-	assert(_filename);
-	strcpy(_filename, file.c_str());
+	_filename = file;
 }
 
 PAKFile::~PAKFile() {
-	delete [] _filename;
-	_filename = 0;
+	_filename.clear();
 	_open = false;
 
 	_files.clear();
@@ -346,10 +336,10 @@
 
 uint8 *PAKFile::getFile(const char *file) {
 	for (PAKFile_Iterate) {
-		if (!scumm_stricmp(start->_name, file)) {
+		if (!scumm_stricmp(start->_name.c_str(), file)) {
 			Common::File pakfile;
 			if (!pakfile.open(_filename)) {
-				debug(3, "couldn't open pakfile '%s'\n", _filename);
+				debug(3, "couldn't open pakfile '%s'\n", _filename.c_str());
 				return 0;
 			}
 			pakfile.seek(start->_start);
@@ -366,9 +356,9 @@
 	filehandle.close();
 
 	for (PAKFile_Iterate) {
-		if (!scumm_stricmp(start->_name, file)) {
+		if (!scumm_stricmp(start->_name.c_str(), file)) {
 			if (!filehandle.open(_filename)) {
-				debug(3, "couldn't open pakfile '%s'\n", _filename);
+				debug(3, "couldn't open pakfile '%s'\n", _filename.c_str());
 				return 0;
 			}
 			filehandle.seek(start->_start);
@@ -380,7 +370,7 @@
 
 uint32 PAKFile::getFileSize(const char* file) {
 	for (PAKFile_Iterate) {
-		if (!scumm_stricmp(start->_name, file))
+		if (!scumm_stricmp(start->_name.c_str(), file))
 			return start->_size;
 	}
 	return 0;

Modified: scummvm/trunk/engines/kyra/resource.h
===================================================================
--- scummvm/trunk/engines/kyra/resource.h	2006-06-03 18:23:36 UTC (rev 22901)
+++ scummvm/trunk/engines/kyra/resource.h	2006-06-03 18:30:07 UTC (rev 22902)
@@ -36,28 +36,26 @@
 // standard Package format for Kyrandia games
 class PAKFile {
 	struct PakChunk {
-		char _name[32];
+		Common::String _name;
 		uint32 _start;
 		uint32 _size;
 	};
 
 public:
-
-	PAKFile(const Common::String &file, bool isAmiga = false);
+	PAKFile(const char *file, bool isAmiga = false);
 	~PAKFile();
 
-	uint8* getFile(const char *file);
+	uint8 *getFile(const char *file);
 	bool getFileHandle(const char *file, Common::File &filehandle);
 	uint32 getFileSize(const char *file);
 
-	bool isValid(void) const { return (_filename != 0); }
+	bool isValid(void) const { return !(_filename.empty()); }
 	bool isOpen(void) const { return _open; }
 
 private:
-
 	bool _open;
 	bool _isAmiga;
-	char *_filename;
+	Common::String _filename;
 	Common::List<PakChunk> _files; // the entries
 };
 
@@ -66,9 +64,9 @@
 	Resource(KyraEngine *engine);
 	~Resource();
 	
-	bool loadPakFile(const char *filename);
-	void unloadPakFile(const char *filename);
-	bool isInPakList(const char *filename);
+	bool loadPakFile(const Common::String &filename);
+	void unloadPakFile(const Common::String &filename);
+	bool isInPakList(const Common::String &filename);
 
 	uint8* fileData(const char *file, uint32 *size);
 	// it gives back a file handle (used for the speech player)
@@ -77,12 +75,18 @@
 	bool fileHandle(const char *file, uint32 *size, Common::File &filehandle);
 
 protected:
-	struct PakFileEntry {
+	class PakFileEntry {
+	public:
+		PakFileEntry(PAKFile *file, const Common::String str) : _file(file), _filename(str) {}
+		PakFileEntry(const PakFileEntry &c) : _file(c._file), _filename(c._filename) {}
+
 		PAKFile *_file;
-		char _filename[32];
+		const Common::String _filename;
+	private:
+		PakFileEntry &operator =(const PakFileEntry &c) { return *this; }
 	};
 
-	KyraEngine* _engine;
+	KyraEngine *_engine;
 	Common::List<PakFileEntry> _pakfiles;
 };
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list