Zipios++
collcoll.cpp
Go to the documentation of this file.
1
2#include "zipios++/zipios-config.h"
3
4#include "zipios++/meta-iostreams.h"
5
6#include "zipios++/collcoll.h"
7#include "zipios_common.h"
8
9namespace zipios {
10
11using std::ifstream ;
12
13CollectionCollection *CollectionCollection::_inst = 0 ;
14
15
17 _valid = true ; // we're valid even though we are empty!
18}
19
20
22 if ( ! _valid )
23 throw InvalidStateException( "Attempt to add a FileCollection to an invalid CollectionCollection" ) ;
24 if ( this == &collection || ! collection.isValid() )
25 return false ;
26 _collections.push_back( collection.clone() ) ;
27 return true ;
28
29}
30
32 if ( ! _valid )
33 throw InvalidStateException( "Attempt to add a FileCollection to an invalid CollectionCollection" ) ;
34 if ( collection == 0 || this == collection || ! collection->isValid() )
35 return false ;
36 _collections.push_back( collection ) ;
37 return true ;
38}
39
40
42 _valid = false ;
43}
44
45
47 if ( ! _valid )
48 throw InvalidStateException( "Attempt to get entries from an invalid CollectionCollection" ) ;
49
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() ;
54 return all_entries ;
55}
56
57
59 MatchPath matchpath ) const {
60 if ( ! _valid )
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 ;
65
66 getEntry( name, cep, it, matchpath ) ;
67
68 return cep ;
69}
70
71
73 if ( ! _valid )
74 throw InvalidStateException( "Attempt to get an input stream from an invalid CollectionCollection" ) ;
75
76 return getInputStream( entry->getName() ) ;
77}
78
79
80istream *CollectionCollection::getInputStream( const string &entry_name,
81 MatchPath matchpath ) {
82 if ( ! _valid )
83 throw InvalidStateException( "Attempt to get an input stream from an invalid CollectionCollection" ) ;
84
85 std::vector< FileCollection * >::const_iterator it ;
87
88 getEntry( entry_name, cep, it, matchpath ) ;
89
90 if ( cep == 0 )
91 return 0 ;
92 else
93 return (*it)->getInputStream( entry_name ) ;
94
95}
96
97
99 if ( ! _valid )
100 throw InvalidStateException( "Attempt to get the size of an invalid CollectionCollection" ) ;
101 int sz = 0 ;
102 std::vector< FileCollection * >::const_iterator it ;
103 for ( it = _collections.begin() ; it != _collections.end() ; it++ )
104 sz += (*it)->size() ;
105 return sz ;
106}
107
109 return new CollectionCollection( *this ) ;
110}
111
112CollectionCollection::~CollectionCollection() {
113 std::vector< FileCollection * >::iterator it ;
114 for ( it = _collections.begin() ; it != _collections.end() ; ++it )
115 delete *it ;
116}
117
118
119//
120// Protected member functions
121//
122
123void CollectionCollection::getEntry( const string &name,
124 ConstEntryPointer &cep,
125 std::vector< FileCollection * >::const_iterator &it,
126 MatchPath matchpath ) const {
127
128 // Returns the first matching entry.
129 cep = 0 ;
130 for ( it = _collections.begin() ; it != _collections.end() ; it++ ) {
131 cep = (*it)->getEntry( name, matchpath ) ;
132 if ( cep )
133 break ;
134 }
135}
136
137
138
139} // namespace
140
145/*
146 Zipios++ - a small C++ library that provides easy access to .zip files.
147 Copyright (C) 2000 Thomas Søndergaard
148
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.
153
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.
158
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
162*/
virtual ConstEntries entries() const
Returns a vector of const pointers to the entries in the FileCollection.
Definition collcoll.cpp:46
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 collcoll.cpp:58
bool addCollection(const FileCollection &collection)
Adds a collection.
Definition collcoll.cpp:21
virtual FileCollection * clone() const
Create a heap allocated clone of the object this method is called for.
Definition collcoll.cpp:108
virtual istream * getInputStream(const ConstEntryPointer &entry)
Returns a pointer to an opened istream for the specified FileEntry.
Definition collcoll.cpp:72
CollectionCollection()
Constructor.
Definition collcoll.cpp:16
virtual int size() const
Returns the number in entries in all collections kept by the CollectionCollection object.
Definition collcoll.cpp:98
virtual void close()
Closes the FileCollection.
Definition collcoll.cpp:41
FileCollection is an abstract baseclass that represents a collection of files.
Definition fcoll.h:21
bool isValid() const
The member function returns true if the collection is valid.
Definition fcoll.h:93
virtual FileCollection * clone() const =0
Create a heap allocated clone of the object this method is called for.
An object member function may throw this exception, if the operation it normally performs is inapprop...
SimpleSmartPointer is a simple reference counting smart pointer template.
Header file that defines CollectionCollection.
vector< EntryPointer > ConstEntries
ConstEntries is a vector of ConstEntryPointer's.
Definition fileentry.h:43
Header file containing miscellaneous small functions.