Zipios++
|
00001 #ifndef fcoll_H 00002 #define fcoll_H 00003 00004 #include "zipios++/zipios-config.h" 00005 00006 #include <vector> 00007 #include <string> 00008 00009 #include "zipios++/fcollexceptions.h" 00010 #include "zipios++/fileentry.h" 00011 00012 namespace zipios { 00013 00014 using std::vector; 00015 00021 class FileCollection { 00022 public: 00024 explicit FileCollection() 00025 : _filename( "-" ), 00026 _entries ( 0 ), 00027 _valid ( false ) {} 00028 00030 inline FileCollection( const FileCollection &src ) ; 00031 00033 inline const FileCollection &operator= ( const FileCollection &src ) ; 00034 00036 virtual void close() = 0 ; 00037 00044 virtual ConstEntries entries() const ; 00045 00046 enum MatchPath { IGNORE, MATCH } ; 00047 00058 virtual ConstEntryPointer getEntry( const string &name, 00059 MatchPath matchpath = MATCH ) const ; 00069 virtual istream *getInputStream( const ConstEntryPointer &entry ) = 0 ; 00079 virtual istream *getInputStream( const string &entry_name, 00080 MatchPath matchpath = MATCH ) = 0 ; 00084 virtual string getName() const ; 00088 virtual int size() const ; 00089 00093 bool isValid() const { return _valid ; } 00094 00099 virtual FileCollection *clone() const = 0 ; 00100 00101 00103 virtual ~FileCollection () ; 00104 protected: 00105 string _filename ; 00106 Entries _entries ; 00107 bool _valid ; 00108 }; 00109 00110 00111 // 00112 // Inline methods 00113 // 00114 00115 FileCollection::FileCollection( const FileCollection &src ) 00116 : _filename( src._filename ), 00117 _valid ( src._valid ) 00118 { 00119 _entries.reserve( src._entries.size() ) ; 00120 Entries::const_iterator it ; 00121 for ( it = src._entries.begin() ; it != src._entries.end() ; ++it ) 00122 _entries.push_back( (*it)->clone() ) ; 00123 } 00124 00125 const FileCollection &FileCollection::operator= ( const FileCollection &src ) { 00126 if ( this != &src ) { 00127 _filename = src._filename ; 00128 _valid = src._valid ; 00129 _entries.clear() ; 00130 _entries.reserve( src._entries.size() ) ; 00131 00132 Entries::const_iterator it ; 00133 for ( it = src._entries.begin() ; it != src._entries.end() ; ++it ) 00134 _entries.push_back( (*it)->clone() ) ; 00135 } 00136 return *this ; 00137 } 00138 00139 inline ostream & operator<< (ostream &os, const FileCollection& collection) { 00140 os << "collection '" << collection.getName() << "' {" ; 00141 ConstEntries entries = collection.entries(); 00142 ConstEntries::const_iterator it; 00143 bool isFirst=true; 00144 for (it=entries.begin(); it != entries.end(); ++it) { 00145 if(! isFirst) 00146 os << ", "; 00147 isFirst = false; 00148 os << (*it)->getName(); 00149 } 00150 os << "}"; 00151 return os; 00152 } 00153 00154 00155 } // namespace 00156 00157 #endif 00158 00159 00292 /* 00293 Zipios++ - a small C++ library that provides easy access to .zip files. 00294 Copyright (C) 2000 Thomas Søndergaard 00295 00296 This library is free software; you can redistribute it and/or 00297 modify it under the terms of the GNU Lesser General Public 00298 License as published by the Free Software Foundation; either 00299 version 2 of the License, or (at your option) any later version. 00300 00301 This library is distributed in the hope that it will be useful, 00302 but WITHOUT ANY WARRANTY; without even the implied warranty of 00303 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00304 Lesser General Public License for more details. 00305 00306 You should have received a copy of the GNU Lesser General Public 00307 License along with this library; if not, write to the Free Software 00308 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00309 */