Version: 3.1.0
wxFileSystem Class Reference

#include <wx/filesys.h>

+ Inheritance diagram for wxFileSystem:

Detailed Description

This class provides an interface for opening files on different file systems.

It can handle absolute and/or local filenames.

It uses a system of handlers (see wxFileSystemHandler) to provide access to user-defined virtual file systems.

Library:  wxBase
Category:  Virtual File System
See also
wxFileSystemHandler, wxFSFile, wxFileSystem Overview

Public Member Functions

 wxFileSystem ()
 Constructor. More...
 
void ChangePathTo (const wxString &location, bool is_dir=false)
 Sets the current location. More...
 
bool FindFileInPath (wxString *pStr, const wxString &path, const wxString &file)
 Looks for the file with the given name file in a colon or semi-colon (depending on the current platform) separated list of directories in path. More...
 
wxString FindFirst (const wxString &wildcard, int flags=0)
 Works like wxFindFirstFile(). More...
 
wxString FindNext ()
 Returns the next filename that matches the parameters passed to FindFirst(). More...
 
wxString GetPath () const
 Returns the actual path (set by wxFileSystem::ChangePathTo). More...
 
wxFSFileOpenFile (const wxString &location, int flags=wxFS_READ)
 Opens the file and returns a pointer to a wxFSFile object or NULL if failed. More...
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data. More...
 
 wxObject (const wxObject &other)
 Copy ctor. More...
 
virtual ~wxObject ()
 Destructor. More...
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class. More...
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj. More...
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone. More...
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer. More...
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public. More...
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 

Static Public Member Functions

static void AddHandler (wxFileSystemHandler *handler)
 This static function adds new handler into the list of handlers (see wxFileSystemHandler) which provide access to virtual FS. More...
 
static wxFileSystemHandlerRemoveHandler (wxFileSystemHandler *handler)
 Remove a filesystem handler from the list of handlers. More...
 
static wxString FileNameToURL (const wxFileName &filename)
 Converts a wxFileName into an URL. More...
 
static bool HasHandlerForPath (const wxString &location)
 This static function returns true if there is a registered handler which can open the given location. More...
 
static wxFileName URLToFileName (const wxString &url)
 Converts URL into a well-formed filename. More...
 

Additional Inherited Members

- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object. More...
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
 
- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data. More...
 

Constructor & Destructor Documentation

wxFileSystem::wxFileSystem ( )

Constructor.

The initial current path of this object will be empty (i.e. GetPath() == wxEmptyString) which means that e.g. OpenFile() or FindFirst() functions will use current working directory as current path (see also wxGetCwd).

Member Function Documentation

static void wxFileSystem::AddHandler ( wxFileSystemHandler handler)
static

This static function adds new handler into the list of handlers (see wxFileSystemHandler) which provide access to virtual FS.

Note that if two handlers for the same protocol are added, the last added one takes precedence.

Note
You can call:
wxFileSystem::AddHandler(new My_FS_Handler);
This is because (a) AddHandler is a static method, and (b) the handlers are deleted in wxFileSystem's destructor so that you don't have to care about it.
void wxFileSystem::ChangePathTo ( const wxString location,
bool  is_dir = false 
)

Sets the current location.

location parameter passed to OpenFile() is relative to this path.

Remarks
Unless is_dir is true the location parameter is not the directory name but the name of the file in this directory.

All these commands change the path to "dir/subdir/":

ChangePathTo("dir/subdir/xh.htm");
ChangePathTo("dir/subdir", true);
ChangePathTo("dir/subdir/", true);

Example:

f = fs->OpenFile("hello.htm"); // opens file 'hello.htm'
fs->ChangePathTo("subdir/folder", true);
f = fs->OpenFile("hello.htm"); // opens file 'subdir/folder/hello.htm' !!
Parameters
locationthe new location. Its meaning depends on the value of is_dir
is_dirif true location is new directory. If false (the default) location is file in the new directory.
static wxString wxFileSystem::FileNameToURL ( const wxFileName filename)
static

Converts a wxFileName into an URL.

See also
URLToFileName(), wxFileName
bool wxFileSystem::FindFileInPath ( wxString pStr,
const wxString path,
const wxString file 
)

Looks for the file with the given name file in a colon or semi-colon (depending on the current platform) separated list of directories in path.

If the file is found in any directory, returns true and the full path of the file in str, otherwise returns false and doesn't modify str.

Parameters
pStrReceives the full path of the file, must not be NULL
pathwxPATH_SEP-separated list of directories
filethe name of the file to look for
wxString wxFileSystem::FindFirst ( const wxString wildcard,
int  flags = 0 
)

Works like wxFindFirstFile().

Returns the name of the first filename (within filesystem's current path) that matches wildcard.

Parameters
wildcardThe wildcard that the filename must match
flagsOne of wxFILE (only files), wxDIR (only directories) or 0 (both).
wxString wxFileSystem::FindNext ( )

Returns the next filename that matches the parameters passed to FindFirst().

wxString wxFileSystem::GetPath ( ) const

Returns the actual path (set by wxFileSystem::ChangePathTo).

static bool wxFileSystem::HasHandlerForPath ( const wxString location)
static

This static function returns true if there is a registered handler which can open the given location.

wxFSFile* wxFileSystem::OpenFile ( const wxString location,
int  flags = wxFS_READ 
)

Opens the file and returns a pointer to a wxFSFile object or NULL if failed.

It first tries to open the file in relative scope (based on value passed to ChangePathTo() method) and then as an absolute path.

Note that the user is responsible for deleting the returned wxFSFile. flags can be one or more of the wxFileSystemOpenFlags values combined together.

A stream opened with just the default wxFS_READ flag may or may not be seekable depending on the underlying source.

Passing "wxFS_READ | wxFS_SEEKABLE" for flags will back a stream that is not natively seekable with memory or a file and return a stream that is always seekable.

Note
The location argument is, despite this method's name not a filename. It is a "location", aka wxFileSystem URL (see wxFileSystem Overview).
static wxFileSystemHandler* wxFileSystem::RemoveHandler ( wxFileSystemHandler handler)
static

Remove a filesystem handler from the list of handlers.

static wxFileName wxFileSystem::URLToFileName ( const wxString url)
static

Converts URL into a well-formed filename.

The URL must use the file protocol.