Zipios++
collcoll.h
Go to the documentation of this file.
1 #ifndef COLLCOLL_H
2 #define COLLCOLL_H
3 
4 #include "zipios++/zipios-config.h"
5 
6 #include <string>
7 #include <vector>
8 
9 #include "zipios++/fcoll.h"
10 
11 namespace zipios {
12 
13 using std::string ;
14 
27 public:
33  static inline CollectionCollection &inst() ;
34 
37  explicit CollectionCollection() ;
38 
40  inline CollectionCollection( const CollectionCollection &src ) ;
41 
43  inline const CollectionCollection &operator= ( const CollectionCollection &src ) ;
44 
51  bool addCollection( const FileCollection &collection ) ;
52 
62  bool addCollection( FileCollection *collection ) ;
63 
64  virtual void close() ;
65 
66  virtual ConstEntries entries() const ;
67 
68  virtual ConstEntryPointer getEntry( const string &name,
69  MatchPath matchpath = MATCH ) const ;
70 
71  virtual istream *getInputStream( const ConstEntryPointer &entry ) ;
72 
73  virtual istream *getInputStream( const string &entry_name,
74  MatchPath matchpath = MATCH ) ;
75 
78  virtual int size() const ;
79 
80  virtual FileCollection *clone() const ;
81 
82  virtual ~CollectionCollection() ;
83 
84 protected:
90  void getEntry( const string &name,
91  ConstEntryPointer &cep,
92  std::vector< FileCollection * >::const_iterator &it,
93  MatchPath matchpath = MATCH ) const ;
94 
95  vector< FileCollection * > _collections ;
96 private:
97  static CollectionCollection *_inst ;
98 };
99 
100 
104 typedef CollectionCollection CColl ;
105 
106 
107 //
108 // Inline (member) functions
109 //
110 
112  if( _inst != 0 )
113  return *_inst ;
114  else
115  return *( _inst = new CollectionCollection ) ;
116 }
117 
119  : FileCollection( src )
120 {
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() ) ;
125 }
126 
127 
128 const CollectionCollection &
130  this->FileCollection::operator=( src ) ;
131 // FileCollection::=( static_cast< FileCollection >( src ) ) ;
132 
133  if ( this != &src ) {
134  // Destroy current contents.
135  std::vector< FileCollection * >::const_iterator it ;
136  for ( it = _collections.begin() ; it != _collections.end() ; ++it )
137  delete *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() ) ;
143  }
144  return *this ;
145 }
146 
147 } // namespace
148 
149 
150 
151 #endif
152 
157 /*
158  Zipios++ - a small C++ library that provides easy access to .zip files.
159  Copyright (C) 2000 Thomas Søndergaard
160 
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.
165 
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.
170 
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
174 */