00001 #ifndef COLLCOLL_H 00002 #define COLLCOLL_H 00003 00004 #include "zipios-config.h" 00005 00006 #include <string> 00007 #include <vector> 00008 00009 #include "fcoll.h" 00010 00011 namespace zipios { 00012 00013 using std::string ; 00014 00026 class CollectionCollection : public FileCollection { 00027 public: 00033 static inline CollectionCollection &inst() ; 00034 00037 explicit CollectionCollection() ; 00038 00040 inline CollectionCollection( const CollectionCollection &src ) ; 00041 00043 inline const CollectionCollection &operator= ( const CollectionCollection &src ) ; 00044 00051 bool addCollection( const FileCollection &collection ) ; 00052 00063 bool addCollection( FileCollection *collection ) ; 00064 00065 virtual void close() ; 00066 00067 virtual ConstEntries entries() const ; 00068 00069 virtual ConstEntryPointer getEntry( const string &name, 00070 MatchPath matchpath = MATCH ) const ; 00071 00072 virtual istream *getInputStream( const ConstEntryPointer &entry ) ; 00073 00074 virtual istream *getInputStream( const string &entry_name, 00075 MatchPath matchpath = MATCH ) ; 00076 00079 virtual int size() const ; 00080 00081 virtual FileCollection *clone() const ; 00082 00083 virtual ~CollectionCollection() ; 00084 00085 protected: 00091 void getEntry( const string &name, 00092 ConstEntryPointer &cep, 00093 std::vector< FileCollection * >::const_iterator &it, 00094 MatchPath matchpath = MATCH ) const ; 00095 00096 vector< FileCollection * > _collections ; 00097 private: 00098 static CollectionCollection *_inst ; 00099 }; 00100 00101 00105 typedef CollectionCollection CColl ; 00106 00107 00108 // 00109 // Inline (member) functions 00110 // 00111 00112 CollectionCollection &CollectionCollection::inst() { 00113 if( _inst != 0 ) 00114 return *_inst ; 00115 else 00116 return *( _inst = new CollectionCollection ) ; 00117 } 00118 00119 CollectionCollection::CollectionCollection( const CollectionCollection &src ) 00120 : FileCollection( src ) 00121 { 00122 _collections.reserve( src._collections.size() ) ; 00123 std::vector< FileCollection * >::const_iterator it ; 00124 for ( it = src._collections.begin() ; it != src._collections.end() ; ++it ) 00125 _collections.push_back( (*it)->clone() ) ; 00126 } 00127 00128 00129 const CollectionCollection & 00130 CollectionCollection::operator= ( const CollectionCollection &src ) { 00131 this->FileCollection::operator=( src ) ; 00132 // FileCollection::=( static_cast< FileCollection >( src ) ) ; 00133 00134 if ( this != &src ) { 00135 // Destroy current contents. 00136 std::vector< FileCollection * >::const_iterator it ; 00137 for ( it = _collections.begin() ; it != _collections.end() ; ++it ) 00138 delete *it ; 00139 // Then copy src's content. 00140 _collections.clear() ; 00141 _collections.reserve( src._collections.size() ) ; 00142 for ( it = src._collections.begin() ; it != src._collections.end() ; ++it ) 00143 _collections.push_back( (*it)->clone() ) ; 00144 } 00145 return *this ; 00146 } 00147 00148 } // namespace 00149 00150 00151 00152 #endif 00153 00158 /* 00159 Zipios++ - a small C++ library that provides easy access to .zip files. 00160 Copyright (C) 2000 Thomas Søndergaard 00161 00162 This library is free software; you can redistribute it and/or 00163 modify it under the terms of the GNU Lesser General Public 00164 License as published by the Free Software Foundation; either 00165 version 2 of the License, or (at your option) any later version. 00166 00167 This library is distributed in the hope that it will be useful, 00168 but WITHOUT ANY WARRANTY; without even the implied warranty of 00169 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00170 Lesser General Public License for more details. 00171 00172 You should have received a copy of the GNU Lesser General Public 00173 License along with this library; if not, write to the Free Software 00174 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00175 */