2 #include "zipios++/zipios-config.h"
4 #include "zipios++/meta-iostreams.h"
6 #include "zipios++/collcoll.h"
7 #include "zipios_common.h"
13 CollectionCollection *CollectionCollection::_inst = 0 ;
16 CollectionCollection::CollectionCollection() {
17 _valid = true ; // we're valid even though we are empty!
21 bool CollectionCollection::addCollection( const FileCollection &collection ) {
23 throw InvalidStateException( "Attempt to add a FileCollection to an invalid CollectionCollection" ) ;
24 if ( this == &collection || ! collection.isValid() )
26 _collections.push_back( collection.clone() ) ;
31 bool CollectionCollection::addCollection( FileCollection *collection ) {
33 throw InvalidStateException( "Attempt to add a FileCollection to an invalid CollectionCollection" ) ;
34 if ( collection == 0 || this == collection || ! collection->isValid() )
36 _collections.push_back( collection ) ;
41 void CollectionCollection::close() {
46 ConstEntries CollectionCollection::entries() const {
48 throw InvalidStateException( "Attempt to get entries from an invalid CollectionCollection" ) ;
50 ConstEntries all_entries ;
51 std::vector< FileCollection * >::const_iterator it ;
52 for ( it = _collections.begin() ; it != _collections.end() ; it++ )
53 all_entries += (*it)->entries() ;
58 ConstEntryPointer CollectionCollection::getEntry( const string &name,
59 MatchPath matchpath ) const {
61 throw InvalidStateException( "Attempt to get an entry from an invalid CollectionCollection" ) ;
62 // Returns the first matching entry.
63 std::vector< FileCollection * >::const_iterator it ;
64 ConstEntryPointer cep ;
66 getEntry( name, cep, it, matchpath ) ;
72 istream *CollectionCollection::getInputStream( const ConstEntryPointer &entry ) {
74 throw InvalidStateException( "Attempt to get an input stream from an invalid CollectionCollection" ) ;
76 return getInputStream( entry->getName() ) ;
80 istream *CollectionCollection::getInputStream( const string &entry_name,
81 MatchPath matchpath ) {
83 throw InvalidStateException( "Attempt to get an input stream from an invalid CollectionCollection" ) ;
85 std::vector< FileCollection * >::const_iterator it ;
86 ConstEntryPointer cep ;
88 getEntry( entry_name, cep, it, matchpath ) ;
93 return (*it)->getInputStream( entry_name ) ;
98 int CollectionCollection::size() const {
100 throw InvalidStateException( "Attempt to get the size of an invalid CollectionCollection" ) ;
102 std::vector< FileCollection * >::const_iterator it ;
103 for ( it = _collections.begin() ; it != _collections.end() ; it++ )
104 sz += (*it)->size() ;
108 FileCollection *CollectionCollection::clone() const {
109 return new CollectionCollection( *this ) ;
112 CollectionCollection::~CollectionCollection() {
113 std::vector< FileCollection * >::iterator it ;
114 for ( it = _collections.begin() ; it != _collections.end() ; ++it )
120 // Protected member functions
123 void CollectionCollection::getEntry( const string &name,
124 ConstEntryPointer &cep,
125 std::vector< FileCollection * >::const_iterator &it,
126 MatchPath matchpath ) const {
128 // Returns the first matching entry.
130 for ( it = _collections.begin() ; it != _collections.end() ; it++ ) {
131 cep = (*it)->getEntry( name, matchpath ) ;
142 Implementation of CollectionCollection.
146 Zipios++ - a small C++ library that provides easy access to .zip files.
147 Copyright (C) 2000 Thomas Søndergaard
149 This library is free software; you can redistribute it and/or
150 modify it under the terms of the GNU Lesser General Public
151 License as published by the Free Software Foundation; either
152 version 2 of the License, or (at your option) any later version.
154 This library is distributed in the hope that it will be useful,
155 but WITHOUT ANY WARRANTY; without even the implied warranty of
156 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
157 Lesser General Public License for more details.
159 You should have received a copy of the GNU Lesser General Public
160 License along with this library; if not, write to the Free Software
161 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA