[Scummvm-cvs-logs] SF.net SVN: scummvm: [28026] scummex/branches/gsoc2007-gameresbrowser/src
zbychs at users.sourceforge.net
zbychs at users.sourceforge.net
Wed Jul 11 15:04:07 CEST 2007
Revision: 28026
http://scummvm.svn.sourceforge.net/scummvm/?rev=28026&view=rev
Author: zbychs
Date: 2007-07-11 06:04:06 -0700 (Wed, 11 Jul 2007)
Log Message:
-----------
Changing the project structure.
The building is broken at the moment.
Last good version is 28025.
Modified Paths:
--------------
scummex/branches/gsoc2007-gameresbrowser/src/ReadMe.txt
scummex/branches/gsoc2007-gameresbrowser/src/core/plugin_detail.h
scummex/branches/gsoc2007-gameresbrowser/src/gui/MainFormCommands.cpp
scummex/branches/gsoc2007-gameresbrowser/src/gui/Test2.cpp
Added Paths:
-----------
scummex/branches/gsoc2007-gameresbrowser/src/browser/
scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreFileTypes.cpp
scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreFileTypes.h
scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreInterfaces.cpp
scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreInterfaces.h
scummex/branches/gsoc2007-gameresbrowser/src/browser/FileType.h
scummex/branches/gsoc2007-gameresbrowser/src/browser/FileTypeRecognizer.h
scummex/branches/gsoc2007-gameresbrowser/src/core/FileTypeRegistry.h
scummex/branches/gsoc2007-gameresbrowser/src/core/ObjectRegistry.cpp
scummex/branches/gsoc2007-gameresbrowser/src/core/ObjectRegistry.h
scummex/branches/gsoc2007-gameresbrowser/src/core/ftregistry.cpp
scummex/branches/gsoc2007-gameresbrowser/src/so/
scummex/branches/gsoc2007-gameresbrowser/src/so/plugin1/
Removed Paths:
-------------
scummex/branches/gsoc2007-gameresbrowser/src/core/CoreFileTypes.cpp
scummex/branches/gsoc2007-gameresbrowser/src/core/CoreFileTypes.h
scummex/branches/gsoc2007-gameresbrowser/src/core/CoreInterfaces.cpp
scummex/branches/gsoc2007-gameresbrowser/src/core/CoreInterfaces.h
scummex/branches/gsoc2007-gameresbrowser/src/core/FileType.h
scummex/branches/gsoc2007-gameresbrowser/src/core/FileTypeRecognizer.h
scummex/branches/gsoc2007-gameresbrowser/src/core/ftregistry.h
scummex/branches/gsoc2007-gameresbrowser/src/core/oregistry.cpp
scummex/branches/gsoc2007-gameresbrowser/src/core/oregistry.h
scummex/branches/gsoc2007-gameresbrowser/src/plugins/ftregistry.cpp
Modified: scummex/branches/gsoc2007-gameresbrowser/src/ReadMe.txt
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/ReadMe.txt 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/ReadMe.txt 2007-07-11 13:04:06 UTC (rev 28026)
@@ -5,8 +5,9 @@
Directories:
core - core files (pins/slots/plugins/registries/objects...)
- gui - wxWidgets gui
- plugins - plugins
+ browser - all the browser specific classes (plugins can use core and browser)
+ gui - wxWidgets browser gui (plugins can't use this)
+ plugins - plugins (including the basic ones)
samples - sample usages of the core/gui modules
Copied: scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreFileTypes.cpp (from rev 28002, scummex/branches/gsoc2007-gameresbrowser/src/core/CoreFileTypes.cpp)
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreFileTypes.cpp (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreFileTypes.cpp 2007-07-11 13:04:06 UTC (rev 28026)
@@ -0,0 +1,49 @@
+/////////////////////////////////////////////////////////////////////////////
+// CoreFileTypes.cpp
+
+#include "core_stdafx.h"
+
+#include "CoreFileTypes.h"
+
+#include "debugmem.h"
+
+namespace Browser {
+
+namespace CoreFileTypes {
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// FileTypes
+
+SAFE_STATIC(binaryFileTypeGUID, BGUID, (wxT("CoreFileTypes"), wxT("Binary File"), 1) )
+
+SAFE_STATIC(bmpFileTypeGUID, BGUID, (wxT("CoreFileTypes"), wxT("Windows Bitmap File (BMP)"), 1) )
+
+SAFE_STATIC(textFileTypeGUID, BGUID, (wxT("CoreFileTypes"), wxT("Text File"), 1) )
+
+SAFE_STATIC(rootDirectoryFileType, RecognizedFileType,
+ (PERFECT_MATCH, BGUID(wxT("CoreFileTypes"), wxT("Root Directory"), 1)) )
+
+SAFE_STATIC(diskDirectoryFileType, RecognizedFileType,
+ (PERFECT_MATCH, BGUID(wxT("CoreFileTypes"), wxT("Disk Directory"), 1)) )
+
+//CAUTION: NO_MATCH here - so that Disk File is not considered a valid file type (it's only for informational/debug purposes)
+SAFE_STATIC(diskFileFileType, RecognizedFileType,
+ (NO_MATCH, BGUID(wxT("CoreFileTypes"), wxT("Disk File"), 1)) )
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// Presenters TODO: move it to a different header
+
+SAFE_STATIC(fileInfoPresenterGUID, BGUID, (wxT("CoreObjects"), wxT("FileInfoPresenter"), 1) )
+
+SAFE_STATIC(textParserGUID, BGUID, (wxT("CoreObjects"), wxT("TextParser"), 1) )
+SAFE_STATIC(binaryParserGUID, BGUID, (wxT("CoreObjects"), wxT("BinaryParser"), 1) )
+SAFE_STATIC(bmpParserGUID, BGUID, (wxT("CoreObjects"), wxT("BMPParser"), 1) )
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+} // namespace CoreFileTypes
+
+} // namespace Browser
Copied: scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreFileTypes.h (from rev 28002, scummex/branches/gsoc2007-gameresbrowser/src/core/CoreFileTypes.h)
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreFileTypes.h (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreFileTypes.h 2007-07-11 13:04:06 UTC (rev 28026)
@@ -0,0 +1,50 @@
+/////////////////////////////////////////////////////////////////////////////
+// CoreFileTypes.h
+
+#ifndef _CORE_FILE_TYPES_H_
+#define _CORE_FILE_TYPES_H_
+
+#include "guid.h"
+#include "FileType.h"
+
+#include "safe_static.h"
+
+namespace Browser {
+
+namespace CoreFileTypes {
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// FileTypes
+
+SAFE_STATIC_DECL(binaryFileTypeGUID, BGUID)
+
+SAFE_STATIC_DECL(bmpFileTypeGUID, BGUID)
+
+SAFE_STATIC_DECL(textFileTypeGUID, BGUID)
+
+SAFE_STATIC_DECL(rootDirectoryFileType, RecognizedFileType)
+
+SAFE_STATIC_DECL(diskDirectoryFileType, RecognizedFileType)
+
+//CAUTION: NO_MATCH here - so that Disk File is not considered a valid file type (it's only for informational/debug purposes)
+SAFE_STATIC_DECL(diskFileFileType, RecognizedFileType)
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// Presenters TODO: move it to a different header
+
+SAFE_STATIC_DECL(fileInfoPresenterGUID, BGUID)
+
+SAFE_STATIC_DECL(textParserGUID, BGUID)
+SAFE_STATIC_DECL(binaryParserGUID, BGUID)
+SAFE_STATIC_DECL(bmpParserGUID, BGUID)
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+} // namespace CoreFileTypes
+
+} // namespace Browser
+
+#endif // _CORE_FILE_TYPES_H_
Copied: scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreInterfaces.cpp (from rev 28002, scummex/branches/gsoc2007-gameresbrowser/src/core/CoreInterfaces.cpp)
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreInterfaces.cpp (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreInterfaces.cpp 2007-07-11 13:04:06 UTC (rev 28026)
@@ -0,0 +1,164 @@
+/////////////////////////////////////////////////////////////////////////////
+// CoreInterfaces.cpp
+
+#include "core_stdafx.h"
+
+#include "CoreInterfaces.h"
+#include "CoreFileTypes.h"
+#include "common/simplefile.h"
+
+#include <iostream>
+
+#include "debugmem.h"
+
+namespace Browser {
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// Concrete implementations of the interfaces
+
+IDirectoryImpl::IDirectoryImpl(IDirectory* parentDir, coreString name,
+ bool ownInterfaces)
+ : _parentDir(parentDir), _name(name), _ifiles(), _isubdirs(),
+ _ownInterfaces(ownInterfaces), _fileType(RecognizedFileType::NotRecognized()) {}
+
+IDirectoryImpl::IDirectoryImpl(IDirectory* parentDir, coreString name,
+ const ifile_list& ifiles, const idir_list& isubdirs,
+ bool ownInterfaces)
+ : _parentDir(parentDir), _name(name), _ifiles(ifiles), _isubdirs(isubdirs),
+ _ownInterfaces(ownInterfaces), _fileType(RecognizedFileType::NotRecognized()) {}
+
+IDirectoryImpl::~IDirectoryImpl() {
+ if (!_ownInterfaces)
+ return;
+
+ std::list<IFile*>::const_iterator i;
+ for (i = _ifiles.begin(); i != _ifiles.end(); ++i) {
+ delete *i;
+ }
+
+ std::list<IDirectory*>::const_iterator j;
+ for (j = _isubdirs.begin(); j != _isubdirs.end(); ++j) {
+ delete *j;
+ }
+}
+
+const coreString& IDirectoryImpl::getName() {
+ return _name;
+}
+
+IDirectory* IDirectoryImpl::getParentDirectory() {
+ return _parentDir;
+}
+
+const RecognizedFileType& IDirectoryImpl::getDirectoryFileType() {
+ return _fileType;
+}
+
+void IDirectoryImpl::setDirectoryFileType(const RecognizedFileType& fileType) {
+ _fileType = fileType;
+}
+
+const ifile_list& IDirectoryImpl::getFiles() {
+ //infoout << wxT("IDirectoryImpl::getFiles()") << std::endl;
+ return _ifiles;
+}
+
+const idir_list& IDirectoryImpl::getSubDirs() {
+ //infoout << wxT("IDirectoryImpl::getSubDirs()") << std::endl;
+ return _isubdirs;
+}
+
+void IDirectoryImpl::addFile(IFile* ifile) {
+ _ifiles.push_back(ifile);
+}
+
+void IDirectoryImpl::addSubDir(IDirectory* idir) {
+ _isubdirs.push_back(idir);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+IStreamImpl::IStreamImpl(Common::SeekableReadStream* stream, bool ownStream /*= false*/)
+ : _stream(stream), _ownStream(ownStream) {}
+
+Common::SeekableReadStream* IStreamImpl::getStream() {
+ return _stream;
+}
+
+IStreamImpl::~IStreamImpl() {
+ if (_ownStream)
+ delete _stream;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+IFileImplBase::IFileImplBase(IDirectory* parentDir, coreString name)
+ : _parentDir(parentDir), _name(name),
+ _fileType(RecognizedFileType::NotRecognized()) {}
+
+const coreString& IFileImplBase::getName() {
+ return _name;
+}
+
+const RecognizedFileType& IFileImplBase::getFileType() {
+ return _fileType;
+}
+
+void IFileImplBase::setFileType(const RecognizedFileType& fileType) {
+ _fileType = fileType;
+}
+
+IDirectory* IFileImplBase::getParentDirectory() {
+ return _parentDir;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+IStreamFileImpl::IStreamFileImpl(IDirectory* parentDir, coreString name, Common::SeekableReadStream* stream, bool ownStream /*= false*/)
+ : IFileImplBase(parentDir, name), _streamImpl(stream, ownStream) {}
+
+Common::SeekableReadStream* IStreamFileImpl::getStream() {
+ return _streamImpl.getStream();
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+IDiskFileImpl::IDiskFileImpl(IDirectory* parentDir, coreString name, coreString fullpath)
+ : IFileImplBase(parentDir, name), _fullpath(fullpath), _stream(NULL) {
+ _fileType = CoreFileTypes::diskFileFileType();
+ }
+
+IDiskFileImpl::~IDiskFileImpl() {
+ diet();
+}
+
+void IDiskFileImpl::diet() {
+ if (_stream)
+ delete _stream;
+ _stream = NULL;
+}
+
+Common::SeekableReadStream* IDiskFileImpl::getStream() {
+ if (!_stream) {
+ Common::SimpleFile* file = new Common::SimpleFile();
+ bool res = file->open(_fullpath);
+ if (!res) {
+ errout << wxT("ERROR: IDiskFileImpl::getStream(): could not open file") << std::endl;
+ delete file;
+ return NULL;
+ }
+ _stream = file;
+ }
+
+ return _stream;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+} // namespace Browser
Copied: scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreInterfaces.h (from rev 28002, scummex/branches/gsoc2007-gameresbrowser/src/core/CoreInterfaces.h)
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreInterfaces.h (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/browser/CoreInterfaces.h 2007-07-11 13:04:06 UTC (rev 28026)
@@ -0,0 +1,279 @@
+/////////////////////////////////////////////////////////////////////////////
+// CoreInterfaces.h
+
+#ifndef _CORE_INTERFACES_H_
+#define _CORE_INTERFACES_H_
+
+#include "core_stdafx.h"
+
+#include "pinslot.h"
+#include "FileType.h"
+
+#include <list>
+#include "common/stream.h"
+
+namespace Browser {
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// Interfaces
+
+template<typename T>
+class IProvider : public IInterface {
+public:
+ ASSIGN_GUID_VERBOSE( toString(typeid(IProvider<T>).name()), wxT("CoreInterfaces"), 1);
+ virtual T* getData() = 0;
+ virtual void release() {
+ delete this;
+ }
+};
+
+template<typename T>
+class IProviderImpl : public IProvider<T> {
+ bool _ownData;
+ T* _data;
+public:
+ IProviderImpl(T* data, bool ownData = false)
+ : _data(data), _ownData(ownData) {}
+ virtual ~IProviderImpl() {
+ if (_ownData && _data)
+ delete _data;
+ }
+ virtual T* getData() {
+ return _data;
+ }
+ virtual void setData(T* data) {
+ _data = data;
+ }
+ virtual void release() {
+ delete this;
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+class IStream : public IInterface {
+public:
+ GUID_FOR(IStream, wxT("CoreInterfaces"), 1);
+ virtual Common::SeekableReadStream* getStream() = 0;
+};
+
+class IDirectory;
+
+class IFile : public IStream {
+public:
+ GUID_FOR(IFile, wxT("CoreInterfaces"), 1);
+ virtual const coreString& getName() = 0;
+
+ //can be not set (returns a file type that is !isOk())
+ virtual const RecognizedFileType& getFileType() = 0;
+ virtual void setFileType(const RecognizedFileType& fileType) = 0;
+
+ //can return NULL
+ virtual IDirectory* getParentDirectory() = 0;
+};
+
+//TODO: IDirectory should support get/release semantics for IFiles
+// It would enable disk files once opened, to be closed, memory
+// once allocated, to be freed when not used anymore.
+// Do it via dynamic dummy Slots?
+class IDirectory : public IInterface {
+public:
+ GUID_FOR(IDirectory, wxT("CoreInterfaces"), 1);
+ virtual const coreString& getName() = 0;
+ virtual const std::list<IFile*>& getFiles() = 0;
+ virtual const std::list<IDirectory*>& getSubDirs() = 0;
+
+ //can be not set (returns a file type that is !isOk())
+ //it is a helper for recognizing files based on the type of the container
+ //they are in (i.e. file with magic BM can be a BMP, but if it is in an XXX
+ //container, then we know it's something else).
+ virtual const RecognizedFileType& getDirectoryFileType() = 0;
+
+ //can return NULL
+ virtual IDirectory* getParentDirectory() = 0;
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+typedef std::list<IFile*> ifile_list;
+typedef std::list<IDirectory*> idir_list;
+
+class IDirectoryImpl : public IDirectory {
+
+protected:
+ coreString _name;
+ RecognizedFileType _fileType;
+ IDirectory* _parentDir;
+
+ bool _ownInterfaces;
+ ifile_list _ifiles;
+ idir_list _isubdirs;
+
+public:
+ //inherit guid - it's a concrete implementation of an abstract interface
+ IDirectoryImpl(IDirectory* parentDir, coreString name,
+ bool ownInterfaces);
+ IDirectoryImpl(IDirectory* parentDir, coreString name,
+ const ifile_list& ifiles, const idir_list& isubdirs,
+ bool ownInterfaces);
+ virtual ~IDirectoryImpl();
+
+ virtual const coreString& getName();
+
+ virtual const RecognizedFileType& getDirectoryFileType();
+ virtual void setDirectoryFileType(const RecognizedFileType& fileType); //not in IDirectory interface
+
+ //can return NULL
+ virtual IDirectory* getParentDirectory();
+
+ void addFile(IFile* ifile);
+ void addSubDir(IDirectory* idir);
+
+ virtual const ifile_list& getFiles();
+ virtual const idir_list& getSubDirs();
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// Concrete implementations of the interfaces
+
+class IStreamImpl : public IStream {
+protected:
+ Common::SeekableReadStream* _stream;
+ bool _ownStream;
+public:
+ //inherit guid - it's a concrete implementation of an abstract interface
+ IStreamImpl(Common::SeekableReadStream* stream, bool ownStream = false);
+ virtual Common::SeekableReadStream* getStream();
+ virtual ~IStreamImpl();
+};
+
+// Limitation: can't inherit from IFile and IStreamImpl, cause I'll have to inherit
+// virtually from IStream to IStreamImpl and from IStream to IFile. It can't be done,
+// since virtual inheritance disallows casting from virtual base class (here:
+// IInterface) to a derived class (here: IFile).
+// Instead of multiple inheritance - I use encapsulation: _streamImpl member.
+class IFileImplBase : public IFile {
+protected:
+ coreString _name;
+ RecognizedFileType _fileType;
+ IDirectory* _parentDir;
+public:
+ //inherit guid - it's a concrete implementation of an abstract interface
+ IFileImplBase(IDirectory* parentDir, coreString name);
+ virtual const coreString& getName();
+ virtual Common::SeekableReadStream* getStream() = 0;
+
+ //can be not set (returns a file type that is !isOk())
+ virtual const RecognizedFileType& getFileType();
+ virtual void setFileType(const RecognizedFileType& fileType);
+
+ //can return NULL
+ virtual IDirectory* getParentDirectory();
+};
+
+class IStreamFileImpl : public IFileImplBase {
+protected:
+ IStreamImpl _streamImpl;
+public:
+ //inherit guid - it's a concrete implementation of an abstract interface
+ IStreamFileImpl(IDirectory* parentDir, coreString name, Common::SeekableReadStream* stream, bool ownStream = false);
+ virtual Common::SeekableReadStream* getStream();
+};
+
+class IDiskFileImpl : public IFileImplBase {
+protected:
+ coreString _fullpath;
+ Common::SeekableReadStream* _stream;
+public:
+ //inherit guid - it's a concrete implementation of an abstract interface
+ IDiskFileImpl(IDirectory* parentDir, coreString name, coreString fullpath);
+ virtual ~IDiskFileImpl();
+ virtual Common::SeekableReadStream* getStream();
+
+ //closes the underlying file, getStream() will reopen it if needed
+ virtual void diet();
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+//to be used by TextPresenter, so it has a title and the text
+class IText : public IInterface {
+public:
+ GUID_FOR(IText, wxT("CoreInterfaces"), 1);
+ virtual bool isMonospace() = 0;
+ virtual const wxString& getTitle() = 0;
+ virtual const wxString& getText() = 0;
+ virtual void release() {
+ delete this;
+ }
+};
+
+class ITextImpl : public IText {
+ wxString _title;
+ wxString _text;
+ bool _monospace;
+public:
+ ITextImpl(const wxString& title, const wxString& text, bool monospace = false)
+ : _title(title), _text(text), _monospace(monospace) {}
+
+ virtual bool isMonospace() {
+ return _monospace;
+ }
+ virtual void setMonospace(bool monospace) {
+ _monospace = monospace;
+ }
+ virtual const wxString& getTitle() {
+ return _title;
+ }
+ virtual const wxString& getText() {
+ return _text;
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+//to be used by HtmlPresenter, so it has a title and url
+class IUrl : public IInterface {
+public:
+ GUID_FOR(IUrl, wxT("CoreInterfaces"), 1);
+ virtual bool isEmpty() = 0;
+ virtual const wxString& getTitle() = 0;
+ virtual const wxString& getUrl() = 0;
+ virtual void release() {
+ delete this;
+ }
+};
+
+class IUrlImpl : public IUrl {
+ wxString _title;
+ wxString _url;
+ bool _empty;
+public:
+ IUrlImpl(const wxString& title)
+ : _title(title), _empty(true) {}
+ IUrlImpl(const wxString& title, const wxString& url)
+ : _title(title), _url(url), _empty(false) {}
+
+ virtual bool isEmpty() {
+ return _empty;
+ }
+ virtual const wxString& getTitle() {
+ return _title;
+ }
+ virtual const wxString& getUrl() {
+ return _url;
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+} // namespace Browser
+
+#endif // _CORE_INTERFACES_H_
Copied: scummex/branches/gsoc2007-gameresbrowser/src/browser/FileType.h (from rev 28002, scummex/branches/gsoc2007-gameresbrowser/src/core/FileType.h)
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/browser/FileType.h (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/browser/FileType.h 2007-07-11 13:04:06 UTC (rev 28026)
@@ -0,0 +1,84 @@
+/////////////////////////////////////////////////////////////////////////////
+// FileType.h
+
+#ifndef _FILE_TYPE_H_
+#define _FILE_TYPE_H_
+
+#include <list>
+
+namespace Browser {
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+// When a VirtualFile is to be presented the following happens:
+// - recognize() is run on all FileTypeRecognizers found
+// -- we get a list of file type GUID's
+// - we find all FileTypeParsers for each file type GUID and choose one of them
+
+// How the priorities work:
+// - FileTypeMatch can be IDEAL, GOOD or POOR, example:
+// BMP: BMPFileType - IDEAL,
+// BinaryFileType - POOR
+// - ResolvedParsersPriority can be IDEAL, GOOD or POOR, example:
+// BMPFileType: BMPParser + BMPInformationParser - IDEAL,
+// BinaryParser - POOR
+//
+// PERFECT_MATCH is reserved for an IDEAL_MATCH, that takes the container type into
+// consideration.
+
+enum FileTypeMatch {
+ NO_MATCH = -1,
+ PERFECT_MATCH = 1,
+ IDEAL_MATCH = 2,
+ GOOD_MATCH = 3,
+ POOR_MATCH = 4,
+};
+
+enum ResolvedParsersPriority {
+ NO_PARSERS = -1,
+ //PERFECT_PARSERS = 1, nonsense
+ IDEAL_PARSERS = 2,
+ GOOD_PARSERS = 3,
+ POOR_PARSERS = 4,
+};
+
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+struct RecognizedFileType {
+ static const RecognizedFileType& NotRecognized();
+
+ FileTypeMatch _match;
+ BGUID _fileTypeGUID;
+ RecognizedFileType(FileTypeMatch match, const BGUID& fileTypeGUID)
+ : _match(match), _fileTypeGUID(fileTypeGUID) {}
+
+ /*RecognizedFileType(const RecognizedFileType& other)
+ : _match(other._match), _fileTypeGUID(other._fileTypeGUID) {}
+ RecognizedFileType& operator=(const RecognizedFileType& other) {
+ _match = other._match; _fileTypeGUID = other._fileTypeGUID;
+ }*/
+
+ bool isOk() const {
+ return _match != NO_MATCH;
+ }
+
+ const BGUID& getFileTypeGUID() const {
+ return _fileTypeGUID;
+ }
+
+ bool operator<(const RecognizedFileType& other) const {
+ return this->_match < other._match;
+ }
+};
+
+typedef std::list<RecognizedFileType> RecognizedFileTypes;
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+} // namespace Browser
+
+#endif // _FILE_TYPE_H_
Copied: scummex/branches/gsoc2007-gameresbrowser/src/browser/FileTypeRecognizer.h (from rev 28002, scummex/branches/gsoc2007-gameresbrowser/src/core/FileTypeRecognizer.h)
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/browser/FileTypeRecognizer.h (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/browser/FileTypeRecognizer.h 2007-07-11 13:04:06 UTC (rev 28026)
@@ -0,0 +1,175 @@
+/////////////////////////////////////////////////////////////////////////////
+// FileTypeRecognizer.h
+
+#ifndef _FILE_TYPE_RECOGNIZER_H_
+#define _FILE_TYPE_RECOGNIZER_H_
+
+#include "pinslot.h"
+
+#include "FileType.h"
+#include "CoreInterfaces.h"
+#include "CoreFileTypes.h"
+
+#include <list>
+
+namespace Browser {
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+// When a VirtualFile is to be presented the following happens:
+// - recognize() is run on all FileTypeRecognizers found
+// -- we get a list of file type GUID's
+// - we find all FileTypeParsers for each file type GUID and choose one of them
+
+// How the priorities work:
+// - FileTypeMatch can be IDEAL, GOOD or POOR, example:
+// BMP: BMPFileType - IDEAL,
+// BinaryFileType - POOR
+// - ResolvedParsersPriority can be IDEAL, GOOD or POOR, example:
+// BMPFileType: BMPParser + BMPInformationParser - IDEAL,
+// BinaryParser - POOR
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+typedef std::list<BGUID> guid_list;
+
+struct ResolvedFileTypeParsers {
+ static const ResolvedFileTypeParsers& NoParsers();
+
+ ResolvedParsersPriority _priority;
+ guid_list _parserGUIDs;
+ ResolvedFileTypeParsers(ResolvedParsersPriority priority,
+ const guid_list& parserGUIDs)
+ : _priority(priority), _parserGUIDs(parserGUIDs) {}
+
+ bool isOk() {
+ return _priority != NO_PARSERS;
+ }
+ bool operator<(const ResolvedFileTypeParsers& other) const {
+ return this->_priority < other._priority;
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+class VirtualFile;
+
+class FileTypeRecognizer {
+public:
+ virtual RecognizedFileType recognize(VirtualFile* file) = 0;
+};
+
+class FileTypeParserResolver {
+public:
+ virtual ResolvedFileTypeParsers resolve(const BGUID& fileType) = 0;
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+//BinaryFileTypeRecognizer - a sample recognizer
+//this is a rather unusual BObject - it does not have any pins nor slots
+class BinaryFileTypeRecognizer : public BObject, public FileTypeRecognizer {
+ DECLARE_BOBJECT_CLASS(BinaryFileTypeRecognizer, BObject)
+
+public:
+ ASSIGN_DESC(IS_FILE_TYPE_RECOGNIZER, wxT("CoreObjects"), 1)
+
+ virtual RecognizedFileType recognize(VirtualFile* file);
+};
+
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+//BinaryFileTypeParserResolver - a sample resolver
+//this is a rather unusual BObject - it does not have any pins nor slots
+class BinaryFileTypeParserResolver : public BObject, public FileTypeParserResolver {
+ DECLARE_BOBJECT_CLASS(BinaryFileTypeParserResolver, BObject)
+
+public:
+ ASSIGN_DESC(IS_FILE_TYPE_RESOLVER, wxT("CoreObjects"), 1)
+
+ virtual ResolvedFileTypeParsers resolve(const BGUID& fileType);
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+//utility base class for FileTypeRecognizers
+class GenericFileTypeRecognizer : public BObject, public FileTypeRecognizer {
+ DECLARE_BOBJECT_CLASS(GenericFileTypeRecognizer, BObject)
+
+protected:
+ Slot<IFile>* _fileSlot;
+
+public:
+ ASSIGN_DESC(IS_FILE_TYPE_RECOGNIZER, wxT("CoreObjects"), 1)
+
+ SLOT_DESCS
+ SLOT_DESC(_fileSlot, SLOT_DEFAULT)
+ END_DESCS
+
+ virtual RecognizedFileType recognize(VirtualFile* file);
+
+ //subclasses need to provide this method
+ virtual RecognizedFileType doRecognize(VirtualFile* file, IFile* ifile) = 0;
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+class TextFileTypeRecognizer : public GenericFileTypeRecognizer {
+ DECLARE_BOBJECT_CLASS(TextFileTypeRecognizer, BObject)
+
+public:
+ ASSIGN_DESC(IS_FILE_TYPE_RECOGNIZER, wxT("CoreObjects"), 1)
+
+ virtual RecognizedFileType doRecognize(VirtualFile* file, IFile* ifile);
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+class TextFileTypeParserResolver : public BObject, public FileTypeParserResolver {
+ DECLARE_BOBJECT_CLASS(TextFileTypeParserResolver, BObject)
+
+public:
+ ASSIGN_DESC(IS_FILE_TYPE_RESOLVER, wxT("CoreObjects"), 1)
+
+ virtual ResolvedFileTypeParsers resolve(const BGUID& fileType);
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+class BMPFileTypeRecognizer : public GenericFileTypeRecognizer {
+ DECLARE_BOBJECT_CLASS(BMPFileTypeRecognizer, BObject)
+
+public:
+ ASSIGN_DESC(IS_FILE_TYPE_RECOGNIZER, wxT("CoreObjects"), 1)
+
+ virtual RecognizedFileType doRecognize(VirtualFile* file, IFile* ifile);
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+class BMPFileTypeParserResolver : public BObject, public FileTypeParserResolver {
+ DECLARE_BOBJECT_CLASS(BMPFileTypeParserResolver, BObject)
+
+public:
+ ASSIGN_DESC(IS_FILE_TYPE_RESOLVER, wxT("CoreObjects"), 1)
+
+ virtual ResolvedFileTypeParsers resolve(const BGUID& fileType);
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+} // namespace Browser
+
+#endif // _FILE_TYPE_RECOGNIZER_H_
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/core/CoreFileTypes.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/CoreFileTypes.cpp 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/CoreFileTypes.cpp 2007-07-11 13:04:06 UTC (rev 28026)
@@ -1,49 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// CoreFileTypes.cpp
-
-#include "core_stdafx.h"
-
-#include "CoreFileTypes.h"
-
-#include "debugmem.h"
-
-namespace Browser {
-
-namespace CoreFileTypes {
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// FileTypes
-
-SAFE_STATIC(binaryFileTypeGUID, BGUID, (wxT("CoreFileTypes"), wxT("Binary File"), 1) )
-
-SAFE_STATIC(bmpFileTypeGUID, BGUID, (wxT("CoreFileTypes"), wxT("Windows Bitmap File (BMP)"), 1) )
-
-SAFE_STATIC(textFileTypeGUID, BGUID, (wxT("CoreFileTypes"), wxT("Text File"), 1) )
-
-SAFE_STATIC(rootDirectoryFileType, RecognizedFileType,
- (PERFECT_MATCH, BGUID(wxT("CoreFileTypes"), wxT("Root Directory"), 1)) )
-
-SAFE_STATIC(diskDirectoryFileType, RecognizedFileType,
- (PERFECT_MATCH, BGUID(wxT("CoreFileTypes"), wxT("Disk Directory"), 1)) )
-
-//CAUTION: NO_MATCH here - so that Disk File is not considered a valid file type (it's only for informational/debug purposes)
-SAFE_STATIC(diskFileFileType, RecognizedFileType,
- (NO_MATCH, BGUID(wxT("CoreFileTypes"), wxT("Disk File"), 1)) )
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// Presenters TODO: move it to a different header
-
-SAFE_STATIC(fileInfoPresenterGUID, BGUID, (wxT("CoreObjects"), wxT("FileInfoPresenter"), 1) )
-
-SAFE_STATIC(textParserGUID, BGUID, (wxT("CoreObjects"), wxT("TextParser"), 1) )
-SAFE_STATIC(binaryParserGUID, BGUID, (wxT("CoreObjects"), wxT("BinaryParser"), 1) )
-SAFE_STATIC(bmpParserGUID, BGUID, (wxT("CoreObjects"), wxT("BMPParser"), 1) )
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-} // namespace CoreFileTypes
-
-} // namespace Browser
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/core/CoreFileTypes.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/CoreFileTypes.h 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/CoreFileTypes.h 2007-07-11 13:04:06 UTC (rev 28026)
@@ -1,50 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// CoreFileTypes.h
-
-#ifndef _CORE_FILE_TYPES_H_
-#define _CORE_FILE_TYPES_H_
-
-#include "guid.h"
-#include "FileType.h"
-
-#include "safe_static.h"
-
-namespace Browser {
-
-namespace CoreFileTypes {
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// FileTypes
-
-SAFE_STATIC_DECL(binaryFileTypeGUID, BGUID)
-
-SAFE_STATIC_DECL(bmpFileTypeGUID, BGUID)
-
-SAFE_STATIC_DECL(textFileTypeGUID, BGUID)
-
-SAFE_STATIC_DECL(rootDirectoryFileType, RecognizedFileType)
-
-SAFE_STATIC_DECL(diskDirectoryFileType, RecognizedFileType)
-
-//CAUTION: NO_MATCH here - so that Disk File is not considered a valid file type (it's only for informational/debug purposes)
-SAFE_STATIC_DECL(diskFileFileType, RecognizedFileType)
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// Presenters TODO: move it to a different header
-
-SAFE_STATIC_DECL(fileInfoPresenterGUID, BGUID)
-
-SAFE_STATIC_DECL(textParserGUID, BGUID)
-SAFE_STATIC_DECL(binaryParserGUID, BGUID)
-SAFE_STATIC_DECL(bmpParserGUID, BGUID)
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-} // namespace CoreFileTypes
-
-} // namespace Browser
-
-#endif // _CORE_FILE_TYPES_H_
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/core/CoreInterfaces.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/CoreInterfaces.cpp 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/CoreInterfaces.cpp 2007-07-11 13:04:06 UTC (rev 28026)
@@ -1,164 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// CoreInterfaces.cpp
-
-#include "core_stdafx.h"
-
-#include "CoreInterfaces.h"
-#include "CoreFileTypes.h"
-#include "common/simplefile.h"
-
-#include <iostream>
-
-#include "debugmem.h"
-
-namespace Browser {
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// Concrete implementations of the interfaces
-
-IDirectoryImpl::IDirectoryImpl(IDirectory* parentDir, coreString name,
- bool ownInterfaces)
- : _parentDir(parentDir), _name(name), _ifiles(), _isubdirs(),
- _ownInterfaces(ownInterfaces), _fileType(RecognizedFileType::NotRecognized()) {}
-
-IDirectoryImpl::IDirectoryImpl(IDirectory* parentDir, coreString name,
- const ifile_list& ifiles, const idir_list& isubdirs,
- bool ownInterfaces)
- : _parentDir(parentDir), _name(name), _ifiles(ifiles), _isubdirs(isubdirs),
- _ownInterfaces(ownInterfaces), _fileType(RecognizedFileType::NotRecognized()) {}
-
-IDirectoryImpl::~IDirectoryImpl() {
- if (!_ownInterfaces)
- return;
-
- std::list<IFile*>::const_iterator i;
- for (i = _ifiles.begin(); i != _ifiles.end(); ++i) {
- delete *i;
- }
-
- std::list<IDirectory*>::const_iterator j;
- for (j = _isubdirs.begin(); j != _isubdirs.end(); ++j) {
- delete *j;
- }
-}
-
-const coreString& IDirectoryImpl::getName() {
- return _name;
-}
-
-IDirectory* IDirectoryImpl::getParentDirectory() {
- return _parentDir;
-}
-
-const RecognizedFileType& IDirectoryImpl::getDirectoryFileType() {
- return _fileType;
-}
-
-void IDirectoryImpl::setDirectoryFileType(const RecognizedFileType& fileType) {
- _fileType = fileType;
-}
-
-const ifile_list& IDirectoryImpl::getFiles() {
- //infoout << wxT("IDirectoryImpl::getFiles()") << std::endl;
- return _ifiles;
-}
-
-const idir_list& IDirectoryImpl::getSubDirs() {
- //infoout << wxT("IDirectoryImpl::getSubDirs()") << std::endl;
- return _isubdirs;
-}
-
-void IDirectoryImpl::addFile(IFile* ifile) {
- _ifiles.push_back(ifile);
-}
-
-void IDirectoryImpl::addSubDir(IDirectory* idir) {
- _isubdirs.push_back(idir);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-IStreamImpl::IStreamImpl(Common::SeekableReadStream* stream, bool ownStream /*= false*/)
- : _stream(stream), _ownStream(ownStream) {}
-
-Common::SeekableReadStream* IStreamImpl::getStream() {
- return _stream;
-}
-
-IStreamImpl::~IStreamImpl() {
- if (_ownStream)
- delete _stream;
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-IFileImplBase::IFileImplBase(IDirectory* parentDir, coreString name)
- : _parentDir(parentDir), _name(name),
- _fileType(RecognizedFileType::NotRecognized()) {}
-
-const coreString& IFileImplBase::getName() {
- return _name;
-}
-
-const RecognizedFileType& IFileImplBase::getFileType() {
- return _fileType;
-}
-
-void IFileImplBase::setFileType(const RecognizedFileType& fileType) {
- _fileType = fileType;
-}
-
-IDirectory* IFileImplBase::getParentDirectory() {
- return _parentDir;
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-IStreamFileImpl::IStreamFileImpl(IDirectory* parentDir, coreString name, Common::SeekableReadStream* stream, bool ownStream /*= false*/)
- : IFileImplBase(parentDir, name), _streamImpl(stream, ownStream) {}
-
-Common::SeekableReadStream* IStreamFileImpl::getStream() {
- return _streamImpl.getStream();
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-IDiskFileImpl::IDiskFileImpl(IDirectory* parentDir, coreString name, coreString fullpath)
- : IFileImplBase(parentDir, name), _fullpath(fullpath), _stream(NULL) {
- _fileType = CoreFileTypes::diskFileFileType();
- }
-
-IDiskFileImpl::~IDiskFileImpl() {
- diet();
-}
-
-void IDiskFileImpl::diet() {
- if (_stream)
- delete _stream;
- _stream = NULL;
-}
-
-Common::SeekableReadStream* IDiskFileImpl::getStream() {
- if (!_stream) {
- Common::SimpleFile* file = new Common::SimpleFile();
- bool res = file->open(_fullpath);
- if (!res) {
- errout << wxT("ERROR: IDiskFileImpl::getStream(): could not open file") << std::endl;
- delete file;
- return NULL;
- }
- _stream = file;
- }
-
- return _stream;
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-} // namespace Browser
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/core/CoreInterfaces.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/CoreInterfaces.h 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/CoreInterfaces.h 2007-07-11 13:04:06 UTC (rev 28026)
@@ -1,279 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// CoreInterfaces.h
-
-#ifndef _CORE_INTERFACES_H_
-#define _CORE_INTERFACES_H_
-
-#include "core_stdafx.h"
-
-#include "pinslot.h"
-#include "FileType.h"
-
-#include <list>
-#include "common/stream.h"
-
-namespace Browser {
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// Interfaces
-
-template<typename T>
-class IProvider : public IInterface {
-public:
- ASSIGN_GUID_VERBOSE( toString(typeid(IProvider<T>).name()), wxT("CoreInterfaces"), 1);
- virtual T* getData() = 0;
- virtual void release() {
- delete this;
- }
-};
-
-template<typename T>
-class IProviderImpl : public IProvider<T> {
- bool _ownData;
- T* _data;
-public:
- IProviderImpl(T* data, bool ownData = false)
- : _data(data), _ownData(ownData) {}
- virtual ~IProviderImpl() {
- if (_ownData && _data)
- delete _data;
- }
- virtual T* getData() {
- return _data;
- }
- virtual void setData(T* data) {
- _data = data;
- }
- virtual void release() {
- delete this;
- }
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-class IStream : public IInterface {
-public:
- GUID_FOR(IStream, wxT("CoreInterfaces"), 1);
- virtual Common::SeekableReadStream* getStream() = 0;
-};
-
-class IDirectory;
-
-class IFile : public IStream {
-public:
- GUID_FOR(IFile, wxT("CoreInterfaces"), 1);
- virtual const coreString& getName() = 0;
-
- //can be not set (returns a file type that is !isOk())
- virtual const RecognizedFileType& getFileType() = 0;
- virtual void setFileType(const RecognizedFileType& fileType) = 0;
-
- //can return NULL
- virtual IDirectory* getParentDirectory() = 0;
-};
-
-//TODO: IDirectory should support get/release semantics for IFiles
-// It would enable disk files once opened, to be closed, memory
-// once allocated, to be freed when not used anymore.
-// Do it via dynamic dummy Slots?
-class IDirectory : public IInterface {
-public:
- GUID_FOR(IDirectory, wxT("CoreInterfaces"), 1);
- virtual const coreString& getName() = 0;
- virtual const std::list<IFile*>& getFiles() = 0;
- virtual const std::list<IDirectory*>& getSubDirs() = 0;
-
- //can be not set (returns a file type that is !isOk())
- //it is a helper for recognizing files based on the type of the container
- //they are in (i.e. file with magic BM can be a BMP, but if it is in an XXX
- //container, then we know it's something else).
- virtual const RecognizedFileType& getDirectoryFileType() = 0;
-
- //can return NULL
- virtual IDirectory* getParentDirectory() = 0;
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-typedef std::list<IFile*> ifile_list;
-typedef std::list<IDirectory*> idir_list;
-
-class IDirectoryImpl : public IDirectory {
-
-protected:
- coreString _name;
- RecognizedFileType _fileType;
- IDirectory* _parentDir;
-
- bool _ownInterfaces;
- ifile_list _ifiles;
- idir_list _isubdirs;
-
-public:
- //inherit guid - it's a concrete implementation of an abstract interface
- IDirectoryImpl(IDirectory* parentDir, coreString name,
- bool ownInterfaces);
- IDirectoryImpl(IDirectory* parentDir, coreString name,
- const ifile_list& ifiles, const idir_list& isubdirs,
- bool ownInterfaces);
- virtual ~IDirectoryImpl();
-
- virtual const coreString& getName();
-
- virtual const RecognizedFileType& getDirectoryFileType();
- virtual void setDirectoryFileType(const RecognizedFileType& fileType); //not in IDirectory interface
-
- //can return NULL
- virtual IDirectory* getParentDirectory();
-
- void addFile(IFile* ifile);
- void addSubDir(IDirectory* idir);
-
- virtual const ifile_list& getFiles();
- virtual const idir_list& getSubDirs();
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// Concrete implementations of the interfaces
-
-class IStreamImpl : public IStream {
-protected:
- Common::SeekableReadStream* _stream;
- bool _ownStream;
-public:
- //inherit guid - it's a concrete implementation of an abstract interface
- IStreamImpl(Common::SeekableReadStream* stream, bool ownStream = false);
- virtual Common::SeekableReadStream* getStream();
- virtual ~IStreamImpl();
-};
-
-// Limitation: can't inherit from IFile and IStreamImpl, cause I'll have to inherit
-// virtually from IStream to IStreamImpl and from IStream to IFile. It can't be done,
-// since virtual inheritance disallows casting from virtual base class (here:
-// IInterface) to a derived class (here: IFile).
-// Instead of multiple inheritance - I use encapsulation: _streamImpl member.
-class IFileImplBase : public IFile {
-protected:
- coreString _name;
- RecognizedFileType _fileType;
- IDirectory* _parentDir;
-public:
- //inherit guid - it's a concrete implementation of an abstract interface
- IFileImplBase(IDirectory* parentDir, coreString name);
- virtual const coreString& getName();
- virtual Common::SeekableReadStream* getStream() = 0;
-
- //can be not set (returns a file type that is !isOk())
- virtual const RecognizedFileType& getFileType();
- virtual void setFileType(const RecognizedFileType& fileType);
-
- //can return NULL
- virtual IDirectory* getParentDirectory();
-};
-
-class IStreamFileImpl : public IFileImplBase {
-protected:
- IStreamImpl _streamImpl;
-public:
- //inherit guid - it's a concrete implementation of an abstract interface
- IStreamFileImpl(IDirectory* parentDir, coreString name, Common::SeekableReadStream* stream, bool ownStream = false);
- virtual Common::SeekableReadStream* getStream();
-};
-
-class IDiskFileImpl : public IFileImplBase {
-protected:
- coreString _fullpath;
- Common::SeekableReadStream* _stream;
-public:
- //inherit guid - it's a concrete implementation of an abstract interface
- IDiskFileImpl(IDirectory* parentDir, coreString name, coreString fullpath);
- virtual ~IDiskFileImpl();
- virtual Common::SeekableReadStream* getStream();
-
- //closes the underlying file, getStream() will reopen it if needed
- virtual void diet();
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-//to be used by TextPresenter, so it has a title and the text
-class IText : public IInterface {
-public:
- GUID_FOR(IText, wxT("CoreInterfaces"), 1);
- virtual bool isMonospace() = 0;
- virtual const wxString& getTitle() = 0;
- virtual const wxString& getText() = 0;
- virtual void release() {
- delete this;
- }
-};
-
-class ITextImpl : public IText {
- wxString _title;
- wxString _text;
- bool _monospace;
-public:
- ITextImpl(const wxString& title, const wxString& text, bool monospace = false)
- : _title(title), _text(text), _monospace(monospace) {}
-
- virtual bool isMonospace() {
- return _monospace;
- }
- virtual void setMonospace(bool monospace) {
- _monospace = monospace;
- }
- virtual const wxString& getTitle() {
- return _title;
- }
- virtual const wxString& getText() {
- return _text;
- }
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-//to be used by HtmlPresenter, so it has a title and url
-class IUrl : public IInterface {
-public:
- GUID_FOR(IUrl, wxT("CoreInterfaces"), 1);
- virtual bool isEmpty() = 0;
- virtual const wxString& getTitle() = 0;
- virtual const wxString& getUrl() = 0;
- virtual void release() {
- delete this;
- }
-};
-
-class IUrlImpl : public IUrl {
- wxString _title;
- wxString _url;
- bool _empty;
-public:
- IUrlImpl(const wxString& title)
- : _title(title), _empty(true) {}
- IUrlImpl(const wxString& title, const wxString& url)
- : _title(title), _url(url), _empty(false) {}
-
- virtual bool isEmpty() {
- return _empty;
- }
- virtual const wxString& getTitle() {
- return _title;
- }
- virtual const wxString& getUrl() {
- return _url;
- }
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-} // namespace Browser
-
-#endif // _CORE_INTERFACES_H_
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/core/FileType.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/FileType.h 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/FileType.h 2007-07-11 13:04:06 UTC (rev 28026)
@@ -1,84 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// FileType.h
-
-#ifndef _FILE_TYPE_H_
-#define _FILE_TYPE_H_
-
-#include <list>
-
-namespace Browser {
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-// When a VirtualFile is to be presented the following happens:
-// - recognize() is run on all FileTypeRecognizers found
-// -- we get a list of file type GUID's
-// - we find all FileTypeParsers for each file type GUID and choose one of them
-
-// How the priorities work:
-// - FileTypeMatch can be IDEAL, GOOD or POOR, example:
-// BMP: BMPFileType - IDEAL,
-// BinaryFileType - POOR
-// - ResolvedParsersPriority can be IDEAL, GOOD or POOR, example:
-// BMPFileType: BMPParser + BMPInformationParser - IDEAL,
-// BinaryParser - POOR
-//
-// PERFECT_MATCH is reserved for an IDEAL_MATCH, that takes the container type into
-// consideration.
-
-enum FileTypeMatch {
- NO_MATCH = -1,
- PERFECT_MATCH = 1,
- IDEAL_MATCH = 2,
- GOOD_MATCH = 3,
- POOR_MATCH = 4,
-};
-
-enum ResolvedParsersPriority {
- NO_PARSERS = -1,
- //PERFECT_PARSERS = 1, nonsense
- IDEAL_PARSERS = 2,
- GOOD_PARSERS = 3,
- POOR_PARSERS = 4,
-};
-
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-struct RecognizedFileType {
- static const RecognizedFileType& NotRecognized();
-
- FileTypeMatch _match;
- BGUID _fileTypeGUID;
- RecognizedFileType(FileTypeMatch match, const BGUID& fileTypeGUID)
- : _match(match), _fileTypeGUID(fileTypeGUID) {}
-
- /*RecognizedFileType(const RecognizedFileType& other)
- : _match(other._match), _fileTypeGUID(other._fileTypeGUID) {}
- RecognizedFileType& operator=(const RecognizedFileType& other) {
- _match = other._match; _fileTypeGUID = other._fileTypeGUID;
- }*/
-
- bool isOk() const {
- return _match != NO_MATCH;
- }
-
- const BGUID& getFileTypeGUID() const {
- return _fileTypeGUID;
- }
-
- bool operator<(const RecognizedFileType& other) const {
- return this->_match < other._match;
- }
-};
-
-typedef std::list<RecognizedFileType> RecognizedFileTypes;
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-} // namespace Browser
-
-#endif // _FILE_TYPE_H_
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/core/FileTypeRecognizer.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/FileTypeRecognizer.h 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/FileTypeRecognizer.h 2007-07-11 13:04:06 UTC (rev 28026)
@@ -1,175 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// FileTypeRecognizer.h
-
-#ifndef _FILE_TYPE_RECOGNIZER_H_
-#define _FILE_TYPE_RECOGNIZER_H_
-
-#include "pinslot.h"
-
-#include "FileType.h"
-#include "CoreInterfaces.h"
-#include "CoreFileTypes.h"
-
-#include <list>
-
-namespace Browser {
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-// When a VirtualFile is to be presented the following happens:
-// - recognize() is run on all FileTypeRecognizers found
-// -- we get a list of file type GUID's
-// - we find all FileTypeParsers for each file type GUID and choose one of them
-
-// How the priorities work:
-// - FileTypeMatch can be IDEAL, GOOD or POOR, example:
-// BMP: BMPFileType - IDEAL,
-// BinaryFileType - POOR
-// - ResolvedParsersPriority can be IDEAL, GOOD or POOR, example:
-// BMPFileType: BMPParser + BMPInformationParser - IDEAL,
-// BinaryParser - POOR
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-typedef std::list<BGUID> guid_list;
-
-struct ResolvedFileTypeParsers {
- static const ResolvedFileTypeParsers& NoParsers();
-
- ResolvedParsersPriority _priority;
- guid_list _parserGUIDs;
- ResolvedFileTypeParsers(ResolvedParsersPriority priority,
- const guid_list& parserGUIDs)
- : _priority(priority), _parserGUIDs(parserGUIDs) {}
-
- bool isOk() {
- return _priority != NO_PARSERS;
- }
- bool operator<(const ResolvedFileTypeParsers& other) const {
- return this->_priority < other._priority;
- }
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-class VirtualFile;
-
-class FileTypeRecognizer {
-public:
- virtual RecognizedFileType recognize(VirtualFile* file) = 0;
-};
-
-class FileTypeParserResolver {
-public:
- virtual ResolvedFileTypeParsers resolve(const BGUID& fileType) = 0;
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-//BinaryFileTypeRecognizer - a sample recognizer
-//this is a rather unusual BObject - it does not have any pins nor slots
-class BinaryFileTypeRecognizer : public BObject, public FileTypeRecognizer {
- DECLARE_BOBJECT_CLASS(BinaryFileTypeRecognizer, BObject)
-
-public:
- ASSIGN_DESC(IS_FILE_TYPE_RECOGNIZER, wxT("CoreObjects"), 1)
-
- virtual RecognizedFileType recognize(VirtualFile* file);
-};
-
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-//BinaryFileTypeParserResolver - a sample resolver
-//this is a rather unusual BObject - it does not have any pins nor slots
-class BinaryFileTypeParserResolver : public BObject, public FileTypeParserResolver {
- DECLARE_BOBJECT_CLASS(BinaryFileTypeParserResolver, BObject)
-
-public:
- ASSIGN_DESC(IS_FILE_TYPE_RESOLVER, wxT("CoreObjects"), 1)
-
- virtual ResolvedFileTypeParsers resolve(const BGUID& fileType);
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-//utility base class for FileTypeRecognizers
-class GenericFileTypeRecognizer : public BObject, public FileTypeRecognizer {
- DECLARE_BOBJECT_CLASS(GenericFileTypeRecognizer, BObject)
-
-protected:
- Slot<IFile>* _fileSlot;
-
-public:
- ASSIGN_DESC(IS_FILE_TYPE_RECOGNIZER, wxT("CoreObjects"), 1)
-
- SLOT_DESCS
- SLOT_DESC(_fileSlot, SLOT_DEFAULT)
- END_DESCS
-
- virtual RecognizedFileType recognize(VirtualFile* file);
-
- //subclasses need to provide this method
- virtual RecognizedFileType doRecognize(VirtualFile* file, IFile* ifile) = 0;
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-class TextFileTypeRecognizer : public GenericFileTypeRecognizer {
- DECLARE_BOBJECT_CLASS(TextFileTypeRecognizer, BObject)
-
-public:
- ASSIGN_DESC(IS_FILE_TYPE_RECOGNIZER, wxT("CoreObjects"), 1)
-
- virtual RecognizedFileType doRecognize(VirtualFile* file, IFile* ifile);
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-class TextFileTypeParserResolver : public BObject, public FileTypeParserResolver {
- DECLARE_BOBJECT_CLASS(TextFileTypeParserResolver, BObject)
-
-public:
- ASSIGN_DESC(IS_FILE_TYPE_RESOLVER, wxT("CoreObjects"), 1)
-
- virtual ResolvedFileTypeParsers resolve(const BGUID& fileType);
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-class BMPFileTypeRecognizer : public GenericFileTypeRecognizer {
- DECLARE_BOBJECT_CLASS(BMPFileTypeRecognizer, BObject)
-
-public:
- ASSIGN_DESC(IS_FILE_TYPE_RECOGNIZER, wxT("CoreObjects"), 1)
-
- virtual RecognizedFileType doRecognize(VirtualFile* file, IFile* ifile);
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-class BMPFileTypeParserResolver : public BObject, public FileTypeParserResolver {
- DECLARE_BOBJECT_CLASS(BMPFileTypeParserResolver, BObject)
-
-public:
- ASSIGN_DESC(IS_FILE_TYPE_RESOLVER, wxT("CoreObjects"), 1)
-
- virtual ResolvedFileTypeParsers resolve(const BGUID& fileType);
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-} // namespace Browser
-
-#endif // _FILE_TYPE_RECOGNIZER_H_
Copied: scummex/branches/gsoc2007-gameresbrowser/src/core/FileTypeRegistry.h (from rev 28002, scummex/branches/gsoc2007-gameresbrowser/src/core/ftregistry.h)
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/FileTypeRegistry.h (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/FileTypeRegistry.h 2007-07-11 13:04:06 UTC (rev 28026)
@@ -0,0 +1,54 @@
+/////////////////////////////////////////////////////////////////////////////
+// FileTypeRegistry.h
+//
+// Declares FileTypeRegistry
+// Plugins are registered into FileTypeRegistry by ObjectRegistry.
+//
+
+#pragma once
+#ifndef _FILE_TYPE_REGISTRY_H_
+#define _FILE_TYPE_REGISTRY_H_
+
+#include "plugin.h"
+
+#include "FileTypeRecognizer.h"
+
+#include <list>
+
+namespace Browser {
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// The FileTypeRegistry
+
+class VirtualFile;
+
+class FileTypeRegistry {
+public:
+ typedef std::list< RCPtr<BObject> > object_list;
+ object_list _recognizers;
+ object_list _resolvers;
+
+ void registerPlugins();
+
+ //return properly sorted list of fileTypes
+ RecognizedFileTypes recognizeFileType(VirtualFile* file);
+
+ guid_list resolveParsers(VirtualFile* file, RecognizedFileType& outFileType);
+
+ ResolvedFileTypeParsers resolveParsers(const BGUID& fileType);
+
+ static FileTypeRegistry* get();
+ static void release();
+private:
+ static FileTypeRegistry* _instance;
+ FileTypeRegistry() {}
+
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+} // namespace Browser
+
+#endif /* _FILE_TYPE_REGISTRY_H_ */
Copied: scummex/branches/gsoc2007-gameresbrowser/src/core/ObjectRegistry.cpp (from rev 28002, scummex/branches/gsoc2007-gameresbrowser/src/core/oregistry.cpp)
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/ObjectRegistry.cpp (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/ObjectRegistry.cpp 2007-07-11 13:04:06 UTC (rev 28026)
@@ -0,0 +1,210 @@
+/////////////////////////////////////////////////////////////////////////////
+// ObjectRegistry.cpp
+//
+// ObjectRegistry implementation.
+//
+
+#include "core_stdafx.h"
+
+#include "ObjectRegistry.h"
+
+#include "debugmem.h"
+
+namespace Browser {
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// The ObjectRegistry
+
+ObjectRegistry* ObjectRegistry::_instance = NULL;
+
+/*static*/ ObjectRegistry* ObjectRegistry::get() {
+ if (!_instance)
+ _instance = new ObjectRegistry();
+
+ return _instance;
+}
+
+/*static*/ void ObjectRegistry::release() {
+ if (_instance)
+ delete _instance;
+ _instance = NULL;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// Plugin registering
+
+typedef Plugin::ObjectPlugins ObjectPlugins;
+
+//returns false if there were some conflicts
+bool ObjectRegistry::registerPlugin(PluginAccessor pluginAccessor, bool overwrite) {
+ const Plugin& plugin = pluginAccessor();
+ return registerPlugin(plugin, overwrite);
+}
+
+//returns false if there were some conflicts
+bool ObjectRegistry::registerPlugin(const Plugin& plugin, bool overwrite) {
+ const ObjectPlugins& oplugs = plugin.getObjectPlugins();
+
+ bool res = true;
+
+ ObjectPlugins::const_iterator i;
+ for (i = oplugs.begin(); i != oplugs.end(); ++i) {
+ const ObjectPlugin* oplug = i->second;
+ ASSERT(oplug);
+ const BGUID& oguid = oplug->getObjectGUID();
+
+ PluginsMap::iterator i;
+ i = _pluginsMap.find(oguid);
+ if (i != _pluginsMap.end()) {
+ res = false;
+ if (!overwrite)
+ continue;
+ i->second = oplug;
+ } else {
+ _pluginsMap.insert( std::make_pair(oguid, oplug) );
+ }
+ }
+
+ //TODO: make this thing below better
+ rebuildPinSlotMaps();
+
+ return res;
+}
+
+void ObjectRegistry::rebuildPinSlotMaps() {
+ _pinMap.clear();
+ _slotMap.clear();
+
+ PluginsMap::const_iterator j;
+ for (j = _pluginsMap.begin(); j != _pluginsMap.end(); ++j) {
+
+ const BGUID& objectGuid = j->first;
+ const ObjectPlugin* objectPlugin = j->second;
+
+ //don't include recognizers nor resolvers
+ const BObjectDesc& objectDesc = objectPlugin->get_desc();
+ if ( objectDesc.get_flags() & IS_FILE_TYPE_RECOGNIZER ||
+ objectDesc.get_flags() & IS_FILE_TYPE_RESOLVER )
+ continue;
+
+ PinSlotDescs::const_iterator i;
+
+ const PinSlotDescs& pins = objectPlugin->get_pins();
+ for (i = pins.begin(); i != pins.end(); ++i) {
+ const BGUID& pinGuid = i->first;
+ _pinMap.insert( PinSlotMap::value_type(pinGuid, objectGuid) );
+ }
+
+ const PinSlotDescs& slots = objectPlugin->get_slots();
+ for (i = slots.begin(); i != slots.end(); ++i) {
+ const BGUID& slotGuid = i->first;
+ _slotMap.insert( PinSlotMap::value_type(slotGuid, objectGuid) );
+ }
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+const ObjectPlugin* ObjectRegistry::findObjectPlugin(const BGUID& objectGuid) {
+ PluginsMap::const_iterator i;
+ i = _pluginsMap.find(objectGuid);
+ if (i == _pluginsMap.end())
+ return NULL;
+ return i->second;
+}
+
+RCPtr<BObject> ObjectRegistry::getObject(const BGUID& objectGuid) {
+ const ObjectPlugin* plug = findObjectPlugin(objectGuid);
+ if (!plug)
+ return NULL;
+ return plug->newInstance();
+}
+
+RCPtr<BObject> ObjectRegistry::getObjectWithPin(const BGUID& pinGuid) {
+ const ObjectPlugin* plug = findObjectWithPin(pinGuid);
+ if (!plug)
+ return NULL;
+ return plug->newInstance();
+}
+
+RCPtr<BObject> ObjectRegistry::getObjectWithSlot(const BGUID& slotGuid) {
+ const ObjectPlugin* plug = findObjectWithSlot(slotGuid);
+ if (!plug)
+ return NULL;
+ return plug->newInstance();
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+const ObjectPlugin* ObjectRegistry::findObjectWithPinOrSlot(const BGUID& pinSlotGuid, bool ifPin) {
+ const PinSlotMap& pinSlotMap = ifPin ? _pinMap : _slotMap;
+
+ PinSlotMap::const_iterator i;
+ i = pinSlotMap.find(pinSlotGuid);
+ if (i != pinSlotMap.end())
+ return findObjectPlugin( i->second );
+
+ return NULL;
+}
+
+const ObjectPlugin* ObjectRegistry::findObjectWithPin(const BGUID& pinGuid) {
+ return findObjectWithPinOrSlot(pinGuid, true);
+}
+
+const ObjectPlugin* ObjectRegistry::findObjectWithSlot(const BGUID& slotGuid) {
+ return findObjectWithPinOrSlot(slotGuid, false);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+std::list<const ObjectPlugin*> ObjectRegistry::findObjectsWithFlags(int requiredFlags) {
+ std::list<const ObjectPlugin*> plugins;
+
+ PluginsMap::const_iterator j;
+ for (j = _pluginsMap.begin(); j != _pluginsMap.end(); ++j) {
+ const ObjectPlugin* oplug = i->second;
+ const BObjectDesc& objectDesc = oplug->get_desc();
+ if (objectDesc.get_flags() & requiredFlags)
+ plugins.push_back(oplug);
+ }
+
+ return plugins;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+std::list<const ObjectPlugin*> ObjectRegistry::findObjectsWithPinOrSlot(const BGUID& pinSlotGuid, bool ifPin) {
+ const PinSlotMap& pinSlotMap = ifPin ? _pinMap : _slotMap;
+
+ PinSlotMap::const_iterator i;
+ i = pinSlotMap.find(pinSlotGuid);
+
+ std::list<const ObjectPlugin*> plugins;
+ for (; i != pinSlotMap.end() && i->first == pinSlotGuid; ++i) {
+ const ObjectPlugin* plugin = findObjectPlugin( i->second );
+ if (!plugin)
+ continue;
+ plugins.push_back( plugin );
+ }
+
+ return plugins;
+}
+
+std::list<const ObjectPlugin*> ObjectRegistry::findObjectsWithPin(const BGUID& pinGuid) {
+ return findObjectsWithPinOrSlot(pinGuid, true);
+}
+
+std::list<const ObjectPlugin*> ObjectRegistry::findObjectsWithSlot(const BGUID& slotGuid) {
+ return findObjectsWithPinOrSlot(slotGuid, false);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+} // namespace Browser
Copied: scummex/branches/gsoc2007-gameresbrowser/src/core/ObjectRegistry.h (from rev 28002, scummex/branches/gsoc2007-gameresbrowser/src/core/oregistry.h)
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/ObjectRegistry.h (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/ObjectRegistry.h 2007-07-11 13:04:06 UTC (rev 28026)
@@ -0,0 +1,85 @@
+/////////////////////////////////////////////////////////////////////////////
+// ObjectRegistry.h
+//
+// Declares ObjectRegistry
+// One can load a plugin into ObjectRegistry.
+// (Maybe I'll do unloading too - later.)
+//
+
+#pragma once
+#ifndef _OBJECT_REGISTRY_H_
+#define _OBJECT_REGISTRY_H_
+
+#include "plugin.h"
+
+#include <map>
+#include <list>
+
+namespace Browser {
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// The ObjectRegistry
+
+class ObjectRegistry {
+
+ //CAUTION: the Plugin::ObjectPlugins map is keyed with the plugins GUID, not
+ // it's object's GUID.
+ //CAUTION: the PluginsMap map is keyed with the object's GUID, not
+ // it's plugin's GUID.
+ typedef std::map<const BGUID, const ObjectPlugin*> PluginsMap;
+ PluginsMap _pluginsMap;
+
+ //maps from pin/slot's GUID to object's GUID
+ typedef std::multimap<const BGUID, const BGUID> PinSlotMap;
+ PinSlotMap _pinMap;
+ PinSlotMap _slotMap;
+
+ typedef const Plugin& (*PluginAccessor)();
+
+public:
+ //returns false if there were some conflicts
+ bool registerPlugin(PluginAccessor pluginAccessor, bool overwrite);
+
+ //returns false if there were some conflicts
+ bool registerPlugin(const Plugin& plugin, bool overwrite);
+
+ const ObjectPlugin* findObjectPlugin(const BGUID& objectGuid);
+
+ RCPtr<BObject> getObject(const BGUID& objectGuid);
+ RCPtr<BObject> getObjectWithPin(const BGUID& pinGuid);
+ RCPtr<BObject> getObjectWithSlot(const BGUID& slotGuid);
+
+ template<typename T>
+ RCPtr<T> getObject() {
+ RCPtr<BObject> obj( getObject(T::static_GUID()) );
+ return static_cast<T*>(obj.get());
+ }
+
+ std::list<const ObjectPlugin*> findObjectsWithFlags(int requiredFlags);
+
+ std::list<const ObjectPlugin*> findObjectsWithPinOrSlot(const BGUID& pinSlotGuid, bool ifPin);
+ std::list<const ObjectPlugin*> findObjectsWithPin(const BGUID& pinGuid);
+ std::list<const ObjectPlugin*> findObjectsWithSlot(const BGUID& slotGuid);
+
+ const ObjectPlugin* findObjectWithPinOrSlot(const BGUID& pinSlotGuid, bool ifPin);
+ const ObjectPlugin* findObjectWithPin(const BGUID& pinGuid);
+ const ObjectPlugin* findObjectWithSlot(const BGUID& slotGuid);
+
+
+ static ObjectRegistry* get();
+ static void release();
+private:
+ static ObjectRegistry* _instance;
+ ObjectRegistry() {}
+
+private:
+ void rebuildPinSlotMaps();
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+} // namespace Browser
+
+#endif /* _OBJECT_REGISTRY_H_ */
Copied: scummex/branches/gsoc2007-gameresbrowser/src/core/ftregistry.cpp (from rev 28002, scummex/branches/gsoc2007-gameresbrowser/src/plugins/ftregistry.cpp)
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/ftregistry.cpp (rev 0)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/ftregistry.cpp 2007-07-11 13:04:06 UTC (rev 28026)
@@ -0,0 +1,151 @@
+/////////////////////////////////////////////////////////////////////////////
+// FileTypeRegistry.cpp
+//
+// Declares FileTypeRegistry
+// Plugins are registered into FileTypeRegistry by ObjectRegistry.
+//
+
+#include "plugins_stdafx.h"
+
+#include "FileTypeRegistry.h"
+#include "ObjectRegistry.h"
+
+#include <algorithm>
+#include <vector>
+
+#include "debugmem.h"
+
+namespace Browser {
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// The FileTypeRegistry
+
+FileTypeRegistry* FileTypeRegistry::_instance = NULL;
+
+/*static*/ FileTypeRegistry* FileTypeRegistry::get() {
+ if (!_instance)
+ _instance = new FileTypeRegistry();
+
+ return _instance;
+}
+
+/*static*/ void FileTypeRegistry::release() {
+ if (_instance)
+ delete _instance;
+ _instance = NULL;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// Plugin registration
+
+void FileTypeRegistry::registerPlugins() {
+
+ std::list<const ObjectPlugin*> plugins;
+ std::list<const ObjectPlugin*>::const_iterator j;
+ object_list::iterator i;
+
+ plugins = ObjectRegistry::get()->findObjectsWithFlags(IS_FILE_TYPE_RECOGNIZER);
+ for (j = plugins.begin(); j != plugins.end(); ++j) {
+ const ObjectPlugin* oplug = *j;
+ const BGUID& objGUID = oplug->getObjectGUID();
+ for (i = _recognizers.begin(); i != _recognizers.end(); ++i) {
+ RCPtr<BObject> recognizer = *i;
+ if (recognizer->get_GUID() == objGUID)
+ goto skip_recognizer;
+ }
+ RCPtr<BObject> recognizer( oplug->newInstance() );
+ _recognizers.push_back(recognizer);
+skip_recognizer:
+ }
+
+ plugins = ObjectRegistry::get()->findObjectsWithFlags(IS_FILE_TYPE_RESOLVER);
+ for (j = plugins.begin(); j != plugins.end(); ++j) {
+ const ObjectPlugin* oplug = *j;
+ const BGUID& objGUID = oplug->getObjectGUID();
+ for (i = _resolvers.begin(); i != _resolvers.end(); ++i) {
+ RCPtr<BObject> resolver = *i;
+ if (resolver->get_GUID() == objGUID)
+ goto skip_resolver;
+ }
+ RCPtr<BObject> resolver( oplug->newInstance() );
+ _resolvers.push_back(resolver);
+skip_resolver:
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// File type recognition
+
+//return properly sorted list of fileTypes
+RecognizedFileTypes FileTypeRegistry::recognizeFileType(VirtualFile* file) {
+ RecognizedFileTypes fileTypes;
+
+ object_list::iterator i;
+ for (i = _recognizers.begin(); i != _recognizers.end(); ++i) {
+ BObject* obj = (*i).get();
+ FileTypeRecognizer* recognizer = dynamic_cast<FileTypeRecognizer*>(obj);
+ ASSERT(recognizer);
+ RecognizedFileType fileType = recognizer->recognize(file);
+ if (fileType.isOk())
+ fileTypes.push_back( fileType );
+ }
+
+ //FIXME: VC++'s STL can't sort std::list - Ughhh...
+ std::vector<RecognizedFileType> types( fileTypes.begin(), fileTypes.end() );
+ std::sort( types.begin(), types.end() );
+ RecognizedFileTypes outTypes( types.begin(), types.end() );
+
+ return outTypes;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// Parser resolving
+
+guid_list FileTypeRegistry::resolveParsers(VirtualFile* file, RecognizedFileType& outFileType) {
+ RecognizedFileTypes fileTypes( recognizeFileType(file) );
+
+ RecognizedFileTypes::iterator i;
+ for (i = fileTypes.begin(); i != fileTypes.end(); ++i) {
+ BGUID fileType = i->getFileTypeGUID();
+
+ ResolvedFileTypeParsers parsers( resolveParsers(fileType) );
+ if (parsers.isOk()) {
+ outFileType = *i;
+ return parsers._parserGUIDs;
+ }
+ }
+
+ outFileType = RecognizedFileType::NotRecognized();
+ return guid_list();
+}
+
+ResolvedFileTypeParsers FileTypeRegistry::resolveParsers(const BGUID& fileType) {
+ ResolvedFileTypeParsers bestParsers(ResolvedFileTypeParsers::NoParsers());
+
+ object_list::iterator i;
+ for (i = _resolvers.begin(); i != _resolvers.end(); ++i) {
+ BObject* obj = (*i).get();
+ FileTypeParserResolver* resolver = dynamic_cast<FileTypeParserResolver*>(obj);
+ ASSERT(resolver);
+ ResolvedFileTypeParsers parsers = resolver->resolve(fileType);
+ if (parsers.isOk()) {
+ if (!bestParsers.isOk())
+ bestParsers = parsers;
+ if (parsers < bestParsers)
+ bestParsers = parsers;
+ if (bestParsers._priority == IDEAL_PARSERS)
+ return bestParsers;
+ }
+ }
+
+ return bestParsers;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+} // namespace Browser
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/core/ftregistry.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/ftregistry.h 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/ftregistry.h 2007-07-11 13:04:06 UTC (rev 28026)
@@ -1,56 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// ftregistry.h
-//
-// Declares FileTypeRegistry
-// Plugins are registered into FileTypeRegistry by ObjectRegistry.
-//
-
-#pragma once
-#ifndef _FILE_TYPE_REGISTRY_H_
-#define _FILE_TYPE_REGISTRY_H_
-
-#include "plugin.h"
-
-#include "FileTypeRecognizer.h"
-
-#include <list>
-
-namespace Browser {
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// The FileTypeRegistry
-
-class VirtualFile;
-
-class FileTypeRegistry {
-public:
- typedef std::list< RCPtr<BObject> > object_list;
- object_list _recognizers;
- object_list _resolvers;
-
- void registerRecognizerPlugin(const ObjectPlugin* oplugin);
-
- void registerResolverPlugin(const ObjectPlugin* oplugin);
-
- //return properly sorted list of fileTypes
- RecognizedFileTypes recognizeFileType(VirtualFile* file);
-
- guid_list resolveParsers(VirtualFile* file, RecognizedFileType& outFileType);
-
- ResolvedFileTypeParsers resolveParsers(const BGUID& fileType);
-
- static FileTypeRegistry* get();
- static void release();
-private:
- static FileTypeRegistry* _instance;
- FileTypeRegistry() {}
-
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-} // namespace Browser
-
-#endif /* _FILE_TYPE_REGISTRY_H_ */
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/core/oregistry.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/oregistry.cpp 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/oregistry.cpp 2007-07-11 13:04:06 UTC (rev 28026)
@@ -1,201 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// oregistry.cpp
-//
-// ObjectRegistry implementation.
-//
-
-#include "core_stdafx.h"
-
-#include "oregistry.h"
-#include "ftregistry.h"
-
-#include "debugmem.h"
-
-namespace Browser {
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// The ObjectRegistry
-
-ObjectRegistry* ObjectRegistry::_instance = NULL;
-
-/*static*/ ObjectRegistry* ObjectRegistry::get() {
- if (!_instance)
- _instance = new ObjectRegistry();
-
- return _instance;
-}
-
-/*static*/ void ObjectRegistry::release() {
- if (_instance)
- delete _instance;
- _instance = NULL;
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// Plugin registering
-
-typedef Plugin::ObjectPlugins ObjectPlugins;
-
-//returns false if there were some conflicts
-bool ObjectRegistry::registerPlugin(PluginAccessor pluginAccessor, bool overwrite) {
- const Plugin& plugin = pluginAccessor();
- return registerPlugin(plugin, overwrite);
-}
-
-//returns false if there were some conflicts
-bool ObjectRegistry::registerPlugin(const Plugin& plugin, bool overwrite) {
- const ObjectPlugins& oplugs = plugin.getObjectPlugins();
-
- bool res = true;
-
- ObjectPlugins::const_iterator i;
- for (i = oplugs.begin(); i != oplugs.end(); ++i) {
- const ObjectPlugin* oplug = i->second;
- ASSERT(oplug);
- const BGUID& oguid = oplug->getObjectGUID();
-
- PluginsMap::iterator i;
- i = _pluginsMap.find(oguid);
- if (i != _pluginsMap.end()) {
- res = false;
- if (!overwrite)
- continue;
- i->second = oplug;
- } else {
- _pluginsMap.insert( std::make_pair(oguid, oplug) );
- }
-
- //register recognizers and resolvers in FileTypeRegistry
- const BObjectDesc& objectDesc = oplug->get_desc();
- if (objectDesc.get_flags() & IS_FILE_TYPE_RECOGNIZER)
- FileTypeRegistry::get()->registerRecognizerPlugin(oplug);
- if (objectDesc.get_flags() & IS_FILE_TYPE_RESOLVER)
- FileTypeRegistry::get()->registerResolverPlugin(oplug);
- }
-
- //TODO: make this thing below better
- rebuildPinSlotMaps();
-
- return res;
-}
-
-void ObjectRegistry::rebuildPinSlotMaps() {
- _pinMap.clear();
- _slotMap.clear();
-
- PluginsMap::const_iterator j;
- for (j = _pluginsMap.begin(); j != _pluginsMap.end(); ++j) {
-
- const BGUID& objectGuid = j->first;
- const ObjectPlugin* objectPlugin = j->second;
-
- //don't include recognizers nor resolvers
- const BObjectDesc& objectDesc = objectPlugin->get_desc();
- if ( objectDesc.get_flags() & IS_FILE_TYPE_RECOGNIZER ||
- objectDesc.get_flags() & IS_FILE_TYPE_RESOLVER )
- continue;
-
- PinSlotDescs::const_iterator i;
-
- const PinSlotDescs& pins = objectPlugin->get_pins();
- for (i = pins.begin(); i != pins.end(); ++i) {
- const BGUID& pinGuid = i->first;
- _pinMap.insert( PinSlotMap::value_type(pinGuid, objectGuid) );
- }
-
- const PinSlotDescs& slots = objectPlugin->get_slots();
- for (i = slots.begin(); i != slots.end(); ++i) {
- const BGUID& slotGuid = i->first;
- _slotMap.insert( PinSlotMap::value_type(slotGuid, objectGuid) );
- }
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-const ObjectPlugin* ObjectRegistry::findObjectPlugin(const BGUID& objectGuid) {
- PluginsMap::const_iterator i;
- i = _pluginsMap.find(objectGuid);
- if (i == _pluginsMap.end())
- return NULL;
- return i->second;
-}
-
-RCPtr<BObject> ObjectRegistry::getObject(const BGUID& objectGuid) {
- const ObjectPlugin* plug = findObjectPlugin(objectGuid);
- if (!plug)
- return NULL;
- return plug->newInstance();
-}
-
-RCPtr<BObject> ObjectRegistry::getObjectWithPin(const BGUID& pinGuid) {
- const ObjectPlugin* plug = findObjectWithPin(pinGuid);
- if (!plug)
- return NULL;
- return plug->newInstance();
-}
-
-RCPtr<BObject> ObjectRegistry::getObjectWithSlot(const BGUID& slotGuid) {
- const ObjectPlugin* plug = findObjectWithSlot(slotGuid);
- if (!plug)
- return NULL;
- return plug->newInstance();
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-const ObjectPlugin* ObjectRegistry::findObjectWithPinOrSlot(const BGUID& pinSlotGuid, bool ifPin) {
- const PinSlotMap& pinSlotMap = ifPin ? _pinMap : _slotMap;
-
- PinSlotMap::const_iterator i;
- i = pinSlotMap.find(pinSlotGuid);
- if (i != pinSlotMap.end())
- return findObjectPlugin( i->second );
-
- return NULL;
-}
-
-const ObjectPlugin* ObjectRegistry::findObjectWithPin(const BGUID& pinGuid) {
- return findObjectWithPinOrSlot(pinGuid, true);
-}
-
-const ObjectPlugin* ObjectRegistry::findObjectWithSlot(const BGUID& slotGuid) {
- return findObjectWithPinOrSlot(slotGuid, false);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-std::list<const ObjectPlugin*> ObjectRegistry::findObjectsWithPinOrSlot(const BGUID& pinSlotGuid, bool ifPin) {
- const PinSlotMap& pinSlotMap = ifPin ? _pinMap : _slotMap;
-
- PinSlotMap::const_iterator i;
- i = pinSlotMap.find(pinSlotGuid);
-
- std::list<const ObjectPlugin*> plugins;
- for (; i != pinSlotMap.end() && i->first == pinSlotGuid; ++i) {
- const ObjectPlugin* plugin = findObjectPlugin( i->second );
- if (!plugin)
- continue;
- plugins.push_back( plugin );
- }
-
- return plugins;
-}
-
-std::list<const ObjectPlugin*> ObjectRegistry::findObjectsWithPin(const BGUID& pinGuid) {
- return findObjectsWithPinOrSlot(pinGuid, true);
-}
-
-std::list<const ObjectPlugin*> ObjectRegistry::findObjectsWithSlot(const BGUID& slotGuid) {
- return findObjectsWithPinOrSlot(slotGuid, false);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-} // namespace Browser
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/core/oregistry.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/oregistry.h 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/oregistry.h 2007-07-11 13:04:06 UTC (rev 28026)
@@ -1,83 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// oregistry.h
-//
-// Declares ObjectRegistry
-// One can load a plugin into ObjectRegistry.
-// (Maybe I'll do unloading too - later.)
-//
-
-#pragma once
-#ifndef _OBJECT_REGISTRY_H_
-#define _OBJECT_REGISTRY_H_
-
-#include "plugin.h"
-
-#include <map>
-#include <list>
-
-namespace Browser {
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// The ObjectRegistry
-
-class ObjectRegistry {
-
- //CAUTION: the Plugin::ObjectPlugins map is keyed with the plugins GUID, not
- // it's object's GUID.
- //CAUTION: the PluginsMap map is keyed with the object's GUID, not
- // it's plugin's GUID.
- typedef std::map<const BGUID, const ObjectPlugin*> PluginsMap;
- PluginsMap _pluginsMap;
-
- //maps from pin/slot's GUID to object's GUID
- typedef std::multimap<const BGUID, const BGUID> PinSlotMap;
- PinSlotMap _pinMap;
- PinSlotMap _slotMap;
-
- typedef const Plugin& (*PluginAccessor)();
-
-public:
- //returns false if there were some conflicts
- bool registerPlugin(PluginAccessor pluginAccessor, bool overwrite);
-
- //returns false if there were some conflicts
- bool registerPlugin(const Plugin& plugin, bool overwrite);
-
- const ObjectPlugin* findObjectPlugin(const BGUID& objectGuid);
-
- RCPtr<BObject> getObject(const BGUID& objectGuid);
- RCPtr<BObject> getObjectWithPin(const BGUID& pinGuid);
- RCPtr<BObject> getObjectWithSlot(const BGUID& slotGuid);
-
- template<typename T>
- RCPtr<T> getObject() {
- RCPtr<BObject> obj( getObject(T::static_GUID()) );
- return static_cast<T*>(obj.get());
- }
-
- std::list<const ObjectPlugin*> findObjectsWithPinOrSlot(const BGUID& pinSlotGuid, bool ifPin);
- std::list<const ObjectPlugin*> findObjectsWithPin(const BGUID& pinGuid);
- std::list<const ObjectPlugin*> findObjectsWithSlot(const BGUID& slotGuid);
-
- const ObjectPlugin* findObjectWithPinOrSlot(const BGUID& pinSlotGuid, bool ifPin);
- const ObjectPlugin* findObjectWithPin(const BGUID& pinGuid);
- const ObjectPlugin* findObjectWithSlot(const BGUID& slotGuid);
-
-
- static ObjectRegistry* get();
- static void release();
-private:
- static ObjectRegistry* _instance;
- ObjectRegistry() {}
-
-private:
- void rebuildPinSlotMaps();
-};
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-} // namespace Browser
-
-#endif /* _OBJECT_REGISTRY_H_ */
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/plugin_detail.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/plugin_detail.h 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/plugin_detail.h 2007-07-11 13:04:06 UTC (rev 28026)
@@ -12,6 +12,11 @@
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
+
+// TODO: make plugins link back to the core library
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
// Helper macros
#define JOIN_TOKENS(x, y) JOIN_TOKENS2(x, y)
@@ -25,6 +30,12 @@
// Macros producing the Plugin
// (see myplugin.h for an example of their output)
+#ifdef _MSC_VER
+ #define DLL_EXPORT __declspec(dllexport)
+#else
+ #define DLL_EXPORT
+#endif
+
#define PLUGIN_DESC_(PluginClazz, AccName, facility, version) \
\
class PluginClazz : public Plugin { \
@@ -34,7 +45,7 @@
virtual const ObjectPlugins& getObjectPlugins() const; \
}; \
\
-const Plugin& AccName() { \
+DLL_EXPORT extern "C" const Plugin& AccName() { \
ASSERT_STATICS_ALLOWED(); \
static PluginClazz plugin; \
return plugin; \
Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/MainFormCommands.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/MainFormCommands.cpp 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/MainFormCommands.cpp 2007-07-11 13:04:06 UTC (rev 28026)
@@ -14,9 +14,11 @@
#include "VirtualNode.h"
#include <iostream>
+#include <list>
#include <wx/filedlg.h>
#include <wx/wfstream.h>
+#include <wx/stdpaths.h>
#include "ochain.h"
@@ -27,6 +29,40 @@
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
+typedef std::list< std::pair<wxString, wxString> > plugins_list;
+plugins_list getAvailablePlugins() {
+ plugins_list plugins;
+
+ wxFileSystem fs;
+ fs.ChangePathTo(getPluginsDir(), true);
+
+ wxString found = fs.FindFirst(wxT("*"), wxFILE);
+ while (!found.IsEmpty()) {
+ wxFileName fname(found);
+ wxString dispName = fname.GetFullName();
+ plugins.push_back(make_pair(dispName, fname.GetFullPath()));
+ found = fs.FindNext();
+ }
+
+ return plugins;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef UNIX
+ #include <dlfcn.h>
+#endif
+
+bool loadPlugin(wxString nativePath) {
+ infoout << wxT("Registering plugin: ") << nativePath << std::endl;
+ LoadLibrary
+ ObjectRegistry::get()->registerPlugin( &getTest2Plugin, false );
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
/*
* browserTreeItemActivated
*/
Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/Test2.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/Test2.cpp 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/Test2.cpp 2007-07-11 13:04:06 UTC (rev 28026)
@@ -10,9 +10,9 @@
#include "gui_stdafx.h"
#include "MainForm.h"
+wxString getResourcePath(const wxString& resourceName);
#include <wx/filename.h>
-#include <wx/stdpaths.h>
#include <iostream>
#include <fstream>
@@ -89,33 +89,6 @@
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
-//outputs a Native path
-wxString getResourcesDir() {
-#ifdef UNIX
- wxFileName execFN(wxStandardPaths::Get().GetExecutablePath());
- wxStandardPaths::Get().SetInstallPrefix(execFN.GetPath());
-#endif
- wxString dataDir = wxStandardPaths::Get().GetResourcesDir();
- return dataDir;
-}
-
-//expects input as Linux path relative to the resources dir, outputs a Native path
-wxString getResourcePath(const wxString& resourceName) {
- wxString dataDir = getResourcesDir();
- wxFileName dataFN(dataDir, wxEmptyString, wxPATH_NATIVE);
- wxFileName resFN(resourceName, wxPATH_UNIX);
- for (int i = 0; i < resFN.GetDirCount(); ++i)
- dataFN.AppendDir(resFN.GetDirs()[i]);
- if (resFN.HasName())
- dataFN.SetName(resFN.GetName());
- if (resFN.HasExt())
- dataFN.SetExt(resFN.GetExt());
- return dataFN.GetFullPath(wxPATH_NATIVE);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
void MainForm::OnTest2(wxCommandEvent& event) {
OnTest1Cleanup(event);
Deleted: scummex/branches/gsoc2007-gameresbrowser/src/plugins/ftregistry.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/ftregistry.cpp 2007-07-11 12:28:07 UTC (rev 28025)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/ftregistry.cpp 2007-07-11 13:04:06 UTC (rev 28026)
@@ -1,127 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// ftregistry.cpp
-//
-// Declares FileTypeRegistry
-// Plugins are registered into FileTypeRegistry by ObjectRegistry.
-//
-
-#include "plugins_stdafx.h"
-
-#include "ftregistry.h"
-
-#include <algorithm>
-#include <vector>
-
-#include "debugmem.h"
-
-namespace Browser {
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// The FileTypeRegistry
-
-FileTypeRegistry* FileTypeRegistry::_instance = NULL;
-
-/*static*/ FileTypeRegistry* FileTypeRegistry::get() {
- if (!_instance)
- _instance = new FileTypeRegistry();
-
- return _instance;
-}
-
-/*static*/ void FileTypeRegistry::release() {
- if (_instance)
- delete _instance;
- _instance = NULL;
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// Plugin registration
-
-//TODO: don't insert duplicates
-void FileTypeRegistry::registerRecognizerPlugin(const ObjectPlugin* oplugin) {
- RCPtr<BObject> recognizer( oplugin->newInstance() );
- _recognizers.push_back(recognizer);
-}
-
-//TODO: don't insert duplicates
-void FileTypeRegistry::registerResolverPlugin(const ObjectPlugin* oplugin) {
- RCPtr<BObject> resolver( oplugin->newInstance() );
- _resolvers.push_back(resolver);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// File type recognition
-
-//return properly sorted list of fileTypes
-RecognizedFileTypes FileTypeRegistry::recognizeFileType(VirtualFile* file) {
- RecognizedFileTypes fileTypes;
-
- object_list::iterator i;
- for (i = _recognizers.begin(); i != _recognizers.end(); ++i) {
- BObject* obj = (*i).get();
- FileTypeRecognizer* recognizer = dynamic_cast<FileTypeRecognizer*>(obj);
- ASSERT(recognizer);
- RecognizedFileType fileType = recognizer->recognize(file);
- if (fileType.isOk())
- fileTypes.push_back( fileType );
- }
-
- //FIXME: VC++'s STL can't sort std::list - Ughhh...
- std::vector<RecognizedFileType> types( fileTypes.begin(), fileTypes.end() );
- std::sort( types.begin(), types.end() );
- RecognizedFileTypes outTypes( types.begin(), types.end() );
-
- return outTypes;
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-// Parser resolving
-
-guid_list FileTypeRegistry::resolveParsers(VirtualFile* file, RecognizedFileType& outFileType) {
- RecognizedFileTypes fileTypes( recognizeFileType(file) );
-
- RecognizedFileTypes::iterator i;
- for (i = fileTypes.begin(); i != fileTypes.end(); ++i) {
- BGUID fileType = i->getFileTypeGUID();
-
- ResolvedFileTypeParsers parsers( resolveParsers(fileType) );
- if (parsers.isOk()) {
- outFileType = *i;
- return parsers._parserGUIDs;
- }
- }
-
- outFileType = RecognizedFileType::NotRecognized();
- return guid_list();
-}
-
-ResolvedFileTypeParsers FileTypeRegistry::resolveParsers(const BGUID& fileType) {
- ResolvedFileTypeParsers bestParsers(ResolvedFileTypeParsers::NoParsers());
-
- object_list::iterator i;
- for (i = _resolvers.begin(); i != _resolvers.end(); ++i) {
- BObject* obj = (*i).get();
- FileTypeParserResolver* resolver = dynamic_cast<FileTypeParserResolver*>(obj);
- ASSERT(resolver);
- ResolvedFileTypeParsers parsers = resolver->resolve(fileType);
- if (parsers.isOk()) {
- if (!bestParsers.isOk())
- bestParsers = parsers;
- if (parsers < bestParsers)
- bestParsers = parsers;
- if (bestParsers._priority == IDEAL_PARSERS)
- return bestParsers;
- }
- }
-
- return bestParsers;
-}
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-} // namespace Browser
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