fcoll.h
Go to the documentation of this file.
#ifndef fcoll_H
#define fcoll_H
#include "zipios++/zipios-config.h"
#include <vector>
#include <string>
#include "zipios++/fcollexceptions.h"
#include "zipios++/fileentry.h"
namespace zipios {
using std::vector;
class FileCollection {
public:
explicit FileCollection()
: _filename( "-" ),
_entries ( 0 ),
_valid ( false ) {}
inline FileCollection( const FileCollection &src ) ;
inline const FileCollection &operator= ( const FileCollection &src ) ;
virtual void close() = 0 ;
virtual ConstEntries entries() const ;
enum MatchPath { IGNORE, MATCH } ;
virtual ConstEntryPointer getEntry( const string &name,
MatchPath matchpath = MATCH ) const ;
virtual istream *getInputStream( const ConstEntryPointer &entry ) = 0 ;
virtual istream *getInputStream( const string &entry_name,
MatchPath matchpath = MATCH ) = 0 ;
virtual string getName() const ;
virtual int size() const ;
bool isValid() const { return _valid ; }
virtual FileCollection *clone() const = 0 ;
virtual ~FileCollection () ;
protected:
string _filename ;
Entries _entries ;
bool _valid ;
};
//
// Inline methods
//
FileCollection::FileCollection( const FileCollection &src )
: _filename( src._filename ),
_valid ( src._valid )
{
_entries.reserve( src._entries.size() ) ;
Entries::const_iterator it ;
for ( it = src._entries.begin() ; it != src._entries.end() ; ++it )
_entries.push_back( (*it)->clone() ) ;
}
const FileCollection &FileCollection::operator= ( const FileCollection &src ) {
if ( this != &src ) {
_filename = src._filename ;
_valid = src._valid ;
_entries.clear() ;
_entries.reserve( src._entries.size() ) ;
Entries::const_iterator it ;
for ( it = src._entries.begin() ; it != src._entries.end() ; ++it )
_entries.push_back( (*it)->clone() ) ;
}
return *this ;
}
inline ostream & operator<< (ostream &os, const FileCollection& collection) {
os << "collection '" << collection.getName() << "' {" ;
ConstEntries entries = collection.entries();
ConstEntries::const_iterator it;
bool isFirst=true;
for (it=entries.begin(); it != entries.end(); ++it) {
if(! isFirst)
os << ", ";
isFirst = false;
os << (*it)->getName();
}
os << "}";
return os;
}
} // namespace
#endif
/*
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
FileCollection is an abstract baseclass that represents a collection of files.
Definition fcoll.h:21
zipios::FileCollection::operator=
const FileCollection & operator=(const FileCollection &src)
Copy assignment operator.
Definition fcoll.h:125
zipios::FileCollection::FileCollection
FileCollection()
FileCollection constructor.
Definition fcoll.h:24
zipios::FileCollection::getInputStream
virtual istream * getInputStream(const string &entry_name, MatchPath matchpath=MATCH)=0
Returns a pointer to an opened istream for the specified entry name.
zipios::FileCollection::close
virtual void close()=0
Closes the FileCollection.
zipios::FileCollection::getName
virtual string getName() const
Returns the name of the FileCollection.
Definition fcoll.cpp:50
zipios::FileCollection::isValid
bool isValid() const
The member function returns true if the collection is valid.
Definition fcoll.h:93
zipios::FileCollection::getInputStream
virtual istream * getInputStream(const ConstEntryPointer &entry)=0
Returns a pointer to an opened istream for the specified FileEntry.
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::FileCollection::clone
virtual FileCollection * clone() const =0
Create a heap allocated clone of the object this method is called for.
fcollexceptions.h
Header file that defines a number of exceptions used by FileCollection and its subclasses.
fileentry.h
Header file that defines FileEntry.
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
zipios::Entries
vector< EntryPointer > Entries
Entries is a vector of EntryPointer's.
Definition fileentry.h:40