00001 00002 #include "zipios-config.h" 00003 00004 #include <algorithm> 00005 #include <string> 00006 #include <vector> 00007 00008 #include "fcoll.h" 00009 00010 namespace zipios { 00011 00012 using std::find_if ; 00013 00014 FileCollection::FileCollection( const FileCollection &src ) 00015 : _filename( src._filename ), 00016 _valid ( src._valid ) 00017 { 00018 _entries.reserve( src._entries.size() ) ; 00019 Entries::const_iterator it ; 00020 for ( it = src._entries.begin() ; it != src._entries.end() ; ++it ) 00021 _entries.push_back( (*it)->clone() ) ; 00022 } 00023 00024 const FileCollection &FileCollection::operator= ( const FileCollection &src ) { 00025 if ( this != &src ) { 00026 _filename = src._filename ; 00027 _valid = src._valid ; 00028 _entries.clear() ; 00029 _entries.reserve( src._entries.size() ) ; 00030 00031 Entries::const_iterator it ; 00032 for ( it = src._entries.begin() ; it != src._entries.end() ; ++it ) 00033 _entries.push_back( (*it)->clone() ) ; 00034 } 00035 return *this ; 00036 } 00037 00038 // FIXME: make InvalidStateException message customized for 00039 // subclasses. maybe make an InvalidStateException factory ;-) 00040 00041 ConstEntries FileCollection::entries() const { 00042 if ( ! _valid ) 00043 throw InvalidStateException( "Attempt to get entries from an invalid FileCollection" ) ; 00044 00045 // The constructor below is not in all vector impl. (not those 00046 // without member templates) 00047 // ConstEntries ( _entries.begin(), _entries.end() ) ; 00048 // Instead of using that we copy the vector manually 00049 ConstEntries cep_vec ; 00050 cep_vec.reserve( _entries.size() ) ; 00051 Entries::const_iterator cit ; 00052 for ( cit = _entries.begin() ; cit != _entries.end() ; ++cit ) 00053 cep_vec.push_back( *cit ) ; 00054 00055 return cep_vec ; 00056 } 00057 00058 ConstEntryPointer FileCollection::getEntry( const string &name, 00059 MatchPath matchpath ) const { 00060 if ( ! _valid ) 00061 throw InvalidStateException( "Attempt to get an entry from an invalid FileCollection" ) ; 00062 00063 Entries::const_iterator iter ; 00064 if ( matchpath == MATCH ) 00065 iter = find_if( _entries.begin(), _entries.end(), FileEntry::MatchName( name ) ) ; 00066 else 00067 iter = find_if( _entries.begin(), _entries.end(), FileEntry::MatchFileName( name ) ) ; 00068 if ( iter == _entries.end() ) 00069 return 0 ; 00070 else 00071 return *iter ; 00072 } 00073 00074 string FileCollection::getName() const { 00075 if ( ! _valid ) 00076 throw InvalidStateException( "Attempt to get the name of an invalid FileCollection" ) ; 00077 return _filename ; 00078 } 00079 00080 00081 int FileCollection::size() const { 00082 if ( ! _valid ) 00083 throw InvalidStateException( "Attempt to get size of an invalid FileCollection" ) ; 00084 return _entries.size() ; 00085 } 00086 00087 FileCollection::~FileCollection() { 00088 } 00089 00090 00091 } // namespace 00092 00097 /* 00098 Zipios++ - a small C++ library that provides easy access to .zip files. 00099 Copyright (C) 2000 Thomas Søndergaard 00100 00101 This library is free software; you can redistribute it and/or 00102 modify it under the terms of the GNU Lesser General Public 00103 License as published by the Free Software Foundation; either 00104 version 2 of the License, or (at your option) any later version. 00105 00106 This library is distributed in the hope that it will be useful, 00107 but WITHOUT ANY WARRANTY; without even the implied warranty of 00108 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00109 Lesser General Public License for more details. 00110 00111 You should have received a copy of the GNU Lesser General Public 00112 License along with this library; if not, write to the Free Software 00113 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00114 */