From e2367f3ed2060b273559200b3e40f75a98bb6a6f Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Tue, 14 Nov 2017 22:30:35 -0600 Subject: FULLPIPE: Remove unnecessary and unsafe C-style casts --- engines/fullpipe/utils.h | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'engines/fullpipe/utils.h') diff --git a/engines/fullpipe/utils.h b/engines/fullpipe/utils.h index 2b97ab6480..8966ceb8ba 100644 --- a/engines/fullpipe/utils.h +++ b/engines/fullpipe/utils.h @@ -58,7 +58,17 @@ public: int readCount(); double readDouble(); CObject *parseClass(bool *isCopyReturned); - CObject *readClass(); + + template + T *readClass() { + CObject *obj = readBaseClass(); + if (!obj) + return nullptr; + + T *res = dynamic_cast(obj); + assert(res); + return res; + } void writeObject(CObject *obj); @@ -76,6 +86,7 @@ public: private: void init(); + CObject *readBaseClass(); }; enum ObjType { @@ -106,9 +117,24 @@ public: bool loadFile(const Common::String &fname); }; -class ObList : public Common::List, public CObject { +template +class ObList : public Common::List, public CObject { public: - virtual bool load(MfcArchive &file); + virtual bool load(MfcArchive &file) { + debugC(5, kDebugLoading, "ObList::load()"); + int count = file.readCount(); + + debugC(9, kDebugLoading, "ObList::count: %d:", count); + + for (int i = 0; i < count; i++) { + debugC(9, kDebugLoading, "ObList::[%d]", i); + T *t = file.readClass(); + + this->push_back(t); + } + + return true; + } }; class MemoryObject : CObject { -- cgit v1.2.3