Zipios++
test_collcoll.cpp
Go to the documentation of this file.
1
2
3#include "zipios++/zipios-config.h"
4
5#include "zipios++/meta-iostreams.h"
6#include <memory>
7
8#include "zipios++/dircoll.h"
9#include "zipios++/zipfile.h"
10#include "zipios++/collcoll.h"
11
12using namespace zipios ;
13
14using std::cerr ;
15using std::cout ;
16using std::endl ;
17using std::auto_ptr ;
18
19int main() {
20 try {
21
22 cout << "Instantiating a DirectoryCollection" << endl ;
23 DirectoryCollection dircoll( "." ) ;
24
25 cout << "Instantiating a ZipFile" << endl ;
26 ZipFile zipfile( "test.zip" ) ;
27
28 cout << "Instantiating a CollectionCollection" << endl ;
29 CollectionCollection collcoll_orig ;
30
31 cout << "Adding the zip file and directory collection to the collection collection"
32 << endl ;
33 if ( ! collcoll_orig.addCollection( zipfile ) ) {
34 cerr << "Failed to add the zip file" << endl ;
35 return 1 ;
36 }
37 if ( ! collcoll_orig.addCollection( dircoll ) ) {
38 cerr << "Failed to add the zip file" << endl ;
39 return 1 ;
40 }
41
42 CollectionCollection collcoll( collcoll_orig ) ; // Test copy constructor
43 CColl::inst() = collcoll ; // test copy-assignment and Singleton instance inst().
44
45// if ( ! collcoll.addCollection( new ZipFile( "test.zip" ) ) ) {
46// cerr << "Failed to add the zip file" << endl ;
47// return 1 ;
48// }
49// if ( ! collcoll.addCollection( new DirectoryCollection( "." ) ) ) {
50// cerr << "Failed to add the zip file" << endl ;
51// return 1 ;
52// }
53
54// cout << "list length : " << collcoll.size() << endl ;
55
56// ConstEntries entries ;
57// entries = collcoll.entries() ;
58
59
60// ConstEntries::iterator it ;
61// for( it = entries.begin() ; it != entries.end() ; it++)
62// cout << *(*it) << endl ;
63
64 ConstEntryPointer ent = CColl::inst().getEntry( "file2.txt" ) ;
65 if ( ent != 0 ) {
66 auto_ptr< istream > is( CColl::inst().getInputStream( ent ) ) ;
67
68 cout << "Contents of entry, " << ent->getName() << " :" << endl ;
69
70 cout << is->rdbuf() ;
71 }
72
73 ent = CColl::inst().getEntry( "flistentry.cpp" ) ;
74 if ( ent != 0 ) {
75 auto_ptr< istream > is( CColl::inst().getInputStream( ent ) ) ;
76
77 cout << "Contents of entry, " << ent->getName() << " :" << endl ;
78
79 cout << is->rdbuf() ;
80 }
81 cout << "end of main()" << endl ;
82
83 return 0 ;
84 }
85 catch( exception &excp ) {
86 cerr << "Exception caught in main() :" << endl ;
87 cerr << excp.what() << endl ;
88 }
89 return -1;
90}
91
98/*
99 Zipios++ - a small C++ library that provides easy access to .zip files.
100 Copyright (C) 2000 Thomas Søndergaard
101
102 This library is free software; you can redistribute it and/or
103 modify it under the terms of the GNU Lesser General Public
104 License as published by the Free Software Foundation; either
105 version 2 of the License, or (at your option) any later version.
106
107 This library is distributed in the hope that it will be useful,
108 but WITHOUT ANY WARRANTY; without even the implied warranty of
109 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
110 Lesser General Public License for more details.
111
112 You should have received a copy of the GNU Lesser General Public
113 License along with this library; if not, write to the Free Software
114 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
115*/
CollectionCollection is a FileCollection that consists of an arbitrary number of FileCollections.
Definition collcoll.h:26
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
static CollectionCollection & inst()
This static method provides a singleton instance of a CollectionCollection.
Definition collcoll.h:111
DirectoryCollection is a FileCollection that obtains its entries from a directory.
Definition dircoll.h:19
SimpleSmartPointer is a simple reference counting smart pointer template.
ZipFile is a FileCollection, where the files are stored in a .zip file.
Definition zipfile.h:20
Header file that defines CollectionCollection.
Header file that defines DirectoryCollection.
Header file that defines ZipFile.