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