]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: archive.h | |
4cbfec15 | 3 | // Purpose: interface of wxArchive* classes |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxArchiveInputStream | |
11 | @wxheader{archive.h} | |
7c913512 | 12 | |
23324ae1 FM |
13 | An abstract base class which serves as a common interface to |
14 | archive input streams such as wxZipInputStream. | |
7c913512 | 15 | |
4cbfec15 FM |
16 | wxArchiveInputStream::GetNextEntry returns an wxArchiveEntry object containing |
17 | the meta-data for the next entry in the archive (and gives away ownership). | |
18 | ||
19 | Reading from the wxArchiveInputStream then returns the entry's data. Eof() | |
20 | becomes @true after an attempt has been made to read past the end of the | |
21 | entry's data. | |
22 | ||
23324ae1 | 23 | When there are no more entries, GetNextEntry() returns @NULL and sets Eof(). |
7c913512 | 24 | |
23324ae1 | 25 | @library{wxbase} |
4cbfec15 | 26 | @category{archive} |
7c913512 | 27 | |
4cbfec15 | 28 | @see @ref overview_archive, wxArchiveEntry, wxArchiveOutputStream |
23324ae1 FM |
29 | */ |
30 | class wxArchiveInputStream : public wxFilterInputStream | |
31 | { | |
32 | public: | |
33 | /** | |
34 | Closes the current entry. On a non-seekable stream reads to the end of | |
35 | the current entry first. | |
36 | */ | |
37 | bool CloseEntry(); | |
38 | ||
39 | /** | |
40 | Closes the current entry if one is open, then reads the meta-data for | |
4cbfec15 FM |
41 | the next entry and returns it in a wxArchiveEntry object, giving away |
42 | ownership. Reading this wxArchiveInputStream then returns the entry's data. | |
23324ae1 FM |
43 | */ |
44 | wxArchiveEntry* GetNextEntry(); | |
45 | ||
46 | /** | |
47 | Closes the current entry if one is open, then opens the entry specified | |
48 | by the wxArchiveEntry object. | |
4cbfec15 FM |
49 | |
50 | @a entry must be from the same archive file that this wxArchiveInputStream | |
51 | is reading, and it must be reading it from a seekable stream. | |
23324ae1 FM |
52 | */ |
53 | bool OpenEntry(wxArchiveEntry& entry); | |
54 | }; | |
55 | ||
56 | ||
e54c96f1 | 57 | |
23324ae1 FM |
58 | /** |
59 | @class wxArchiveOutputStream | |
60 | @wxheader{archive.h} | |
7c913512 | 61 | |
23324ae1 FM |
62 | An abstract base class which serves as a common interface to |
63 | archive output streams such as wxZipOutputStream. | |
7c913512 | 64 | |
4cbfec15 FM |
65 | wxArchiveOutputStream::PutNextEntry is used to create a new entry in the |
66 | output archive, then the entry's data is written to the wxArchiveOutputStream. | |
67 | Another call to PutNextEntry() closes the current entry and begins the next. | |
7c913512 | 68 | |
23324ae1 | 69 | @library{wxbase} |
4cbfec15 | 70 | @category{archive} |
7c913512 | 71 | |
4cbfec15 | 72 | @see @ref overview_archive, wxArchiveEntry, wxArchiveInputStream |
23324ae1 FM |
73 | */ |
74 | class wxArchiveOutputStream : public wxFilterOutputStream | |
75 | { | |
76 | public: | |
77 | /** | |
4cbfec15 | 78 | Calls Close() if it has not already been called. |
23324ae1 FM |
79 | */ |
80 | ~wxArchiveOutputStream(); | |
81 | ||
82 | /** | |
83 | Closes the archive, returning @true if it was successfully written. | |
84 | Called by the destructor if not called explicitly. | |
cc6e1a74 FM |
85 | |
86 | @see wxOutputStream::Close() | |
23324ae1 | 87 | */ |
cc6e1a74 | 88 | virtual bool Close(); |
23324ae1 FM |
89 | |
90 | /** | |
4cbfec15 FM |
91 | Close the current entry. |
92 | It is called implicitly whenever another new entry is created with CopyEntry() | |
93 | or PutNextEntry(), or when the archive is closed. | |
23324ae1 | 94 | */ |
cc6e1a74 | 95 | virtual bool CloseEntry(); |
23324ae1 FM |
96 | |
97 | /** | |
98 | Some archive formats have additional meta-data that applies to the archive | |
4cbfec15 FM |
99 | as a whole. |
100 | For example in the case of zip there is a comment, which is stored at the end | |
101 | of the zip file. CopyArchiveMetaData() can be used to transfer such information | |
102 | when writing a modified copy of an archive. | |
103 | ||
23324ae1 FM |
104 | Since the position of the meta-data can vary between the various archive |
105 | formats, it is best to call CopyArchiveMetaData() before transferring | |
4cbfec15 FM |
106 | the entries. The wxArchiveOutputStream will then hold on to the meta-data |
107 | and write it at the correct point in the output file. | |
108 | ||
23324ae1 FM |
109 | When the input archive is being read from a non-seekable stream, the |
110 | meta-data may not be available when CopyArchiveMetaData() is called, | |
111 | in which case the two streams set up a link and transfer the data | |
112 | when it becomes available. | |
113 | */ | |
cc6e1a74 | 114 | virtual bool CopyArchiveMetaData(wxArchiveInputStream& stream); |
23324ae1 FM |
115 | |
116 | /** | |
4cc4bfaf FM |
117 | Takes ownership of @a entry and uses it to create a new entry in the |
118 | archive. @a entry is then opened in the input stream @e stream | |
23324ae1 | 119 | and its contents copied to this stream. |
4cbfec15 | 120 | |
23324ae1 FM |
121 | For archive types which compress entry data, CopyEntry() is likely to be |
122 | much more efficient than transferring the data using Read() and Write() | |
123 | since it will copy them without decompressing and recompressing them. | |
4cbfec15 | 124 | |
4cc4bfaf FM |
125 | @a entry must be from the same archive file that @a stream is |
126 | accessing. For non-seekable streams, @a entry must also be the last | |
23324ae1 FM |
127 | thing read from @e stream. |
128 | */ | |
cc6e1a74 FM |
129 | virtual bool CopyEntry(wxArchiveEntry* entry, |
130 | wxArchiveInputStream& stream); | |
23324ae1 FM |
131 | |
132 | /** | |
4cbfec15 FM |
133 | Create a new directory entry (see wxArchiveEntry::IsDir) with the given |
134 | name and timestamp. | |
135 | ||
136 | PutNextEntry() can also be used to create directory entries, by supplying | |
137 | a name with a trailing path separator. | |
23324ae1 | 138 | */ |
cc6e1a74 FM |
139 | virtual bool PutNextDirEntry(const wxString& name, |
140 | const wxDateTime& dt = wxDateTime::Now()); | |
23324ae1 | 141 | |
23324ae1 | 142 | /** |
4cbfec15 FM |
143 | Takes ownership of entry and uses it to create a new entry in the archive. |
144 | The entry's data can then be written by writing to this wxArchiveOutputStream. | |
145 | */ | |
cc6e1a74 | 146 | virtual bool PutNextEntry(wxArchiveEntry* entry); |
4cbfec15 FM |
147 | |
148 | /** | |
23324ae1 FM |
149 | Create a new entry with the given name, timestamp and size. The entry's |
150 | data can then be written by writing to this wxArchiveOutputStream. | |
151 | */ | |
cc6e1a74 FM |
152 | virtual bool PutNextEntry(const wxString& name, |
153 | const wxDateTime& dt = wxDateTime::Now(), | |
154 | wxFileOffset size = wxInvalidOffset); | |
23324ae1 FM |
155 | }; |
156 | ||
157 | ||
e54c96f1 | 158 | |
23324ae1 FM |
159 | /** |
160 | @class wxArchiveEntry | |
161 | @wxheader{archive.h} | |
7c913512 | 162 | |
23324ae1 FM |
163 | An abstract base class which serves as a common interface to |
164 | archive entry classes such as wxZipEntry. | |
165 | These hold the meta-data (filename, timestamp, etc.), for entries | |
166 | in archive files such as zips and tars. | |
7c913512 | 167 | |
4cbfec15 FM |
168 | <b>About non-seekable streams</b>: this information applies only when reading |
169 | archives from non-seekable streams. When the stream is seekable GetNextEntry() | |
170 | returns a fully populated wxArchiveEntry. | |
171 | See @ref overview_archive_noseek for more information. | |
172 | ||
173 | For generic programming, when the worst case must be assumed, you can rely on | |
174 | all the fields of wxArchiveEntry being fully populated when | |
175 | wxArchiveInputStream::GetNextEntry() returns, with the the following exceptions: | |
176 | ||
177 | @li GetSize(): guaranteed to be available after the entry has been read to Eof(), | |
178 | or CloseEntry() has been called; | |
179 | @li IsReadOnly(): guaranteed to be available after the end of the archive has | |
180 | been reached, i.e. after GetNextEntry() returns NULL and Eof() is true. | |
181 | ||
23324ae1 | 182 | @library{wxbase} |
4cbfec15 | 183 | @category{archive} |
7c913512 | 184 | |
4cbfec15 FM |
185 | @see @ref overview_archive, @ref overview_archive_generic, |
186 | wxArchiveInputStream, wxArchiveOutputStream, wxArchiveNotifier | |
23324ae1 FM |
187 | */ |
188 | class wxArchiveEntry : public wxObject | |
189 | { | |
190 | public: | |
191 | /** | |
192 | Returns a copy of this entry object. | |
193 | */ | |
328f5751 | 194 | wxArchiveEntry* Clone() const; |
23324ae1 | 195 | |
23324ae1 | 196 | /** |
4cbfec15 | 197 | Gets the entry's timestamp. |
23324ae1 | 198 | */ |
cc6e1a74 | 199 | virtual wxDateTime GetDateTime() const; |
4cbfec15 FM |
200 | |
201 | /** | |
202 | Sets the entry's timestamp. | |
203 | */ | |
cc6e1a74 | 204 | virtual void SetDateTime(const wxDateTime& dt); |
23324ae1 | 205 | |
23324ae1 | 206 | /** |
4cbfec15 FM |
207 | Returns the entry's name, by default in the native format. |
208 | The name can include directory components, i.e. it can be a full path. | |
209 | ||
210 | If this is a directory entry, (i.e. if IsDir() is @true) then the | |
211 | returned string is the name with a trailing path separator. | |
23324ae1 | 212 | */ |
cc6e1a74 | 213 | virtual wxString GetName(wxPathFormat format = wxPATH_NATIVE) const; |
4cbfec15 FM |
214 | |
215 | /** | |
216 | Sets the entry's name. | |
217 | Setting a name with a trailing path separator sets IsDir(). | |
218 | ||
219 | @see GetName() | |
220 | */ | |
cc6e1a74 FM |
221 | virtual void SetName(const wxString& name, |
222 | wxPathFormat format = wxPATH_NATIVE); | |
23324ae1 | 223 | |
23324ae1 | 224 | /** |
4cbfec15 | 225 | Returns the size of the entry's data in bytes. |
23324ae1 | 226 | */ |
cc6e1a74 | 227 | virtual wxFileOffset GetSize() const; |
4cbfec15 FM |
228 | |
229 | /** | |
230 | Sets the size of the entry's data in bytes. | |
231 | */ | |
cc6e1a74 | 232 | virtual void SetSize(wxFileOffset size); |
23324ae1 FM |
233 | |
234 | /** | |
235 | Returns the path format used internally within the archive to store | |
236 | filenames. | |
237 | */ | |
cc6e1a74 | 238 | virtual wxPathFormat GetInternalFormat() const; |
23324ae1 FM |
239 | |
240 | /** | |
241 | Returns the entry's filename in the internal format used within the | |
242 | archive. The name can include directory components, i.e. it can be a | |
243 | full path. | |
4cbfec15 | 244 | |
23324ae1 FM |
245 | The names of directory entries are returned without any trailing path |
246 | separator. This gives a canonical name that can be used in comparisons. | |
3c4f71cc | 247 | |
4cbfec15 | 248 | @see @ref overview_archive_byname |
23324ae1 | 249 | */ |
cc6e1a74 | 250 | virtual wxString GetInternalName() const; |
23324ae1 FM |
251 | |
252 | /** | |
253 | Returns a numeric value unique to the entry within the archive. | |
254 | */ | |
cc6e1a74 | 255 | virtual wxFileOffset GetOffset() const; |
23324ae1 | 256 | |
23324ae1 | 257 | /** |
4cbfec15 FM |
258 | Returns @true if this is a directory entry. |
259 | ||
23324ae1 FM |
260 | Directory entries are entries with no data, which are used to store |
261 | the meta-data of directories. They also make it possible for completely | |
262 | empty directories to be stored. | |
4cbfec15 FM |
263 | |
264 | @note | |
23324ae1 FM |
265 | The names of entries within an archive can be complete paths, and |
266 | unarchivers typically create whatever directories are necessary as they | |
267 | restore files, even if the archive contains no explicit directory entries. | |
268 | */ | |
cc6e1a74 | 269 | virtual bool IsDir() const; |
4cbfec15 FM |
270 | |
271 | /** | |
272 | Marks this entry as a directory if @a isDir is @true. See IsDir() for more info. | |
273 | */ | |
cc6e1a74 | 274 | virtual void SetIsDir(bool isDir = true); |
23324ae1 | 275 | |
23324ae1 | 276 | /** |
4cbfec15 | 277 | Returns @true if the entry is a read-only file. |
23324ae1 | 278 | */ |
cc6e1a74 | 279 | virtual bool IsReadOnly() const; |
4cbfec15 FM |
280 | |
281 | /** | |
282 | Sets this entry as a read-only file. | |
283 | */ | |
cc6e1a74 | 284 | virtual void SetIsReadOnly(bool isReadOnly = true); |
23324ae1 | 285 | |
23324ae1 | 286 | /** |
4cbfec15 FM |
287 | Sets the notifier (see wxArchiveNotifier) for this entry. |
288 | ||
289 | Whenever the wxArchiveInputStream updates this entry, it will then invoke | |
290 | the associated notifier's wxArchiveNotifier::OnEntryUpdated method. | |
291 | ||
23324ae1 FM |
292 | Setting a notifier is not usually necessary. It is used to handle |
293 | certain cases when modifying an archive in a pipeline (i.e. between | |
294 | non-seekable streams). | |
295 | */ | |
296 | void SetNotifier(wxArchiveNotifier& notifier); | |
4cbfec15 FM |
297 | |
298 | /** | |
299 | Unsets the notifier eventually attached to this entry. | |
300 | */ | |
cc6e1a74 | 301 | virtual void UnsetNotifier(); |
23324ae1 FM |
302 | }; |
303 | ||
304 | ||
4cbfec15 FM |
305 | /** |
306 | Type of stream enumeration; used by wxArchiveClassFactory methods. | |
307 | */ | |
308 | enum wxStreamProtocolType | |
309 | { | |
310 | wxSTREAM_PROTOCOL, //!< wxFileSystem protocol (should be only one) | |
311 | wxSTREAM_MIMETYPE, //!< MIME types the stream handles | |
312 | wxSTREAM_ENCODING, //!< Not used for archives | |
313 | wxSTREAM_FILEEXT //!< File extensions the stream handles | |
314 | }; | |
e54c96f1 | 315 | |
23324ae1 FM |
316 | /** |
317 | @class wxArchiveClassFactory | |
318 | @wxheader{archive.h} | |
7c913512 | 319 | |
4cbfec15 | 320 | Allows the creation of streams to handle archive formats such as zip and tar. |
7c913512 | 321 | |
23324ae1 FM |
322 | For example, given a filename you can search for a factory that will |
323 | handle it and create a stream to read it: | |
7c913512 | 324 | |
23324ae1 | 325 | @code |
4cbfec15 | 326 | factory = wxArchiveClassFactory::Find(filename, wxSTREAM_FILEEXT); |
23324ae1 | 327 | if (factory) |
4cbfec15 | 328 | stream = factory->NewStream(new wxFFileInputStream(filename)); |
23324ae1 | 329 | @endcode |
7c913512 | 330 | |
4cbfec15 FM |
331 | wxArchiveClassFactory::Find can also search for a factory by MIME type |
332 | or wxFileSystem protocol. | |
333 | ||
3c4f71cc | 334 | The available factories can be enumerated using |
4cbfec15 | 335 | wxArchiveClassFactory::GetFirst() and wxArchiveClassFactory::GetNext(). |
7c913512 | 336 | |
23324ae1 | 337 | @library{wxbase} |
4cbfec15 | 338 | @category{archive} |
7c913512 | 339 | |
4cbfec15 FM |
340 | @see @ref overview_archive, @ref overview_archive_generic, wxArchiveEntry, |
341 | wxArchiveInputStream, wxArchiveOutputStream, wxFilterClassFactory | |
23324ae1 FM |
342 | */ |
343 | class wxArchiveClassFactory : public wxObject | |
344 | { | |
345 | public: | |
346 | /** | |
347 | Returns @true if this factory can handle the given protocol, MIME type | |
348 | or file extension. | |
4cbfec15 | 349 | |
23324ae1 FM |
350 | When using wxSTREAM_FILEEXT for the second parameter, the first parameter |
351 | can be a complete filename rather than just an extension. | |
352 | */ | |
353 | bool CanHandle(const wxChar* protocol, | |
328f5751 | 354 | wxStreamProtocolType type = wxSTREAM_PROTOCOL) const; |
23324ae1 FM |
355 | |
356 | /** | |
357 | A static member that finds a factory that can handle a given protocol, MIME | |
358 | type or file extension. Returns a pointer to the class factory if found, or | |
359 | @NULL otherwise. It does not give away ownership of the factory. | |
4cbfec15 | 360 | |
23324ae1 FM |
361 | When using wxSTREAM_FILEEXT for the second parameter, the first parameter |
362 | can be a complete filename rather than just an extension. | |
363 | */ | |
364 | static const wxArchiveClassFactory* Find(const wxChar* protocol, | |
7c913512 | 365 | wxStreamProtocolType type = wxSTREAM_PROTOCOL); |
23324ae1 | 366 | |
23324ae1 | 367 | /** |
4cbfec15 FM |
368 | Returns the wxMBConv object that the created streams will use when |
369 | translating meta-data. The initial default, set by the constructor, | |
370 | is wxConvLocal. | |
23324ae1 | 371 | */ |
4cbfec15 FM |
372 | wxMBConv GetConv() const; |
373 | ||
374 | /** | |
375 | Sets the wxMBConv object that the created streams will use when | |
376 | translating meta-data. | |
377 | */ | |
378 | void SetConv(wxMBConv& conv); | |
23324ae1 FM |
379 | |
380 | //@{ | |
381 | /** | |
382 | GetFirst and GetNext can be used to enumerate the available factories. | |
23324ae1 | 383 | For example, to list them: |
4cbfec15 FM |
384 | |
385 | @code | |
386 | wxString list; | |
387 | const wxArchiveClassFactory *factory = wxArchiveClassFactory::GetFirst(); | |
3c4f71cc | 388 | |
4cbfec15 FM |
389 | while (factory) { |
390 | list << factory->GetProtocol() << _T("\n"); | |
391 | factory = factory->GetNext(); | |
392 | } | |
393 | @endcode | |
3c4f71cc | 394 | |
4cbfec15 | 395 | GetFirst() and GetNext() return a pointer to a factory or @NULL if no more |
23324ae1 FM |
396 | are available. They do not give away ownership of the factory. |
397 | */ | |
328f5751 FM |
398 | static const wxArchiveClassFactory* GetFirst() const; |
399 | const wxArchiveClassFactory* GetNext() const; | |
23324ae1 FM |
400 | //@} |
401 | ||
402 | /** | |
403 | Calls the static GetInternalName() function for the archive entry type, | |
4cbfec15 | 404 | for example wxZipEntry::GetInternalName. |
23324ae1 FM |
405 | */ |
406 | wxString GetInternalName(const wxString& name, | |
328f5751 | 407 | wxPathFormat format = wxPATH_NATIVE) const; |
23324ae1 FM |
408 | |
409 | /** | |
4cbfec15 FM |
410 | Returns the wxFileSystem protocol supported by this factory. |
411 | Equivalent to @code wxString(*GetProtocols()) @endcode. | |
23324ae1 | 412 | */ |
328f5751 | 413 | wxString GetProtocol() const; |
23324ae1 FM |
414 | |
415 | /** | |
416 | Returns the protocols, MIME types or file extensions supported by this | |
4cbfec15 FM |
417 | factory, as an array of null terminated strings. |
418 | ||
419 | It does not give away ownership of the array or strings. | |
23324ae1 | 420 | For example, to list the file extensions a factory supports: |
4cbfec15 FM |
421 | |
422 | @code | |
423 | wxString list; | |
424 | const wxChar *const *p; | |
3c4f71cc | 425 | |
4cbfec15 FM |
426 | for (p = factory->GetProtocols(wxSTREAM_FILEEXT); *p; p++) |
427 | list << *p << _T("\n"); | |
428 | @encode | |
23324ae1 | 429 | */ |
328f5751 | 430 | const wxChar* const* GetProtocols(wxStreamProtocolType type = wxSTREAM_PROTOCOL) const; |
23324ae1 FM |
431 | |
432 | /** | |
4cbfec15 | 433 | Create a new wxArchiveEntry object of the appropriate type. |
23324ae1 | 434 | */ |
328f5751 | 435 | wxArchiveEntry* NewEntry() const; |
23324ae1 FM |
436 | |
437 | //@{ | |
438 | /** | |
439 | Create a new input or output stream to read or write an archive. | |
4cbfec15 | 440 | |
23324ae1 FM |
441 | If the parent stream is passed as a pointer then the new archive stream |
442 | takes ownership of it. If it is passed by reference then it does not. | |
443 | */ | |
328f5751 | 444 | wxArchiveInputStream* NewStream(wxInputStream& stream) const; |
4cbfec15 FM |
445 | wxArchiveOutputStream* NewStream(wxOutputStream& stream) const; |
446 | wxArchiveInputStream* NewStream(wxInputStream* stream) const; | |
447 | wxArchiveOutputStream* NewStream(wxOutputStream* stream) const; | |
23324ae1 FM |
448 | //@} |
449 | ||
450 | /** | |
4cbfec15 FM |
451 | Adds this class factory to the list returned by GetFirst() or GetNext(). |
452 | ||
23324ae1 | 453 | It is not necessary to do this to use the archive streams. It is usually |
7c913512 | 454 | used when implementing streams, typically the implementation will |
23324ae1 | 455 | add a static instance of its factory class. |
4cbfec15 | 456 | |
23324ae1 FM |
457 | It can also be used to change the order of a factory already in the list, |
458 | bringing it to the front. This isn't a thread safe operation | |
459 | so can't be done when other threads are running that will be using the list. | |
23324ae1 FM |
460 | The list does not take ownership of the factory. |
461 | */ | |
462 | void PushFront(); | |
463 | ||
464 | /** | |
4cbfec15 FM |
465 | Removes this class factory from the list returned by GetFirst() and GetNext(). |
466 | ||
467 | Removing from the list isn't a thread safe operation so can't be done when | |
468 | other threads are running that will be using the list. | |
23324ae1 FM |
469 | The list does not own the factories, so removing a factory does not delete it. |
470 | */ | |
471 | void Remove(); | |
472 | }; | |
473 | ||
474 | ||
e54c96f1 | 475 | |
23324ae1 FM |
476 | /** |
477 | @class wxArchiveNotifier | |
478 | @wxheader{archive.h} | |
7c913512 | 479 | |
4cbfec15 FM |
480 | If you need to know when a wxArchiveInputStream updates a wxArchiveEntry |
481 | object, you can create a notifier by deriving from this abstract base class, | |
482 | overriding wxArchiveNotifier::OnEntryUpdated. | |
483 | ||
484 | An instance of your notifier class can then be assigned to the wxArchiveEntry | |
485 | object using wxArchiveEntry::SetNotifier. | |
23324ae1 FM |
486 | Your OnEntryUpdated() method will then be invoked whenever the input |
487 | stream updates the entry. | |
7c913512 | 488 | |
23324ae1 FM |
489 | Setting a notifier is not usually necessary. It is used to handle |
490 | certain cases when modifying an archive in a pipeline (i.e. between | |
491 | non-seekable streams). | |
4cbfec15 | 492 | See @ref overview_archive_noseek. |
7c913512 | 493 | |
23324ae1 | 494 | @library{wxbase} |
4cbfec15 | 495 | @category{archive} |
7c913512 | 496 | |
4cbfec15 FM |
497 | @see @ref overview_archive_noseek, wxArchiveEntry, wxArchiveInputStream, |
498 | wxArchiveOutputStream | |
23324ae1 | 499 | */ |
7c913512 | 500 | class wxArchiveNotifier |
23324ae1 FM |
501 | { |
502 | public: | |
503 | /** | |
504 | This method must be overridden in your derived class. | |
505 | */ | |
506 | void OnEntryUpdated(class wxArchiveEntry& entry); | |
507 | }; | |
508 | ||
509 | ||
e54c96f1 | 510 | |
23324ae1 FM |
511 | /** |
512 | @class wxArchiveIterator | |
513 | @wxheader{archive.h} | |
7c913512 | 514 | |
23324ae1 FM |
515 | An input iterator template class that can be used to transfer an archive's |
516 | catalogue to a container. It is only available if wxUSE_STL is set to 1 | |
517 | in setup.h, and the uses for it outlined below require a compiler which | |
518 | supports member templates. | |
7c913512 | 519 | |
23324ae1 FM |
520 | @code |
521 | template class Arc, class T = typename Arc::entry_type* | |
522 | class wxArchiveIterator | |
523 | { | |
524 | // this constructor creates an 'end of sequence' object | |
525 | wxArchiveIterator(); | |
7c913512 | 526 | |
23324ae1 FM |
527 | // template parameter 'Arc' should be the type of an archive input stream |
528 | wxArchiveIterator(Arc& arc) { | |
4cc4bfaf FM |
529 | // ... |
530 | } | |
531 | }; | |
532 | @endcode | |
7c913512 | 533 | |
4cc4bfaf | 534 | The first template parameter should be the type of archive input stream |
4cbfec15 | 535 | (e.g. wxArchiveInputStream) and the second can either be a pointer to an entry |
3c4f71cc | 536 | (e.g. wxArchiveEntry*), or a string/pointer pair (e.g. std::pairwxString, |
4cbfec15 | 537 | wxArchiveEntry*). |
7c913512 | 538 | |
4cc4bfaf | 539 | The @c wx/archive.h header defines the following typedefs: |
7c913512 | 540 | |
4cc4bfaf | 541 | @code |
4cbfec15 | 542 | typedef wxArchiveIterator<wxArchiveInputStream> wxArchiveIter; |
7c913512 | 543 | |
4cbfec15 FM |
544 | typedef wxArchiveIterator<wxArchiveInputStream, |
545 | std::pair<wxString, wxArchiveEntry*> > wxArchivePairIter; | |
4cc4bfaf | 546 | @endcode |
7c913512 | 547 | |
4cc4bfaf FM |
548 | The header for any implementation of this interface should define similar |
549 | typedefs for its types, for example in @c wx/zipstrm.h there is: | |
7c913512 | 550 | |
4cc4bfaf | 551 | @code |
4cbfec15 | 552 | typedef wxArchiveIterator<wxZipInputStream> wxZipIter; |
7c913512 | 553 | |
4cbfec15 FM |
554 | typedef wxArchiveIterator<wxZipInputStream, |
555 | std::pair<wxString, wxZipEntry*> > wxZipPairIter; | |
4cc4bfaf | 556 | @endcode |
7c913512 | 557 | |
4cc4bfaf FM |
558 | Transferring the catalogue of an archive @e arc to a vector @e cat, |
559 | can then be done something like this: | |
7c913512 | 560 | |
4cc4bfaf | 561 | @code |
4cbfec15 | 562 | std::vector<wxArchiveEntry*> cat((wxArchiveIter)arc, wxArchiveIter()); |
4cc4bfaf | 563 | @endcode |
7c913512 | 564 | |
4cc4bfaf FM |
565 | When the iterator is dereferenced, it gives away ownership of an entry |
566 | object. So in the above example, when you have finished with @e cat | |
567 | you must delete the pointers it contains. | |
7c913512 | 568 | |
4cc4bfaf | 569 | If you have smart pointers with normal copy semantics (i.e. not auto_ptr |
4cbfec15 FM |
570 | or wxScopedPtr), then you can create an iterator which uses them instead. |
571 | ||
572 | For example, with a smart pointer class for zip entries @e ZipEntryPtr: | |
7c913512 | 573 | |
4cc4bfaf | 574 | @code |
4cbfec15 FM |
575 | typedef std::vector<ZipEntryPtr> ZipCatalog; |
576 | typedef wxArchiveIterator<wxZipInputStream, ZipEntryPtr> ZipIter; | |
577 | ZipCatalog cat((ZipIter)zip, ZipIter()); | |
4cc4bfaf | 578 | @endcode |
7c913512 | 579 | |
4cbfec15 FM |
580 | Iterators that return std::pair objects can be used to populate a std::multimap, |
581 | to allow entries to be looked up by name. | |
582 | The string is initialised using the wxArchiveEntry object's | |
583 | wxArchiveEntry::GetInternalName function. | |
7c913512 | 584 | |
4cc4bfaf | 585 | @code |
4cbfec15 FM |
586 | typedef std::multimap<wxString, wxZipEntry*> ZipCatalog; |
587 | ZipCatalog cat((wxZipPairIter)zip, wxZipPairIter()); | |
4cc4bfaf | 588 | @endcode |
7c913512 | 589 | |
4cc4bfaf FM |
590 | Note that this iterator also gives away ownership of an entry |
591 | object each time it is dereferenced. So in the above example, when | |
592 | you have finished with @e cat you must delete the pointers it contains. | |
7c913512 | 593 | |
4cc4bfaf FM |
594 | Or if you have them, a pair containing a smart pointer can be used |
595 | (again @e ZipEntryPtr), no worries about ownership: | |
7c913512 | 596 | |
4cc4bfaf | 597 | @code |
4cbfec15 FM |
598 | typedef std::multimap<wxString, ZipEntryPtr> ZipCatalog; |
599 | typedef wxArchiveIterator<wxZipInputStream, | |
600 | std::pair<wxString, ZipEntryPtr> > ZipPairIter; | |
601 | ZipCatalog cat((ZipPairIter)zip, ZipPairIter()); | |
4cc4bfaf | 602 | @endcode |
7c913512 | 603 | |
4cc4bfaf | 604 | @library{wxbase} |
4cbfec15 | 605 | @category{archive} |
7c913512 | 606 | |
e54c96f1 | 607 | @see wxArchiveEntry, wxArchiveInputStream, wxArchiveOutputStream |
23324ae1 | 608 | */ |
7c913512 | 609 | class wxArchiveIterator |
23324ae1 FM |
610 | { |
611 | public: | |
4cc4bfaf | 612 | /** |
4cbfec15 | 613 | Default constructor. |
4cc4bfaf FM |
614 | */ |
615 | wxArchiveIterator(); | |
4cbfec15 FM |
616 | |
617 | /** | |
618 | Construct the iterator that returns all the entries in the archive input | |
619 | stream @e arc. | |
620 | */ | |
4cc4bfaf | 621 | wxArchiveIterator(Arc& arc); |
23324ae1 | 622 | |
4cc4bfaf FM |
623 | /** |
624 | Returns an entry object from the archive input stream, giving away | |
625 | ownership. | |
626 | */ | |
328f5751 | 627 | const T operator*() const; |
23324ae1 | 628 | |
4cc4bfaf FM |
629 | //@{ |
630 | /** | |
631 | Position the input iterator at the next entry in the archive input stream. | |
632 | */ | |
633 | wxArchiveIterator operator++(); | |
4cbfec15 | 634 | wxArchiveIterator operator++(int); |
4cc4bfaf | 635 | //@} |
23324ae1 | 636 | }; |
e54c96f1 | 637 |