wxarchiveiteratoran input iterator template class that can be used to transfer an archive's catalogue to a container. it is only available if wxuse_stl is set to 1 in setup.h, and the uses for it outlined below require a compiler which supports member templates.
template <class arc, class t = typename arc::entry_type*> class wxarchiveiterator { // this constructor creates an 'end of sequence' object wxarchiveiterator(); // template parameter 'arc' should be the type of an archive input stream wxarchiveiterator(arc& arc) { /* ... */ };the first template parameter should be the type of archive input stream (e.g. wxarchiveinputstream) and the second can either be a pointer to an entry (e.g. wxarchiveentry*), or a string/pointer pair (e.g. std::pair<wxstring, wxarchiveentry*>). the <wx/archive.h> header defines the following typedefs:
typedef wxarchiveiterator<wxarchiveinputstream> wxarchiveiter; typedef wxarchiveiterator<wxarchiveinputstream, std::pair<wxstring, wxarchiveentry*> > wxarchivepairiter;the header for any implementation of this interface should define similar typedefs for its types, for example in <wx/zipstrm.h> there is:
typedef wxarchiveiterator<wxzipinputstream> wxzipiter; typedef wxarchiveiterator<wxzipinputstream, std::pair<wxstring, wxzipentry*> > wxzippairiter;transferring the catalogue of an archive arc to a vector cat, can then be done something like this:
std::vector<wxarchiveentry*> cat((wxarchiveiter)arc, wxarchiveiter());when the iterator is dereferenced, it gives away ownership of an entry object. so in the above example, when you have finished with cat you must delete the pointers it contains. if you have smart pointers with normal copy semantics (i.e. not auto_ptr or wxscopedptr), then you can create an iterator which uses them instead. for example, with a smart pointer class for zip entries zipentryptr:
typedef std::vector<zipentryptr> zipcatalog; typedef wxarchiveiterator<wxzipinputstream, zipentryptr> zipiter; zipcatalog cat((zipiter)zip, zipiter());iterators that return std::pair objects can be used to populate a std::multimap, to allow entries to be looked up by name. the string is initialised using the wxarchiveentry object's getinternalname() function.
typedef std::multimap<wxstring, wxzipentry*> zipcatalog; zipcatalog cat((wxzippairiter)zip, wxzippairiter());note that this iterator also gives away ownership of an entry object each time it is dereferenced. so in the above example, when you have finished with cat you must delete the pointers it contains. or if you have them, a pair containing a smart pointer can be used (again zipentryptr), no worries about ownership:
typedef std::multimap<wxstring, zipentryptr> zipcatalog; typedef wxarchiveiterator<wxzipinputstream, std::pair<wxstring, zipentryptr> > zippairiter; zipcatalog cat((zippairiter)zip, zippairiter());derived from no base class include files <wx/archive.h> see also
wxarchiveentry data structures typedef std::input_iterator_tag iterator_category typedef t value_type typedef ptrdiff_t difference_type typedef t* pointer typedef t& referencemembers
wxarchiveiterator::wxarchiveiterator
wxarchiveiterator::wxarchiveiteratorwxarchiveiterator() construct an 'end of sequence' instance. wxarchiveiterator(arc& arc) construct iterator that returns all the entries in the archive input stream arc.
wxarchiveiterator::operator*const t& operator*() const returns an entry object from the archive input stream, giving away ownership.
wxarchiveiterator::operator++wxarchiveiterator& operator++() wxarchiveiterator& operator++(int) position the input iterator at the next entry in the archive input stream.
|