]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/archive.h
fix the bug in insert(end(), value) and added unit test for it
[wxWidgets.git] / include / wx / archive.h
index e6003c66cb784445ebecb9c4737350ac4353e773..67419a91fc2364dc710bb0fe72abf68f9099c8e5 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        archive.h
+// Name:        wx/archive.h
 // Purpose:     Streams for archive formats
 // Author:      Mike Wetherell
 // RCS-ID:      $Id$
 #ifndef _WX_ARCHIVE_H__
 #define _WX_ARCHIVE_H__
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma interface "archive.h"
-#endif
-
 #include "wx/defs.h"
 
-#if wxUSE_ZLIB && wxUSE_STREAMS && wxUSE_ZIPSTREAM
+#if wxUSE_STREAMS && wxUSE_ARCHIVE_STREAMS
 
 #include "wx/stream.h"
 #include "wx/filename.h"
@@ -59,7 +55,7 @@ public:
     virtual void SetIsReadOnly(bool isReadOnly = true) = 0;
     virtual void SetName(const wxString& name,
                          wxPathFormat format = wxPATH_NATIVE) = 0;
-    
+
     wxArchiveEntry *Clone() const { return DoClone(); }
 
     void SetNotifier(wxArchiveNotifier& notifier);
@@ -98,16 +94,17 @@ public:
     typedef wxArchiveEntry entry_type;
 
     virtual ~wxArchiveInputStream() { }
-    
+
     virtual bool OpenEntry(wxArchiveEntry& entry) = 0;
     virtual bool CloseEntry() = 0;
 
     wxArchiveEntry *GetNextEntry()  { return DoGetNextEntry(); }
 
     virtual char Peek()             { return wxInputStream::Peek(); }
-    
+
 protected:
     wxArchiveInputStream(wxInputStream& stream, wxMBConv& conv);
+    wxArchiveInputStream(wxInputStream *stream, wxMBConv& conv);
 
     virtual wxArchiveEntry *DoGetNextEntry() = 0;
 
@@ -126,7 +123,7 @@ private:
 //
 // Only one entry can be open for output at a time; another call to
 // PutNextEntry closes the current entry and begins the next.
-// 
+//
 // The overload 'bool PutNextEntry(wxArchiveEntry *entry)' takes ownership
 // of the entry object.
 
@@ -153,6 +150,7 @@ public:
 
 protected:
     wxArchiveOutputStream(wxOutputStream& stream, wxMBConv& conv);
+    wxArchiveOutputStream(wxOutputStream *stream, wxMBConv& conv);
 
     wxMBConv& GetConv() const { return m_conv; }
 
@@ -161,47 +159,6 @@ private:
 };
 
 
-/////////////////////////////////////////////////////////////////////////////
-// wxArchiveClassFactory
-//
-// A wxArchiveClassFactory instance for a particular archive type allows
-// the creation of the other classes that may be needed.
-
-class WXDLLIMPEXP_BASE wxArchiveClassFactory : public wxObject
-{
-public:
-    virtual ~wxArchiveClassFactory() { }
-
-    wxArchiveEntry *NewEntry() const
-        { return DoNewEntry(); }
-    wxArchiveInputStream *NewStream(wxInputStream& stream) const
-        { return DoNewStream(stream); }
-    wxArchiveOutputStream *NewStream(wxOutputStream& stream) const
-        { return DoNewStream(stream); }
-
-    virtual wxString GetInternalName(
-        const wxString& name,
-        wxPathFormat format = wxPATH_NATIVE) const = 0;
-
-    void SetConv(wxMBConv& conv) { m_pConv = &conv; }
-    wxMBConv& GetConv() const { return *m_pConv; }
-
-protected:
-    virtual wxArchiveEntry        *DoNewEntry() const = 0;
-    virtual wxArchiveInputStream  *DoNewStream(wxInputStream& stream) const = 0;
-    virtual wxArchiveOutputStream *DoNewStream(wxOutputStream& stream) const = 0;
-
-    wxArchiveClassFactory() : m_pConv(&wxConvLocal) { }
-    wxArchiveClassFactory& operator=(const wxArchiveClassFactory& WXUNUSED(f))
-        { return *this; }
-
-private:
-    wxMBConv *m_pConv;
-
-    DECLARE_ABSTRACT_CLASS(wxArchiveClassFactory)
-};
-
-
 /////////////////////////////////////////////////////////////////////////////
 // wxArchiveIterator
 //
@@ -250,7 +207,7 @@ public:
         if (m_rep)
             m_rep->AddRef();
     }
-    
+
     ~wxArchiveIterator() {
         if (m_rep)
             m_rep->UnRef();
@@ -298,13 +255,13 @@ private:
         typename Arc::entry_type* m_entry;
         T m_value;
         int m_ref;
-        
+
     public:
         Rep(Arc& arc, typename Arc::entry_type* entry)
             : m_arc(arc), m_entry(entry), m_value(), m_ref(1) { }
         ~Rep()
             { delete m_entry; }
-        
+
         void AddRef() {
             m_ref++;
         }
@@ -321,7 +278,7 @@ private:
                 return NULL;
             }
             if (m_ref > 1) {
-                m_ref--; 
+                m_ref--;
                 return new Rep(m_arc, entry);
             }
             delete m_entry;
@@ -346,6 +303,81 @@ typedef wxArchiveIterator<wxArchiveInputStream,
 
 #endif // wxUSE_STL || defined WX_TEST_ARCHIVE_ITERATOR
 
-#endif // wxUSE_STREAMS
+
+/////////////////////////////////////////////////////////////////////////////
+// wxArchiveClassFactory
+//
+// A wxArchiveClassFactory instance for a particular archive type allows
+// the creation of the other classes that may be needed.
+
+void WXDLLIMPEXP_BASE wxUseArchiveClasses();
+
+class WXDLLIMPEXP_BASE wxArchiveClassFactory : public wxFilterClassFactoryBase
+{
+public:
+    typedef wxArchiveEntry        entry_type;
+    typedef wxArchiveInputStream  instream_type;
+    typedef wxArchiveOutputStream outstream_type;
+    typedef wxArchiveNotifier     notifier_type;
+#if wxUSE_STL || defined WX_TEST_ARCHIVE_ITERATOR
+    typedef wxArchiveIter         iter_type;
+    typedef wxArchivePairIter     pairiter_type;
+#endif
+
+    virtual ~wxArchiveClassFactory() { }
+
+    wxArchiveEntry *NewEntry() const
+        { return DoNewEntry(); }
+    wxArchiveInputStream *NewStream(wxInputStream& stream) const
+        { return DoNewStream(stream); }
+    wxArchiveOutputStream *NewStream(wxOutputStream& stream) const
+        { return DoNewStream(stream); }
+    wxArchiveInputStream *NewStream(wxInputStream *stream) const
+        { return DoNewStream(stream); }
+    wxArchiveOutputStream *NewStream(wxOutputStream *stream) const
+        { return DoNewStream(stream); }
+
+    virtual wxString GetInternalName(
+        const wxString& name,
+        wxPathFormat format = wxPATH_NATIVE) const = 0;
+
+    // FIXME-UTF8: remove these from this file, they are used for ANSI
+    //             build only
+    void SetConv(wxMBConv& conv) { m_pConv = &conv; }
+    wxMBConv& GetConv() const
+        { if (m_pConv) return *m_pConv; else return wxConvLocal; }
+
+    static const wxArchiveClassFactory *Find(const wxString& protocol,
+                                             wxStreamProtocolType type
+                                             = wxSTREAM_PROTOCOL);
+
+    static const wxArchiveClassFactory *GetFirst();
+    const wxArchiveClassFactory *GetNext() const { return m_next; }
+
+    void PushFront() { Remove(); m_next = sm_first; sm_first = this; }
+    void Remove();
+
+protected:
+    // old compilers don't support covarient returns, so 'Do' methods are
+    // used to simulate them
+    virtual wxArchiveEntry        *DoNewEntry() const = 0;
+    virtual wxArchiveInputStream  *DoNewStream(wxInputStream& stream) const = 0;
+    virtual wxArchiveOutputStream *DoNewStream(wxOutputStream& stream) const = 0;
+    virtual wxArchiveInputStream  *DoNewStream(wxInputStream *stream) const = 0;
+    virtual wxArchiveOutputStream *DoNewStream(wxOutputStream *stream) const = 0;
+
+    wxArchiveClassFactory() : m_pConv(NULL), m_next(this) { }
+    wxArchiveClassFactory& operator=(const wxArchiveClassFactory& WXUNUSED(f))
+        { return *this; }
+
+private:
+    wxMBConv *m_pConv;
+    static wxArchiveClassFactory *sm_first;
+    wxArchiveClassFactory *m_next;
+
+    DECLARE_ABSTRACT_CLASS(wxArchiveClassFactory)
+};
+
+#endif // wxUSE_STREAMS && wxUSE_ARCHIVE_STREAMS
 
 #endif // _WX_ARCHIVE_H__