]> git.donarmstrong.com Git - flightcrew.git/blob - src/zipios/zipios++/fileentry.h
Imported Upstream version 0.7.2+dfsg
[flightcrew.git] / src / zipios / zipios++ / fileentry.h
1 #ifndef FILEENTRY_H
2 #define FILEENTRY_H
3
4 #include "zipios++/zipios-config.h"
5
6 #include <string>
7 #include <vector>
8 #include "zipios++/meta-iostreams.h"
9
10 #include "zipios++/simplesmartptr.h"
11 #include "zipios++/zipios_defs.h"
12
13 namespace zipios {
14
15 using std::vector ;
16 using std::ostream ;
17 using std::istream ;
18 using std::string ;
19
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,
27                      DEFLATED } ;
28
29 class FileEntry ;
30
31 /** \typedef typedef SimpleSmartPointer< FileEntry > EntryPointer
32     EntryPointer is a SimpleSmartPointer for FileEntry's.  */
33 typedef SimpleSmartPointer< FileEntry > EntryPointer ;
34
35
36 /** ConstEntryPointer is a SimpleSmartPointer for const FileEntry's.  */
37 typedef SimpleSmartPointer< const FileEntry > ConstEntryPointer ;
38
39 /** Entries is a vector of EntryPointer's */
40 typedef vector< EntryPointer >      Entries ;
41
42 /** ConstEntries is a vector of ConstEntryPointer's */
43 typedef vector< EntryPointer > ConstEntries ;
44
45
46
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. */
52 class FileEntry {
53 public:
54
55   /* Default construcotr, copy constructor and copy assignment
56      operator are sufficient. */
57
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.
61   */
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
65       returned.
66       @return the compressed size of the entry. If the entry is stored without 
67       compression the uncompressed size is returned.
68   */
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.
73   */
74   virtual uint32 getCrc() const = 0 ;
75   /** Returns a vector of bytes of extra data that may be stored with
76       the entry.
77       @return A vector< unsigned char > of extra bytes that may potentially
78       be associated with an entry.
79   */
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.
83       @see StorageMethod.
84    */
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
89       in a sub-folder.
90   */
91   virtual string getName() const = 0 ;
92   /** Returns the filename of the entry.  
93       @return Returns the filename of the entry.
94   */
95   virtual string getFileName() const = 0 ;
96   /** Returns the (uncompressed) size of the entry data.  
97       @return Returns the (uncompressed) size of the entry.
98    */
99   virtual uint32 getSize() const = 0 ;
100   /** Returns the date and time of FIXME: what?  
101       @return the date and time of the entry.
102   */
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.
108    */
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.
115    */
116   virtual bool isDirectory() const = 0 ;
117   
118   /** Sets the comment field for the FileEntry.
119       @param comment string with the new comment.
120   */
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.
124   */
125   virtual void setCompressedSize( uint32 size ) = 0 ;
126   /** Sets the crc field.
127       @param crc value to set the crc field to.
128   */
129   virtual void setCrc( uint32 crc ) = 0 ;
130   /** Sets the extra field.
131       @param extra the extra field is set to this value.
132   */
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.
136   */
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.
140   */
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.
144   */
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.
148   */
149   virtual void setTime( int time ) = 0 ;
150   
151   /** Returns a human-readable string representation of the entry.
152       @return a human-readable string representation of the entry.
153   */
154   virtual string toString() const = 0 ;
155
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.
159   */
160   virtual FileEntry *clone() const = 0 ;
161   
162   /** FileEntry destructor. */
163   virtual ~FileEntry() {}
164
165 //  protected:
166   class MatchName ;
167   class MatchFileName ;
168 protected:
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() ; }
173
174   ReferenceCount< FileEntry > _refcount ;
175 };
176
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 {
182 public:
183   explicit MatchName( const string &name ) : _name( name ) {}
184   bool operator() ( const ConstEntryPointer &entry ) {
185     return entry->getName() == _name ;
186   }
187 private:
188   string _name ;
189 };
190
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 {
196 public:
197   explicit MatchFileName( const string &name ) : _name( name ) {}
198   bool operator() ( const ConstEntryPointer &entry ) {
199     return entry->getFileName() == _name ;
200   }
201 private:
202   string _name ;
203 };
204
205 ostream &operator<< ( ostream &os, const FileEntry &entry ) ;
206
207 inline ostream &operator<< ( ostream &os, const ConstEntryPointer &entry ) {
208   os << *entry ;
209   return os ;
210 }
211
212
213
214 } // namespace
215
216 #endif
217
218
219 /** \file
220     Header file that defines FileEntry.
221 */
222
223 /*
224   Zipios++ - a small C++ library that provides easy access to .zip files.
225   Copyright (C) 2000  Thomas Søndergaard
226   
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.
231   
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.
236   
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
240 */