Zipios++
fcoll.cpp
Go to the documentation of this file.
1 
2 #include "zipios++/zipios-config.h"
3 
4 #include <algorithm>
5 #include <string>
6 #include <vector>
7 
8 #include "zipios++/fcoll.h"
9 
10 namespace zipios {
11 
12 using std::find_if ;
13 
14 // FIXME: make InvalidStateException message customized for
15 // subclasses. maybe make an InvalidStateException factory ;-)
16 
18  if ( ! _valid )
19  throw InvalidStateException( "Attempt to get entries from an invalid FileCollection" ) ;
20 
21  // The constructor below is not in all vector impl. (not those
22  // without member templates)
23  // ConstEntries ( _entries.begin(), _entries.end() ) ;
24  // Instead of using that we copy the vector manually
25  ConstEntries cep_vec ;
26  cep_vec.reserve( _entries.size() ) ;
27  Entries::const_iterator cit ;
28  for ( cit = _entries.begin() ; cit != _entries.end() ; ++cit )
29  cep_vec.push_back( *cit ) ;
30 
31  return cep_vec ;
32 }
33 
35  MatchPath matchpath ) const {
36  if ( ! _valid )
37  throw InvalidStateException( "Attempt to get an entry from an invalid FileCollection" ) ;
38 
39  Entries::const_iterator iter ;
40  if ( matchpath == MATCH )
41  iter = find_if( _entries.begin(), _entries.end(), FileEntry::MatchName( name ) ) ;
42  else
43  iter = find_if( _entries.begin(), _entries.end(), FileEntry::MatchFileName( name ) ) ;
44  if ( iter == _entries.end() )
45  return 0 ;
46  else
47  return *iter ;
48 }
49 
50 string FileCollection::getName() const {
51  if ( ! _valid )
52  throw InvalidStateException( "Attempt to get the name of an invalid FileCollection" ) ;
53  return _filename ;
54 }
55 
56 
57 int FileCollection::size() const {
58  if ( ! _valid )
59  throw InvalidStateException( "Attempt to get size of an invalid FileCollection" ) ;
60  return _entries.size() ;
61 }
62 
64 }
65 
66 
67 } // namespace
68 
73 /*
74  Zipios++ - a small C++ library that provides easy access to .zip files.
75  Copyright (C) 2000 Thomas Søndergaard
76 
77  This library is free software; you can redistribute it and/or
78  modify it under the terms of the GNU Lesser General Public
79  License as published by the Free Software Foundation; either
80  version 2 of the License, or (at your option) any later version.
81 
82  This library is distributed in the hope that it will be useful,
83  but WITHOUT ANY WARRANTY; without even the implied warranty of
84  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
85  Lesser General Public License for more details.
86 
87  You should have received a copy of the GNU Lesser General Public
88  License along with this library; if not, write to the Free Software
89  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
90 */
virtual int size() const
Returns the number of entries in the FileCollection.
Definition: fcoll.cpp:57
Header file that defines FileCollection.
SimpleSmartPointer is a simple reference counting smart pointer template.
vector< EntryPointer > ConstEntries
ConstEntries is a vector of ConstEntryPointer&#39;s.
Definition: fileentry.h:43
Function object to be used with the STL find_if algorithm to find a FileEntry in a container...
Definition: fileentry.h:195
virtual ~FileCollection()
FileCollection destructor.
Definition: fcoll.cpp:63
virtual string getName() const
Returns the name of the FileCollection.
Definition: fcoll.cpp:50
virtual ConstEntryPointer getEntry(const string &name, MatchPath matchpath=MATCH) const
Definition: fcoll.cpp:34
An object member function may throw this exception, if the operation it normally performs is inapprop...
Function object to be used with the STL find_if algorithm to find a FileEntry in a container...
Definition: fileentry.h:181
virtual ConstEntries entries() const
Definition: fcoll.cpp:17