Zipios++
fileentry.h
Go to the documentation of this file.
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 
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 
25 enum StorageMethod { STORED = 0, SHRUNK, REDUCED1, REDUCED2,
26  REDUCED3, REDUCED4, IMPLODED, RESERVED,
27  DEFLATED } ;
28 
29 class FileEntry ;
30 
34 
35 
38 
40 typedef vector< EntryPointer > Entries ;
41 
43 typedef vector< EntryPointer > ConstEntries ;
44 
45 
46 
52 class FileEntry {
53 public:
54 
55  /* Default construcotr, copy constructor and copy assignment
56  operator are sufficient. */
57 
62  virtual string getComment() const = 0 ;
69  virtual uint32 getCompressedSize() const = 0 ;
74  virtual uint32 getCrc() const = 0 ;
80  virtual vector< unsigned char > getExtra() const = 0 ;
85  virtual StorageMethod getMethod() const = 0 ;
91  virtual string getName() const = 0 ;
95  virtual string getFileName() const = 0 ;
99  virtual uint32 getSize() const = 0 ;
103  virtual int getTime() const = 0 ;
109  virtual bool isValid() const = 0 ;
110  // virtual int hashCode() const = 0 ;
116  virtual bool isDirectory() const = 0 ;
117 
121  virtual void setComment( const string &comment ) = 0 ;
125  virtual void setCompressedSize( uint32 size ) = 0 ;
129  virtual void setCrc( uint32 crc ) = 0 ;
133  virtual void setExtra( const vector< unsigned char > &extra ) = 0 ;
137  virtual void setMethod( StorageMethod method ) = 0 ;
141  virtual void setName( const string &name ) = 0 ;
145  virtual void setSize( uint32 size ) = 0 ;
149  virtual void setTime( int time ) = 0 ;
150 
154  virtual string toString() const = 0 ;
155 
160  virtual FileEntry *clone() const = 0 ;
161 
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 
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 
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 
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 */
virtual FileEntry * clone() const =0
Create a heap allocated clone of the object this method is called for.
virtual uint32 getSize() const =0
Returns the (uncompressed) size of the entry data.
virtual void setCompressedSize(uint32 size)=0
Set the compressed size field of the entry.
virtual string toString() const =0
Returns a human-readable string representation of the entry.
Header file that defines some simple data types.
SimpleSmartPointer is a simple reference counting smart pointer template.
vector< EntryPointer > ConstEntries
ConstEntries is a vector of ConstEntryPointer&#39;s.
Definition: fileentry.h:43
virtual void setCrc(uint32 crc)=0
Sets the crc field.
Header file that defines SimpleSmartPointer and ReferenceCount.
virtual StorageMethod getMethod() const =0
Returns the method used to store the entry in the FileCollection.
Function object to be used with the STL find_if algorithm to find a FileEntry in a container...
Definition: fileentry.h:195
virtual void setTime(int time)=0
Sets the time field for the entry.
vector< EntryPointer > Entries
Entries is a vector of EntryPointer&#39;s.
Definition: fileentry.h:40
virtual int getTime() const =0
Returns the date and time of FIXME: what?
virtual void setExtra(const vector< unsigned char > &extra)=0
Sets the extra field.
virtual void setName(const string &name)=0
Sets the name field for the entry.
virtual string getName() const =0
Returns the full filename of the entry, including a path if the entry is stored in a subfolder...
virtual ~FileEntry()
FileEntry destructor.
Definition: fileentry.h:163
virtual void setComment(const string &comment)=0
Sets the comment field for the FileEntry.
ReferenceCount is useful to ensure proper handling of the reference count for (objects of) classes ha...
Function object to be used with the STL find_if algorithm to find a FileEntry in a container...
Definition: fileentry.h:181
virtual string getFileName() const =0
Returns the filename of the entry.
virtual string getComment() const =0
Returns the comment of the entry, if it has one.
virtual void setSize(uint32 size)=0
Sets the size field for the entry.
A FileEntry represents an entry in a FileCollection.
Definition: fileentry.h:52
virtual void setMethod(StorageMethod method)=0
Sets the storage method field for the entry.
StorageMethod
The types used with FileEntry::setMethod and FileEntry::getMethod.
Definition: fileentry.h:25
virtual uint32 getCrc() const =0
Returns the Crc for the entry, if it has one.
virtual bool isDirectory() const =0
Returns true if the entry is a directory.
virtual vector< unsigned char > getExtra() const =0
Returns a vector of bytes of extra data that may be stored with the entry.
virtual uint32 getCompressedSize() const =0
Returns the compressed size of the entry.
virtual bool isValid() const =0
Any method or operator that initializes a FileEntry may set a flag, that specifies whether the read e...