From 1460947005f40e7abf6aa891f097cfc518b60ef9 Mon Sep 17 00:00:00 2001 From: stephena Date: Fri, 26 Dec 2014 17:19:36 +0000 Subject: [PATCH] Move ZipHandler from OSystem directly into FSNodeZip class, since it's the only class that uses it. This is in preparation for improvements to ZIP file handling. Use emplace_back instead of push_back in several places, as it's faster. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3121 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- src/common/FSNodeZIP.cxx | 11 +++++++---- src/common/FSNodeZIP.hxx | 18 ++++++++++++++++++ src/emucore/FSNode.cxx | 2 +- src/emucore/OSystem.cxx | 6 ------ src/emucore/OSystem.hxx | 15 --------------- src/unix/FSNodePOSIX.cxx | 6 +++--- src/windows/FSNodeWINDOWS.cxx | 4 ++-- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/common/FSNodeZIP.cxx b/src/common/FSNodeZIP.cxx index dfb146d1a..8ebc6aa41 100644 --- a/src/common/FSNodeZIP.cxx +++ b/src/common/FSNodeZIP.cxx @@ -45,7 +45,7 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p) _zipFile = p.substr(0, pos+4); // Open file at least once to initialize the virtual file count - ZipHandler& zip = OSystem::zip(_zipFile); + ZipHandler& zip = open(_zipFile); _numFiles = zip.romFiles(); if(_numFiles == 0) { @@ -123,11 +123,11 @@ bool FilesystemNodeZIP::getChildren(AbstractFSList& myList, ListMode mode, if(!isDirectory() || _error != ZIPERR_NONE) return false; - ZipHandler& zip = OSystem::zip(_zipFile); + ZipHandler& zip = open(_zipFile); while(zip.hasNext()) { FilesystemNodeZIP entry(_path, zip.next(), _realNode); - myList.push_back(new FilesystemNodeZIP(entry)); + myList.emplace_back(new FilesystemNodeZIP(entry)); } return true; @@ -144,7 +144,7 @@ uInt32 FilesystemNodeZIP::read(uInt8*& image) const case ZIPERR_NO_ROMS: throw "ZIP file doesn't contain any ROMs"; } - ZipHandler& zip = OSystem::zip(_zipFile); + ZipHandler& zip = open(_zipFile); bool found = false; while(zip.hasNext() && !found) @@ -158,3 +158,6 @@ AbstractFSNode* FilesystemNodeZIP::getParent() const { return _realNode ? _realNode->getParent() : nullptr; } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +unique_ptr FilesystemNodeZIP::myZipHandler = make_ptr(); diff --git a/src/common/FSNodeZIP.hxx b/src/common/FSNodeZIP.hxx index 93b1711eb..d27d5d94e 100644 --- a/src/common/FSNodeZIP.hxx +++ b/src/common/FSNodeZIP.hxx @@ -20,6 +20,7 @@ #ifndef FS_NODE_ZIP_HXX #define FS_NODE_ZIP_HXX +#include "ZipHandler.hxx" #include "FSNode.hxx" /* @@ -74,6 +75,15 @@ class FilesystemNodeZIP : public AbstractFSNode void setFlags(const string& zipfile, const string& virtualfile, shared_ptr realnode); + friend ostream& operator<<(ostream& os, const FilesystemNodeZIP& node) + { + os << "_zipFile: " << node._zipFile << endl + << "_virtualFile: " << node._virtualFile << endl + << "_path: " << node._path << endl + << "_shortPath: " << node._shortPath << endl; + return os; + } + private: /* Error types */ enum zip_error @@ -89,6 +99,14 @@ class FilesystemNodeZIP : public AbstractFSNode string _path, _shortPath; zip_error _error; uInt32 _numFiles; + + // ZIP static reference variable responsible for accessing ZIP files + static unique_ptr myZipHandler; + static ZipHandler& open(const string& file) + { + myZipHandler->open(file); + return *myZipHandler; + } }; #endif diff --git a/src/emucore/FSNode.cxx b/src/emucore/FSNode.cxx index 43d41923a..4968cbb4f 100644 --- a/src/emucore/FSNode.cxx +++ b/src/emucore/FSNode.cxx @@ -70,7 +70,7 @@ bool FilesystemNode::getChildren(FSList& fslist, ListMode mode, bool hidden) con return false; for (const auto& i: tmp) - fslist.push_back(FilesystemNode(i)); + fslist.emplace_back(FilesystemNode(i)); return true; } diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 17513314f..9c1e314d1 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -159,9 +159,6 @@ bool OSystem::create() // Create PNG handler myPNGLib = make_ptr(*myFrameBuffer); - // Create ZIP handler - myZipHandler = make_ptr(); - return true; } @@ -690,6 +687,3 @@ void OSystem::mainLoop() myCheatManager->saveCheatDatabase(); #endif } - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -unique_ptr OSystem::myZipHandler = unique_ptr(); diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index 4d757caf2..4e4ff0789 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -39,7 +39,6 @@ class VideoDialog; #include "FSNode.hxx" #include "FrameBuffer.hxx" #include "PNGLibrary.hxx" -#include "ZipHandler.hxx" #include "bspf.hxx" struct TimingInfo { @@ -173,17 +172,6 @@ class OSystem */ PNGLibrary& png() const { return *myPNGLib; } - /** - Get the ZIP handler of the system. - - @return The ZIP object, using the given file - */ - static ZipHandler& zip(const string& file) - { - myZipHandler->open(file); - return *myZipHandler; - } - /** This method should be called to load the current settings from an rc file. It first loads the settings from the config file, then informs subsystems @@ -506,9 +494,6 @@ class OSystem // Indicates whether to stop the main loop bool myQuitLoop; - // ZIP static reference variable responsible for accessing ZIP files - static unique_ptr myZipHandler; - private: string myBaseDir; string myStateDir; diff --git a/src/unix/FSNodePOSIX.cxx b/src/unix/FSNodePOSIX.cxx index a453f6d6d..1dba2dd8f 100644 --- a/src/unix/FSNodePOSIX.cxx +++ b/src/unix/FSNodePOSIX.cxx @@ -195,7 +195,7 @@ bool FilesystemNodePOSIX::getChildren(AbstractFSList& myList, ListMode mode, (mode == FilesystemNode::kListDirectoriesOnly && !entry._isDirectory)) continue; - myList.push_back(new FilesystemNodePOSIX(entry)); + myList.emplace_back(new FilesystemNodePOSIX(entry)); } closedir(dirp); @@ -256,8 +256,8 @@ AbstractFSNode* FilesystemNodePOSIX::getParent() const if (_path == "/") return nullptr; - const char *start = _path.c_str(); - const char *end = lastPathComponent(_path); + const char* start = _path.c_str(); + const char* end = lastPathComponent(_path); return new FilesystemNodePOSIX(string(start, end - start)); } diff --git a/src/windows/FSNodeWINDOWS.cxx b/src/windows/FSNodeWINDOWS.cxx index e5fd04aea..1ec37d76c 100644 --- a/src/windows/FSNodeWINDOWS.cxx +++ b/src/windows/FSNodeWINDOWS.cxx @@ -149,7 +149,7 @@ void FilesystemNodeWINDOWS::addFile(AbstractFSList& list, ListMode mode, entry._isValid = true; entry._isPseudoRoot = false; - list.push_back(new FilesystemNodeWINDOWS(entry)); + list.emplace_back(new FilesystemNodeWINDOWS(entry)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -244,7 +244,7 @@ bool FilesystemNodeWINDOWS:: entry._isValid = true; entry._isPseudoRoot = false; entry._path = toAscii(current_drive); - myList.push_back(new FilesystemNodeWINDOWS(entry)); + myList.emplace_back(new FilesystemNodeWINDOWS(entry)); } } else