4 #include "zipios++/zipios-config.h"
9 #include "zipios++/fcoll.h"
15 /** \anchor collcoll_anchor
16 CollectionCollection is a FileCollection that consists of an
17 arbitrary number of FileCollections. With a CollectionCollection
18 the user can use multiple FileCollections transparently, making it
19 easy for a program to keep some of its files in a zip archive and
20 others stored in ordinary files. CollectionCollection can be used
21 to create a simple virtual filesystem, where all collections are
22 mounted in /. If more than one collection contain a file with
23 the same path only the one in the first added collection will
26 class CollectionCollection : public FileCollection {
28 /** \anchor collcoll_inst_anchor
29 This static method provides a singleton instance of a CollectionCollection.
30 The instance is instantiated the first time the method is called.
31 @return A pointer to a singleton CollectionCollection instance.
33 static inline CollectionCollection &inst() ;
37 explicit CollectionCollection() ;
39 /** Copy constructor. */
40 inline CollectionCollection( const CollectionCollection &src ) ;
42 /** Copy assignment operator. */
43 inline const CollectionCollection &operator= ( const CollectionCollection &src ) ;
45 /** \anchor collcoll_addcoll_anchor
47 @param collection The collection to add.
48 @return true if the collection was added succesfully and
49 the added collection is valid.
51 bool addCollection( const FileCollection &collection ) ;
53 /** Adds the collection pointed to by collection. The CollectionCollection
54 will call delete on the pointer when it is destructed, so the caller
55 should make absolutely sure to only pass in a collection created with new
56 and be sure to leave it alone after adding it. If the collection is not
57 added false is returned and the caller remains responsible for the
58 collection pointed to by collection.
59 @param collection A pointer to the collection to add.
60 @return true if the collection was added succesfully and
61 the added collection is valid. */
62 bool addCollection( FileCollection *collection ) ;
64 virtual void close() ;
66 virtual ConstEntries entries() const ;
68 virtual ConstEntryPointer getEntry( const string &name,
69 MatchPath matchpath = MATCH ) const ;
71 virtual istream *getInputStream( const ConstEntryPointer &entry ) ;
73 virtual istream *getInputStream( const string &entry_name,
74 MatchPath matchpath = MATCH ) ;
76 /** Returns the number in entries in all collections kept by
77 the CollectionCollection object */
78 virtual int size() const ;
80 virtual FileCollection *clone() const ;
82 virtual ~CollectionCollection() ;
85 /** A protected getEntry member function, that not only
86 finds an entry that match the name, if such an entry exists
87 in the collection, it also returns, which collection it was found
90 void getEntry( const string &name,
91 ConstEntryPointer &cep,
92 std::vector< FileCollection * >::const_iterator &it,
93 MatchPath matchpath = MATCH ) const ;
95 vector< FileCollection * > _collections ;
97 static CollectionCollection *_inst ;
101 /** Shortcut name for a CollectionCollection. If the static method
102 inst is used, it is often used a lot, so it's handy with a short name for
103 CollectionCollection */
104 typedef CollectionCollection CColl ;
108 // Inline (member) functions
111 CollectionCollection &CollectionCollection::inst() {
115 return *( _inst = new CollectionCollection ) ;
118 CollectionCollection::CollectionCollection( const CollectionCollection &src )
119 : FileCollection( src )
121 _collections.reserve( src._collections.size() ) ;
122 std::vector< FileCollection * >::const_iterator it ;
123 for ( it = src._collections.begin() ; it != src._collections.end() ; ++it )
124 _collections.push_back( (*it)->clone() ) ;
128 const CollectionCollection &
129 CollectionCollection::operator= ( const CollectionCollection &src ) {
130 this->FileCollection::operator=( src ) ;
131 // FileCollection::=( static_cast< FileCollection >( src ) ) ;
133 if ( this != &src ) {
134 // Destroy current contents.
135 std::vector< FileCollection * >::const_iterator it ;
136 for ( it = _collections.begin() ; it != _collections.end() ; ++it )
138 // Then copy src's content.
139 _collections.clear() ;
140 _collections.reserve( src._collections.size() ) ;
141 for ( it = src._collections.begin() ; it != src._collections.end() ; ++it )
142 _collections.push_back( (*it)->clone() ) ;
154 Header file that defines CollectionCollection.
158 Zipios++ - a small C++ library that provides easy access to .zip files.
159 Copyright (C) 2000 Thomas Søndergaard
161 This library is free software; you can redistribute it and/or
162 modify it under the terms of the GNU Lesser General Public
163 License as published by the Free Software Foundation; either
164 version 2 of the License, or (at your option) any later version.
166 This library is distributed in the hope that it will be useful,
167 but WITHOUT ANY WARRANTY; without even the implied warranty of
168 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
169 Lesser General Public License for more details.
171 You should have received a copy of the GNU Lesser General Public
172 License along with this library; if not, write to the Free Software
173 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA