Zipios++
fcoll.h
Go to the documentation of this file.
1 #ifndef fcoll_H
2 #define fcoll_H
3 
4 #include "zipios++/zipios-config.h"
5 
6 #include <vector>
7 #include <string>
8 
10 #include "zipios++/fileentry.h"
11 
12 namespace zipios {
13 
14 using std::vector;
15 
22 public:
24  explicit FileCollection()
25  : _filename( "-" ),
26  _entries ( 0 ),
27  _valid ( false ) {}
28 
30  inline FileCollection( const FileCollection &src ) ;
31 
33  inline const FileCollection &operator= ( const FileCollection &src ) ;
34 
36  virtual void close() = 0 ;
37 
44  virtual ConstEntries entries() const ;
45 
46  enum MatchPath { IGNORE, MATCH } ;
47 
58  virtual ConstEntryPointer getEntry( const string &name,
59  MatchPath matchpath = MATCH ) const ;
69  virtual istream *getInputStream( const ConstEntryPointer &entry ) = 0 ;
79  virtual istream *getInputStream( const string &entry_name,
80  MatchPath matchpath = MATCH ) = 0 ;
84  virtual string getName() const ;
88  virtual int size() const ;
89 
93  bool isValid() const { return _valid ; }
94 
99  virtual FileCollection *clone() const = 0 ;
100 
101 
103  virtual ~FileCollection () ;
104 protected:
105  string _filename ;
106  Entries _entries ;
107  bool _valid ;
108 };
109 
110 
111 //
112 // Inline methods
113 //
114 
116  : _filename( src._filename ),
117  _valid ( src._valid )
118 {
119  _entries.reserve( src._entries.size() ) ;
120  Entries::const_iterator it ;
121  for ( it = src._entries.begin() ; it != src._entries.end() ; ++it )
122  _entries.push_back( (*it)->clone() ) ;
123 }
124 
126  if ( this != &src ) {
127  _filename = src._filename ;
128  _valid = src._valid ;
129  _entries.clear() ;
130  _entries.reserve( src._entries.size() ) ;
131 
132  Entries::const_iterator it ;
133  for ( it = src._entries.begin() ; it != src._entries.end() ; ++it )
134  _entries.push_back( (*it)->clone() ) ;
135  }
136  return *this ;
137 }
138 
139 inline ostream & operator<< (ostream &os, const FileCollection& collection) {
140  os << "collection '" << collection.getName() << "' {" ;
141  ConstEntries entries = collection.entries();
142  ConstEntries::const_iterator it;
143  bool isFirst=true;
144  for (it=entries.begin(); it != entries.end(); ++it) {
145  if(! isFirst)
146  os << ", ";
147  isFirst = false;
148  os << (*it)->getName();
149  }
150  os << "}";
151  return os;
152 }
153 
154 
155 } // namespace
156 
157 #endif
158 
159 
292 /*
293  Zipios++ - a small C++ library that provides easy access to .zip files.
294  Copyright (C) 2000 Thomas Søndergaard
295 
296  This library is free software; you can redistribute it and/or
297  modify it under the terms of the GNU Lesser General Public
298  License as published by the Free Software Foundation; either
299  version 2 of the License, or (at your option) any later version.
300 
301  This library is distributed in the hope that it will be useful,
302  but WITHOUT ANY WARRANTY; without even the implied warranty of
303  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
304  Lesser General Public License for more details.
305 
306  You should have received a copy of the GNU Lesser General Public
307  License along with this library; if not, write to the Free Software
308  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
309 */
virtual void close()=0
Closes the FileCollection.
Header file that defines FileEntry.
virtual FileCollection * clone() const =0
Create a heap allocated clone of the object this method is called for.
virtual ConstEntries entries() const
Definition: fcoll.cpp:17
FileCollection()
FileCollection constructor.
Definition: fcoll.h:24
virtual istream * getInputStream(const ConstEntryPointer &entry)=0
const FileCollection & operator=(const FileCollection &src)
Copy assignment operator.
Definition: fcoll.h:125
virtual int size() const
Returns the number of entries in the FileCollection.
Definition: fcoll.cpp:57
virtual ~FileCollection()
FileCollection destructor.
Definition: fcoll.cpp:63
bool isValid() const
The member function returns true if the collection is valid.
Definition: fcoll.h:93
virtual string getName() const
Returns the name of the FileCollection.
Definition: fcoll.cpp:50
Header file that defines a number of exceptions used by FileCollection and its subclasses.
virtual ConstEntryPointer getEntry(const string &name, MatchPath matchpath=MATCH) const
Definition: fcoll.cpp:34