1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxArchiveInputStream class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxArchiveInputStream
13 An abstract base class which serves as a common interface to
14 archive input streams such as wxZipInputStream.
16 wxArchiveInputStream::GetNextEntry returns an
17 wxArchiveEntry object containing the meta-data
18 for the next entry in the archive (and gives away ownership). Reading from
19 the wxArchiveInputStream then returns the entry's data. Eof() becomes @true
20 after an attempt has been made to read past the end of the entry's data.
21 When there are no more entries, GetNextEntry() returns @NULL and sets Eof().
27 @ref overview_wxarc "Archive formats such as zip", wxArchiveEntry,
30 class wxArchiveInputStream
: public wxFilterInputStream
34 Closes the current entry. On a non-seekable stream reads to the end of
35 the current entry first.
40 Closes the current entry if one is open, then reads the meta-data for
41 the next entry and returns it in a wxArchiveEntry
42 object, giving away ownership. Reading this wxArchiveInputStream then
43 returns the entry's data.
45 wxArchiveEntry
* GetNextEntry();
48 Closes the current entry if one is open, then opens the entry specified
49 by the wxArchiveEntry object.
51 @e entry must be from the same archive file that this
52 wxArchiveInputStream is reading, and it must be reading it from a
55 bool OpenEntry(wxArchiveEntry
& entry
);
60 @class wxArchiveOutputStream
63 An abstract base class which serves as a common interface to
64 archive output streams such as wxZipOutputStream.
66 wxArchiveOutputStream::PutNextEntry is used
67 to create a new entry in the output archive, then the entry's data is
68 written to the wxArchiveOutputStream. Another call to PutNextEntry()
69 closes the current entry and begins the next.
75 @ref overview_wxarc "Archive formats such as zip", wxArchiveEntry,
78 class wxArchiveOutputStream
: public wxFilterOutputStream
82 Calls Close() if it has not already
85 ~wxArchiveOutputStream();
88 Closes the archive, returning @true if it was successfully written.
89 Called by the destructor if not called explicitly.
94 Close the current entry. It is called implicitly whenever another new
95 entry is created with CopyEntry()
97 when the archive is closed.
102 Some archive formats have additional meta-data that applies to the archive
103 as a whole. For example in the case of zip there is a comment, which
104 is stored at the end of the zip file. CopyArchiveMetaData() can be used
105 to transfer such information when writing a modified copy of an archive.
107 Since the position of the meta-data can vary between the various archive
108 formats, it is best to call CopyArchiveMetaData() before transferring
109 the entries. The wxArchiveOutputStream
110 will then hold on to the meta-data and write it at the correct point in
113 When the input archive is being read from a non-seekable stream, the
114 meta-data may not be available when CopyArchiveMetaData() is called,
115 in which case the two streams set up a link and transfer the data
116 when it becomes available.
118 bool CopyArchiveMetaData(wxArchiveInputStream
& stream
);
121 Takes ownership of @e entry and uses it to create a new entry in the
122 archive. @e entry is then opened in the input stream @e stream
123 and its contents copied to this stream.
125 For archive types which compress entry data, CopyEntry() is likely to be
126 much more efficient than transferring the data using Read() and Write()
127 since it will copy them without decompressing and recompressing them.
129 @e entry must be from the same archive file that @e stream is
130 accessing. For non-seekable streams, @e entry must also be the last
131 thing read from @e stream.
133 bool CopyEntry(wxArchiveEntry
* entry
,
134 wxArchiveInputStream
& stream
);
139 Create a new directory entry
140 (see wxArchiveEntry::IsDir)
141 with the given name and timestamp.
144 also be used to create directory entries, by supplying a name with
145 a trailing path separator.
147 bool PutNextDirEntry(const wxString
& name
);
151 , @b off_t@e size = wxInvalidOffset)
153 Create a new entry with the given name, timestamp and size. The entry's
154 data can then be written by writing to this wxArchiveOutputStream.
156 bool PutNextEntry(wxArchiveEntry
* entry
);
157 bool PutNextEntry(const wxString
& name
);
163 @class wxArchiveEntry
166 An abstract base class which serves as a common interface to
167 archive entry classes such as wxZipEntry.
168 These hold the meta-data (filename, timestamp, etc.), for entries
169 in archive files such as zips and tars.
175 @ref overview_wxarc "Archive formats such as zip", @ref overview_wxarcgeneric
176 "Generic archive programming", wxArchiveInputStream, wxArchiveOutputStream, wxArchiveNotifier
178 class wxArchiveEntry
: public wxObject
182 Returns a copy of this entry object.
184 wxArchiveEntry
* Clone();
188 The entry's timestamp.
190 wxDateTime
GetDateTime();
191 void SetDateTime(const wxDateTime
& dt
);
196 The entry's name, by default in the native format. The name can include
197 directory components, i.e. it can be a full path.
199 If this is a directory entry, (i.e. if IsDir()
200 is @true) then GetName() returns the name with a trailing path separator.
202 Similarly, setting a name with a trailing path separator sets IsDir().
204 wxString
GetName(wxPathFormat format
= wxPATH_NATIVE
);
205 void SetName(const wxString
& name
,
206 wxPathFormat format
= wxPATH_NATIVE
);
211 The size of the entry's data in bytes.
214 void SetSize(off_t size
);
218 Returns the path format used internally within the archive to store
221 wxPathFormat
GetInternalFormat();
224 Returns the entry's filename in the internal format used within the
225 archive. The name can include directory components, i.e. it can be a
228 The names of directory entries are returned without any trailing path
229 separator. This gives a canonical name that can be used in comparisons.
231 @sa @ref overview_wxarcbyname "Looking up an archive entry by name"
233 wxString
GetInternalName();
236 Returns a numeric value unique to the entry within the archive.
242 True if this is a directory entry.
244 Directory entries are entries with no data, which are used to store
245 the meta-data of directories. They also make it possible for completely
246 empty directories to be stored.
248 The names of entries within an archive can be complete paths, and
249 unarchivers typically create whatever directories are necessary as they
250 restore files, even if the archive contains no explicit directory entries.
253 void SetIsDir(bool isDir
= @
true);
258 True if the entry is a read-only file.
261 void SetIsReadOnly(bool isReadOnly
= @
true);
266 Sets the notifier for this entry.
267 Whenever the wxArchiveInputStream updates
268 this entry, it will then invoke the associated
269 notifier's wxArchiveNotifier::OnEntryUpdated
272 Setting a notifier is not usually necessary. It is used to handle
273 certain cases when modifying an archive in a pipeline (i.e. between
274 non-seekable streams).
276 void SetNotifier(wxArchiveNotifier
& notifier
);
277 void UnsetNotifier();
283 @class wxArchiveClassFactory
286 Allows the creation of streams to handle archive formats such
289 For example, given a filename you can search for a factory that will
290 handle it and create a stream to read it:
293 factory = wxArchiveClassFactory::Find(filename, wxSTREAM_FILEEXT);
295 stream = factory-NewStream(new wxFFileInputStream(filename));
298 wxArchiveClassFactory::Find can also search
299 for a factory by MIME type or wxFileSystem protocol.
300 The available factories can be enumerated
301 using @ref wxArchiveClassFactory::getfirst "GetFirst() and GetNext".
307 @ref overview_wxarc "Archive formats such as zip", @ref overview_wxarcgeneric
308 "Generic archive programming", wxArchiveEntry, wxArchiveInputStream, wxArchiveOutputStream, wxFilterClassFactory
310 class wxArchiveClassFactory
: public wxObject
314 Returns @true if this factory can handle the given protocol, MIME type
317 When using wxSTREAM_FILEEXT for the second parameter, the first parameter
318 can be a complete filename rather than just an extension.
320 bool CanHandle(const wxChar
* protocol
,
321 wxStreamProtocolType type
= wxSTREAM_PROTOCOL
);
324 A static member that finds a factory that can handle a given protocol, MIME
325 type or file extension. Returns a pointer to the class factory if found, or
326 @NULL otherwise. It does not give away ownership of the factory.
328 When using wxSTREAM_FILEEXT for the second parameter, the first parameter
329 can be a complete filename rather than just an extension.
331 static const wxArchiveClassFactory
* Find(const wxChar
* protocol
,
332 wxStreamProtocolType type
= wxSTREAM_PROTOCOL
);
336 The wxMBConv object that the created streams
337 will use when translating meta-data. The initial default, set by the
338 constructor, is wxConvLocal.
341 void SetConv(wxMBConv
& conv
);
346 GetFirst and GetNext can be used to enumerate the available factories.
348 For example, to list them:
349 GetFirst()/GetNext() return a pointer to a factory or @NULL if no more
350 are available. They do not give away ownership of the factory.
352 static const wxArchiveClassFactory
* GetFirst();
353 const wxArchiveClassFactory
* GetNext();
357 Calls the static GetInternalName() function for the archive entry type,
359 wxZipEntry::GetInternalName.
361 wxString
GetInternalName(const wxString
& name
,
362 wxPathFormat format
= wxPATH_NATIVE
);
365 Returns the wxFileSystem protocol supported by this factory. Equivalent
366 to wxString(*GetProtcols()).
368 wxString
GetProtocol();
371 Returns the protocols, MIME types or file extensions supported by this
372 factory, as an array of null terminated strings. It does not give away
373 ownership of the array or strings.
375 For example, to list the file extensions a factory supports:
377 const wxChar
* const* GetProtocols(wxStreamProtocolType type
= wxSTREAM_PROTOCOL
);
380 Create a new wxArchiveEntry object of the
383 wxArchiveEntry
* NewEntry();
387 Create a new input or output stream to read or write an archive.
389 If the parent stream is passed as a pointer then the new archive stream
390 takes ownership of it. If it is passed by reference then it does not.
392 wxArchiveInputStream
* NewStream(wxInputStream
& stream
);
393 wxArchiveOutputStream
* NewStream(wxOutputStream
& stream
);
394 wxArchiveInputStream
* NewStream(wxInputStream
* stream
);
395 wxArchiveOutputStream
* NewStream(wxOutputStream
* stream
);
399 Adds this class factory to the list returned
400 by @ref getfirst() GetFirst()/GetNext.
402 It is not necessary to do this to use the archive streams. It is usually
403 used when implementing streams, typically the implementation will
404 add a static instance of its factory class.
406 It can also be used to change the order of a factory already in the list,
407 bringing it to the front. This isn't a thread safe operation
408 so can't be done when other threads are running that will be using the list.
410 The list does not take ownership of the factory.
415 Removes this class factory from the list returned
416 by @ref getfirst() GetFirst()/GetNext.
418 Removing from the list isn't a thread safe operation
419 so can't be done when other threads are running that will be using the list.
421 The list does not own the factories, so removing a factory does not delete it.
428 @class wxArchiveNotifier
431 If you need to know when a
432 wxArchiveInputStream updates a
433 wxArchiveEntry object, you can create
434 a notifier by deriving from this abstract base class, overriding
435 wxArchiveNotifier::OnEntryUpdated. An instance
436 of your notifier class can then be assigned to the wxArchiveEntry object
437 using wxArchiveEntry::SetNotifier.
438 Your OnEntryUpdated() method will then be invoked whenever the input
439 stream updates the entry.
441 Setting a notifier is not usually necessary. It is used to handle
442 certain cases when modifying an archive in a pipeline (i.e. between
443 non-seekable streams).
444 See @ref overview_wxarcnoseek "Archives on non-seekable streams".
450 @ref overview_wxarcnoseek "Archives on non-seekable streams", wxArchiveEntry,
451 wxArchiveInputStream, wxArchiveOutputStream
453 class wxArchiveNotifier
457 This method must be overridden in your derived class.
459 void OnEntryUpdated(class wxArchiveEntry
& entry
);
464 @class wxArchiveIterator
467 An input iterator template class that can be used to transfer an archive's
468 catalogue to a container. It is only available if wxUSE_STL is set to 1
469 in setup.h, and the uses for it outlined below require a compiler which
470 supports member templates.
473 template class Arc, class T = typename Arc::entry_type*
474 class wxArchiveIterator
476 // this constructor creates an 'end of sequence' object
479 // template parameter 'Arc' should be the type of an archive input stream
480 wxArchiveIterator(Arc& arc) {
486 The first
template parameter should be the type of archive input stream
487 (e
.g
. wxArchiveInputStream
) and the
488 second can either be a pointer to an entry
489 (e
.g
. wxArchiveEntry
*), or a string
/pointer pair
490 (e
.g
. std::pairwxString
, wxArchiveEntry
*).
492 The @c wx
/archive
.h header defines the following typedefs
:
495 typedef wxArchiveIteratorwxArchiveInputStream wxArchiveIter
;
497 typedef wxArchiveIteratorwxArchiveInputStream
,
498 std::pairwxString
, wxArchiveEntry
* wxArchivePairIter
;
501 The header
for any implementation of
this interface should define similar
502 typedefs
for its types
, for example in @c wx
/zipstrm
.h there is
:
505 typedef wxArchiveIteratorwxZipInputStream wxZipIter
;
507 typedef wxArchiveIteratorwxZipInputStream
,
508 std::pairwxString
, wxZipEntry
* wxZipPairIter
;
511 Transferring the catalogue of an archive @e arc to a vector @e cat
,
512 can then be done something like
this:
515 std::vectorwxArchiveEntry
* cat((wxArchiveIter
)arc
, wxArchiveIter());
518 When the iterator is dereferenced
, it gives away ownership of an entry
519 object
. So in the above example
, when you have finished with @e cat
520 you must
delete the pointers it contains
.
522 If you have smart pointers with normal copy
semantics (i
.e
. not auto_ptr
523 or wxScopedPtr
), then you can create an iterator
524 which uses them instead
. For example
, with a smart pointer
class for
525 zip entries @e ZipEntryPtr
:
528 typedef std::vectorZipEntryPtr ZipCatalog
;
529 typedef wxArchiveIteratorwxZipInputStream
, ZipEntryPtr ZipIter
;
530 ZipCatalog
cat((ZipIter
)zip
, ZipIter());
533 Iterators that
return std::pair objects can be used to
534 populate a
std::multimap
, to allow entries to be looked
535 up by name
. The string is initialised
using the wxArchiveEntry object
's
536 wxArchiveEntry::GetInternalName function.
539 typedef std::multimapwxString, wxZipEntry* ZipCatalog;
540 ZipCatalog cat((wxZipPairIter)zip, wxZipPairIter());
544 Note that this iterator also gives away ownership of an entry
545 object each time it is dereferenced. So in the above example, when
546 you have finished with @e cat you must delete the pointers it contains.
548 Or if you have them, a pair containing a smart pointer can be used
549 (again @e ZipEntryPtr), no worries about ownership:
552 typedef std::multimapwxString, ZipEntryPtr ZipCatalog;
553 typedef wxArchiveIteratorwxZipInputStream,
554 std::pairwxString, ZipEntryPtr ZipPairIter;
555 ZipCatalog cat((ZipPairIter)zip, ZipPairIter());
562 wxArchiveEntry, wxArchiveInputStream, wxArchiveOutputStream
564 class wxArchiveIterator
569 Construct iterator that returns all the entries in the archive input
573 wxArchiveIterator(Arc& arc);
577 Returns an entry object from the archive input stream, giving away
584 Position the input iterator at the next entry in the archive input stream.
586 wxArchiveIterator operator++();
587 wxArchiveIterator operator++(int );