fcoll.cpp
Go to the documentation of this file.
#include "zipios++/zipios-config.h"
#include <algorithm>
#include <string>
#include <vector>
#include "zipios++/fcoll.h"
namespace zipios {
using std::find_if ;
// FIXME: make InvalidStateException message customized for
// subclasses. maybe make an InvalidStateException factory ;-)
ConstEntries FileCollection::entries() const {
if ( ! _valid )
throw InvalidStateException( "Attempt to get entries from an invalid FileCollection" ) ;
// The constructor below is not in all vector impl. (not those
// without member templates)
// ConstEntries ( _entries.begin(), _entries.end() ) ;
// Instead of using that we copy the vector manually
ConstEntries cep_vec ;
cep_vec.reserve( _entries.size() ) ;
Entries::const_iterator cit ;
for ( cit = _entries.begin() ; cit != _entries.end() ; ++cit )
cep_vec.push_back( *cit ) ;
return cep_vec ;
}
ConstEntryPointer FileCollection::getEntry( const string &name,
MatchPath matchpath ) const {
if ( ! _valid )
throw InvalidStateException( "Attempt to get an entry from an invalid FileCollection" ) ;
Entries::const_iterator iter ;
if ( matchpath == MATCH )
iter = find_if( _entries.begin(), _entries.end(), FileEntry::MatchName( name ) ) ;
else
iter = find_if( _entries.begin(), _entries.end(), FileEntry::MatchFileName( name ) ) ;
if ( iter == _entries.end() )
return 0 ;
else
return *iter ;
}
string FileCollection::getName() const {
if ( ! _valid )
throw InvalidStateException( "Attempt to get the name of an invalid FileCollection" ) ;
return _filename ;
}
int FileCollection::size() const {
if ( ! _valid )
throw InvalidStateException( "Attempt to get size of an invalid FileCollection" ) ;
return _entries.size() ;
}
FileCollection::~FileCollection() {
}
} // namespace
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
zipios::FileCollection::getName
virtual string getName() const
Returns the name of the FileCollection.
Definition fcoll.cpp:50
zipios::FileCollection::getEntry
virtual ConstEntryPointer getEntry(const string &name, MatchPath matchpath=MATCH) const
Returns a ConstEntryPointer to a FileEntry object for the entry with the specified name.
Definition fcoll.cpp:34
zipios::FileCollection::~FileCollection
virtual ~FileCollection()
FileCollection destructor.
Definition fcoll.cpp:63
zipios::FileCollection::entries
virtual ConstEntries entries() const
Returns a vector of const pointers to the entries in the FileCollection.
Definition fcoll.cpp:17
zipios::FileCollection::size
virtual int size() const
Returns the number of entries in the FileCollection.
Definition fcoll.cpp:57
zipios::FileEntry::MatchFileName
Function object to be used with the STL find_if algorithm to find a FileEntry in a container,...
Definition fileentry.h:195
zipios::FileEntry::MatchName
Function object to be used with the STL find_if algorithm to find a FileEntry in a container,...
Definition fileentry.h:181
zipios::InvalidStateException
An object member function may throw this exception, if the operation it normally performs is inapprop...
Definition fcollexceptions.h:47
fcoll.h
Header file that defines FileCollection.
zipios::ConstEntryPointer
SimpleSmartPointer< const FileEntry > ConstEntryPointer
ConstEntryPointer is a SimpleSmartPointer for const FileEntry's.
Definition fileentry.h:37
zipios::ConstEntries
vector< EntryPointer > ConstEntries
ConstEntries is a vector of ConstEntryPointer's.
Definition fileentry.h:43