]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxFSInputStream providing stream interface to wxFileSystem.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 16 Apr 2012 13:53:49 +0000 (13:53 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 16 Apr 2012 13:53:49 +0000 (13:53 +0000)
This class allows using virtual wxFSFiles with any wx functions taking
streams. E.g. it makes it possible to load images and animations from
wxFileSystem.

Closes #14185.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71206 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/filesys.h
interface/wx/filesys.h
src/common/filesys.cpp

index a145245ed7b64780031b85858bbb858f21ad3df1..eaa94e96a19db6d41879eee821ae991723e1ffad 100644 (file)
@@ -469,6 +469,7 @@ Major new features in this release
 All:
 
 - Added wxLogFormatter to allow customizing wxLog output (Sébastien Gallou).
+- Added wxFSInputStream for reading data from wxFileSystem (Armel Asselin).
 - Added "%z" support to wxDateTime::Format() and Parse() (Armel Asselin).
 - Add wxHTTP::SetPostBuffer(wxMemoryBuffer) and SetPostText() (Eran Ifrah).
 - Fix wrong time zone used in wxDateTime::UNow().
index 51f06fad2163458cde9b442b69c7f32c160c783a..026fff1f28d9c72aaf85d9a06e83503a6d4703fc 100644 (file)
@@ -293,7 +293,20 @@ protected:
     static wxString ms_root;
 };
 
+// Stream reading data from wxFSFile: this allows to use virtual files with any
+// wx functions accepting streams.
+class WXDLLIMPEXP_BASE wxFSInputStream : public wxWrapperInputStream
+{
+public:
+    // Notice that wxFS_READ is implied in flags.
+    wxFSInputStream(const wxString& filename, int flags = 0);
+    virtual ~wxFSInputStream();
 
+private:
+    wxFSFile* m_file;
+
+    wxDECLARE_NO_COPY_CLASS(wxFSInputStream);
+};
 
 #endif
   // wxUSE_FILESYSTEM
index 17157177da50c5497c9c60a4a680a5865044490b..94ea102527b8751a13667246ac238856f5aa8431 100644 (file)
@@ -463,3 +463,41 @@ protected:
     static wxString GetRightLocation(const wxString& location);
 };
 
+
+/**
+    Input stream for virtual file stream files.
+
+    The stream reads data from wxFSFile obtained from wxFileSystem. It is
+    especially useful to allow using virtual files with other wxWidgets
+    functions and classes working with streams, e.g. for loading images or
+    animations from virtual files and not only physical ones.
+
+    @library{wxbase}
+    @category{streams}
+
+    @see wxWrapperInputStream, wxFSFile
+
+    @since 2.9.4
+*/
+class wxFSInputStream : public wxWrapperInputStream
+{
+public:
+    /**
+        Create a stream associated with the data of the given virtual file
+        system file.
+
+        @param filename
+            The name of the input file passed to wxFileSystem::OpenFile().
+        @param flags
+            Combination of flags from wxFileSystemOpenFlags. ::wxFS_READ is
+            implied, i.e. it is always added to the flags value.
+
+        Use wxStreamBase::IsOk() to verify if the constructor succeeded.
+    */
+    wxFileInputStream(const wxString& filename, int flags = 0);
+
+    /**
+        Returns @true if the stream is initialized and ready.
+    */
+    bool IsOk() const;
+};
index 4f7becfebbb1e1d7783f5315f0bdd6742279ea96..f4533871e248fb0efa1f889f4dc96de48445a9f0 100644 (file)
@@ -756,5 +756,29 @@ class wxFileSystemModule : public wxModule
 
 IMPLEMENT_DYNAMIC_CLASS(wxFileSystemModule, wxModule)
 
+//// wxFSInputStream
+
+wxFSInputStream::wxFSInputStream(const wxString& filename, int flags)
+{
+    wxFileSystem fs;
+    m_file = fs.OpenFile(filename, flags | wxFS_READ);
+
+    if ( m_file )
+    {
+        wxInputStream* const stream = m_file->GetStream();
+        if ( stream )
+        {
+            // Notice that we pass the stream by reference: it shouldn't be
+            // deleted by us as it's owned by m_file already.
+            InitParentStream(*stream);
+        }
+    }
+}
+
+wxFSInputStream::~wxFSInputStream()
+{
+    delete m_file;
+}
+
 #endif
   // wxUSE_FILESYSTEM