aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobia Tesan2016-02-29 15:02:33 +0100
committerTobia Tesan2016-03-01 20:40:45 +0100
commit4926cc7cff3be8e63d590d6e1367f371e63655d5 (patch)
tree77fdc564de8756edf9f61ffe5ebf8bda0140be18
parent63e6473467700395725c893ff24b0e3926dac451 (diff)
downloadscummvm-rg350-4926cc7cff3be8e63d590d6e1367f371e63655d5.tar.gz
scummvm-rg350-4926cc7cff3be8e63d590d6e1367f371e63655d5.tar.bz2
scummvm-rg350-4926cc7cff3be8e63d590d6e1367f371e63655d5.zip
WINTERMUTE: Add CachedSourceListingProvider
-rw-r--r--engines/wintermute/debugger/listing_providers/cached_source_listing_provider.cpp80
-rw-r--r--engines/wintermute/debugger/listing_providers/cached_source_listing_provider.h52
-rw-r--r--engines/wintermute/module.mk1
3 files changed, 133 insertions, 0 deletions
diff --git a/engines/wintermute/debugger/listing_providers/cached_source_listing_provider.cpp b/engines/wintermute/debugger/listing_providers/cached_source_listing_provider.cpp
new file mode 100644
index 0000000000..20fe708380
--- /dev/null
+++ b/engines/wintermute/debugger/listing_providers/cached_source_listing_provider.cpp
@@ -0,0 +1,80 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "cached_source_listing_provider.h"
+#include "basic_source_listing_provider.h"
+#include "blank_listing_provider.h"
+#include "source_listing.h"
+
+namespace Wintermute {
+
+CachedSourceListingProvider::CachedSourceListingProvider() {
+ _sourceListingProvider = new BasicSourceListingProvider();
+ _fallbackListingProvider = new BlankListingProvider();
+}
+
+CachedSourceListingProvider::~CachedSourceListingProvider() {
+ delete _sourceListingProvider;
+ delete _fallbackListingProvider;
+ for (Common::HashMap<Common::String, SourceListing*>::iterator it = _cached.begin();
+ it != _cached.end(); it++) {
+ delete (it->_value);
+ }
+}
+
+Listing *CachedSourceListingProvider::getListing(const Common::String &filename, Wintermute::ErrorCode &error) {
+ if (_cached.contains(filename)) {
+ error = OK;
+ SourceListing *copy = new SourceListing(*_cached.getVal(filename));
+ return copy;
+ } else {
+ ErrorCode inner;
+ SourceListing *res = _sourceListingProvider->getListing(filename, inner);
+ if (inner == OK) {
+ SourceListing *copy = new SourceListing(*res);
+ _cached.setVal(filename, copy); // The cached copy is deleted on destruction
+ return res;
+ } else {
+ delete res;
+ return _fallbackListingProvider->getListing(filename, error);
+ }
+ }
+}
+
+void CachedSourceListingProvider::invalidateCache() {
+ for (Common::HashMap<Common::String, SourceListing*>::iterator it = _cached.begin();
+ it != _cached.end(); it++) {
+ delete (it->_value);
+ }
+ _cached.clear();
+}
+
+ErrorCode CachedSourceListingProvider::setPath(const Common::String &path) {
+ invalidateCache();
+ return _sourceListingProvider->setPath(path);
+}
+
+Common::String CachedSourceListingProvider::getPath() const {
+ return _sourceListingProvider->getPath();
+}
+
+} // End of namespace Wintermute
diff --git a/engines/wintermute/debugger/listing_providers/cached_source_listing_provider.h b/engines/wintermute/debugger/listing_providers/cached_source_listing_provider.h
new file mode 100644
index 0000000000..6e4925f2b4
--- /dev/null
+++ b/engines/wintermute/debugger/listing_providers/cached_source_listing_provider.h
@@ -0,0 +1,52 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef CACHED_LISTING_PROVIDER_H_
+#define CACHED_LISTING_PROVIDER_H_
+
+#include "common/hashmap.h"
+#include "common/hash-str.h"
+#include "engines/wintermute/debugger/error.h"
+#include "source_listing_provider.h"
+
+namespace Wintermute {
+
+class BasicSourceListingProvider;
+class BlankListingProvider;
+class Listing;
+
+class CachedSourceListingProvider : public SourceListingProvider {
+ BasicSourceListingProvider *_sourceListingProvider;
+ BlankListingProvider *_fallbackListingProvider;
+ Common::HashMap<Common::String, SourceListing *> _cached;
+ void invalidateCache();
+public:
+ CachedSourceListingProvider();
+ virtual ~CachedSourceListingProvider();
+ ErrorCode setPath(const Common::String &path);
+ Common::String getPath() const;
+ Listing *getListing(const Common::String &filename, ErrorCode &err);
+};
+
+} // End of namespace Wintermute
+
+#endif /* CACHED_LISTING_PROVIDER_H_ */
diff --git a/engines/wintermute/module.mk b/engines/wintermute/module.mk
index 1947a3f20b..22b3609c5f 100644
--- a/engines/wintermute/module.mk
+++ b/engines/wintermute/module.mk
@@ -96,6 +96,7 @@ MODULE_OBJS := \
debugger/listing_providers/blank_listing.o \
debugger/listing_providers/blank_listing_provider.o \
debugger/listing_providers/basic_source_listing_provider.o \
+ debugger/listing_providers/cached_source_listing_provider.o \
debugger/listing_providers/source_listing.o \
debugger/listing.o \
debugger/script_monitor.o \