4 #include "zipios++/zipios-config.h"
8 #include "zipios++/meta-iostreams.h"
10 #include "zipios++/simplesmartptr.h"
11 #include "zipios++/zipios_defs.h"
20 /** The types used with FileEntry::setMethod and
21 FileEntry::getMethod. The current entries are the types supported
22 by the zip format. The numbering also matches the numbering used
23 in the zip file format, ie STORED is indicated by a 0 in the
24 method field in a zip file and so on. */
25 enum StorageMethod { STORED = 0, SHRUNK, REDUCED1, REDUCED2,
26 REDUCED3, REDUCED4, IMPLODED, RESERVED,
31 /** \typedef typedef SimpleSmartPointer< FileEntry > EntryPointer
32 EntryPointer is a SimpleSmartPointer for FileEntry's. */
33 typedef SimpleSmartPointer< FileEntry > EntryPointer ;
36 /** ConstEntryPointer is a SimpleSmartPointer for const FileEntry's. */
37 typedef SimpleSmartPointer< const FileEntry > ConstEntryPointer ;
39 /** Entries is a vector of EntryPointer's */
40 typedef vector< EntryPointer > Entries ;
42 /** ConstEntries is a vector of ConstEntryPointer's */
43 typedef vector< EntryPointer > ConstEntries ;
47 /** A FileEntry represents an entry in a FileCollection. The interface
48 is a copy of the ZipEntry interface from the java.util.zip
49 package. The name has been changed to FileEntry, as FileCollection
50 is a more general abstraction, that covers other types of file
51 collections than just zip files. */
55 /* Default construcotr, copy constructor and copy assignment
56 operator are sufficient. */
58 /** Returns the comment of the entry, if it has one. Otherwise it
59 returns an empty string.
60 @return the comment associated with the entry, if there is one.
62 virtual string getComment() const = 0 ;
63 /** Returns the compressed size of the entry. If the entry is not
64 stored in a compressed format, the uncompressed size is
66 @return the compressed size of the entry. If the entry is stored without
67 compression the uncompressed size is returned.
69 virtual uint32 getCompressedSize() const = 0 ;
70 /** Returns the Crc for the entry, if it has one. FIXME: what is
71 returned if it doesn't have one?
72 @return the Crc for the entry, if it has one.
74 virtual uint32 getCrc() const = 0 ;
75 /** Returns a vector of bytes of extra data that may be stored with
77 @return A vector< unsigned char > of extra bytes that may potentially
78 be associated with an entry.
80 virtual vector< unsigned char > getExtra() const = 0 ;
81 /** Returns the method used to store the entry in the FileCollection.
82 @return the storage method used to store the entry in the collection.
85 virtual StorageMethod getMethod() const = 0 ;
86 /** Returns the full filename of the entry, including a path if the
87 entry is stored in a subfolder.
88 @return the filename of the entry, including path if the entry is stored
91 virtual string getName() const = 0 ;
92 /** Returns the filename of the entry.
93 @return Returns the filename of the entry.
95 virtual string getFileName() const = 0 ;
96 /** Returns the (uncompressed) size of the entry data.
97 @return Returns the (uncompressed) size of the entry.
99 virtual uint32 getSize() const = 0 ;
100 /** Returns the date and time of FIXME: what?
101 @return the date and time of the entry.
103 virtual int getTime() const = 0 ;
104 /** Any method or operator that initializes a FileEntry may set a
105 flag, that specifies whether the read entry is valid or not. If
106 it isn't this method returns false.
107 @return true if the FileEntry has been parsed succesfully.
109 virtual bool isValid() const = 0 ;
110 // virtual int hashCode() const = 0 ;
111 /** Returns true if the entry is a directory. A directory entry is
112 an entry which name ends with a separator ('/' for Unix systems,
113 '\' for Windows and DOS systems.
114 @return true if the entry is a directory.
116 virtual bool isDirectory() const = 0 ;
118 /** Sets the comment field for the FileEntry.
119 @param comment string with the new comment.
121 virtual void setComment( const string &comment ) = 0 ;
122 /** Set the compressed size field of the entry.
123 @param size value to set the compressed size field of the entry to.
125 virtual void setCompressedSize( uint32 size ) = 0 ;
126 /** Sets the crc field.
127 @param crc value to set the crc field to.
129 virtual void setCrc( uint32 crc ) = 0 ;
130 /** Sets the extra field.
131 @param extra the extra field is set to this value.
133 virtual void setExtra( const vector< unsigned char > &extra ) = 0 ;
134 /** Sets the storage method field for the entry.
135 @param method the method field is set to the specified value.
137 virtual void setMethod( StorageMethod method ) = 0 ;
138 /** Sets the name field for the entry.
139 @param name the name field is set to the specified value.
141 virtual void setName( const string &name ) = 0 ;
142 /** Sets the size field for the entry.
143 @param size the size field is set to this value.
145 virtual void setSize( uint32 size ) = 0 ;
146 /** Sets the time field for the entry.
147 @param time the time field is set to the specified value.
149 virtual void setTime( int time ) = 0 ;
151 /** Returns a human-readable string representation of the entry.
152 @return a human-readable string representation of the entry.
154 virtual string toString() const = 0 ;
156 /** Create a heap allocated clone of the object this method is called for. The
157 caller is responsible for deallocating the clone when he is done with it.
158 @return A heap allocated copy of the object this method is called for.
160 virtual FileEntry *clone() const = 0 ;
162 /** FileEntry destructor. */
163 virtual ~FileEntry() {}
167 class MatchFileName ;
169 friend class SimpleSmartPointer< FileEntry > ;
170 friend class SimpleSmartPointer< const FileEntry > ;
171 void ref() const { _refcount.ref() ; }
172 unsigned int unref() const { return _refcount.unref() ; }
174 ReferenceCount< FileEntry > _refcount ;
177 /** Function object to be used with the STL find_if algorithm to
178 find a FileEntry in a container, which name (as obtained with
179 FileEntry::getName()) is identical to the name specified in the
180 MatchName constructor. */
181 class FileEntry::MatchName {
183 explicit MatchName( const string &name ) : _name( name ) {}
184 bool operator() ( const ConstEntryPointer &entry ) {
185 return entry->getName() == _name ;
191 /** Function object to be used with the STL find_if algorithm to
192 find a FileEntry in a container, which name (as obtained with
193 FileEntry::getFileName()) is identical to the name specified in the
194 MatchName constructor. */
195 class FileEntry::MatchFileName {
197 explicit MatchFileName( const string &name ) : _name( name ) {}
198 bool operator() ( const ConstEntryPointer &entry ) {
199 return entry->getFileName() == _name ;
205 ostream &operator<< ( ostream &os, const FileEntry &entry ) ;
207 inline ostream &operator<< ( ostream &os, const ConstEntryPointer &entry ) {
220 Header file that defines FileEntry.
224 Zipios++ - a small C++ library that provides easy access to .zip files.
225 Copyright (C) 2000 Thomas Søndergaard
227 This library is free software; you can redistribute it and/or
228 modify it under the terms of the GNU Lesser General Public
229 License as published by the Free Software Foundation; either
230 version 2 of the License, or (at your option) any later version.
232 This library is distributed in the hope that it will be useful,
233 but WITHOUT ANY WARRANTY; without even the implied warranty of
234 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
235 Lesser General Public License for more details.
237 You should have received a copy of the GNU Lesser General Public
238 License along with this library; if not, write to the Free Software
239 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA