Main Page   Class Hierarchy   Compound List   File List   Compound Members  

fcoll.cpp

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

Generated at Tue Aug 14 20:39:26 2001 for Zipios++ by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000