Difference between revisions of "User talk:David corrales"

Jump to navigation Jump to search
Added a link to the proposal uml diagram
(Added a link to the proposal uml diagram)
 
(3 intermediate revisions by the same user not shown)
Line 190: Line 190:
|}
|}


== Common::File redesign discussion ==
== Common::File redesign discussion (old)==
While analizing the current state of the Common::File class, I've been noticing several important things that I feel, should be discussed.
While analizing the current state of the Common::File class, I've been noticing several important things that I feel, should be discussed.
First of all, is the relevance of breaking up this class (like the FilesystemNode) into different implementations for each architecture. This is the primary motivation for this section.
First of all, is the relevance of breaking up this class (like the FilesystemNode) into different implementations for each architecture. This is the primary motivation for this section.
Line 282: Line 282:
=== New methods ===
=== New methods ===
Adding new methods to the existing Common::File class wouldn't have an impact, unless it redefines or changes the signature of the old ones. Instead of breaking up said class, it could be cleaned up and extended with new functionality.
Adding new methods to the existing Common::File class wouldn't have an impact, unless it redefines or changes the signature of the old ones. Instead of breaking up said class, it could be cleaned up and extended with new functionality.
== New Common::File redesign proposal and implementation ==
After being involved in the project for more time, I analyzed the current design and created the following proposal to address the Common::File class.
Reading through the cpp file, I discovered that most discrepancies occur in the redefinition of standard I/O manipulation functions (e.g. fopen, ftell, fseek and so on) in 3 platforms: ds, ps2 and symbian. There's some #ifdef's around, but the algorithms are 99% the same for all platforms, so a separate implementation for each architecture is not needed and instead, would result in unnecessary code duplication.
Given this situation the template pattern looked like a really good alternative: create a base file class that implements the algorithm but allows subclasses to choose which method they want for fopen, fclose, etc calls. This is done through protected functions named _fopen, _close, etc.
Additionally, the current Common::File class is mixing responsibilities that go beyond a regular file class. For example, the whole default directory structure (contained in a hash map for quick access) is beyond the scope of a regular file manipulation object. The objective is then to convert Common::File into a wrapper for BaseFile, just like Common:FsNode is around AbstractFilesystemNode.
The responsibilities per function would be:
{| border="1" cellpadding="5" cellspacing="0"
!Function
!BaseFile
!Common::File
|-
|void clearIOFailed
|Clear the last I/O error flag
|Checks + Call the base class
|-
|virtual void close
|Close the open file
|Checks + Call the base class
|-
|bool eof
|Whether the seek pointer is at the EOF
|Checks + Call the base class
|-
|bool eos
|Whether the seek pointer is at the EOS
|Checks + Call the base class
|-
|bool ioFailed
|Whether the last I/O failed
|Checks + Call the base class
|-
|const char *name
|Name of the stream
|Checks + Call the base class
|-
|bool isOpen
|Whether the file is open
|Checks + Call the base class
|-
|virtual bool open
|Open a given filepath
|Use the default paths to locate the filepath, then call the base class
|-
|uint32 pos
|Position of the seek pointer within the file
|Checks + Call the base class
|-
|uint32 read
|Reads a chunk from a file
|Checks + Call the base class
|-
|virtual bool remove
|Remove a file
|Checks + Call the base class
|-
|void seek
|Move the seek pointer
|Checks + Call the base class
|-
|uint32 size
|Size of the file
|Checks + Call the base class
|-
|void addDefaultDirectory
| -
|Add a default search path
|-
|void addDefaultDirectoryRecursive
| -
|Recursive method of addDefaultDirectory
|-
|void resetDefaultDirectories
| -
|Clear default directories
|-
|bool exists
| -
|Whether the file exists. Uses Common:FSNode
|-
|}
The wrapper will handle the whole default search path functionality plus checks and maybe some caching for the BaseFile object, again, just like Common::FsNode does.
I did not list the write functions here, since a while ago I recall a discussion that implied removing the write abilities from the Common::File class. This of course needs to be defined clearly.
Another issue to be resolved is BaseScummFile inheriting Common::File. Max told me it was possible to code BaseScummFile as a wrapper instead of an inherited class, so that could be a possible solution.
The following diagram shows the class structure:
[[Image:File.png]]


== Current Filesystem API implementation diagrams==
== Current Filesystem API implementation diagrams==
Line 295: Line 390:
'''Update 19/06''': removed isValid() and added the hidden parameter to getChildren()''.
'''Update 19/06''': removed isValid() and added the hidden parameter to getChildren()''.


== Common::File Redesign proposal ==
== Common::File Redesign proposal (old)==
[[Image:Fs3.png]]
[[Image:Fs3.png]]


Line 414: Line 509:


Another thing: look at <code>engines/scumm/plugin.cpp</code> and the <code>searchFSNode()</code> function in there. It can be used to look for a given file(name) within a directory (ignoring case). It's a bit like getChild() only that it ignores the file name case, and is only used to check for the presence of a given file. This is a commonly used function, I think. Might be worse taking this into consideration for the FS API redesign  [[User:Fingolfin|Fingolfin]] 21:41, 3 April 2007 (CEST)
Another thing: look at <code>engines/scumm/plugin.cpp</code> and the <code>searchFSNode()</code> function in there. It can be used to look for a given file(name) within a directory (ignoring case). It's a bit like getChild() only that it ignores the file name case, and is only used to check for the presence of a given file. This is a commonly used function, I think. Might be worse taking this into consideration for the FS API redesign  [[User:Fingolfin|Fingolfin]] 21:41, 3 April 2007 (CEST)
'''Update 08/07''': The lookupFile() function in fs.h/cpp can be used to supply this functionality. It uses wildcards for matching filenames.

Navigation menu