Zipios++
|
00001 00002 00003 #include "zipios++/zipios-config.h" 00004 00005 #include "zipios++/meta-iostreams.h" 00006 #include <memory> 00007 00008 #include "zipios++/dircoll.h" 00009 #include "zipios++/zipfile.h" 00010 #include "zipios++/collcoll.h" 00011 00012 using namespace zipios ; 00013 00014 using std::cerr ; 00015 using std::cout ; 00016 using std::endl ; 00017 using std::auto_ptr ; 00018 00019 int main() { 00020 try { 00021 00022 cout << "Instantiating a DirectoryCollection" << endl ; 00023 DirectoryCollection dircoll( "." ) ; 00024 00025 cout << "Instantiating a ZipFile" << endl ; 00026 ZipFile zipfile( "test.zip" ) ; 00027 00028 cout << "Instantiating a CollectionCollection" << endl ; 00029 CollectionCollection collcoll_orig ; 00030 00031 cout << "Adding the zip file and directory collection to the collection collection" 00032 << endl ; 00033 if ( ! collcoll_orig.addCollection( zipfile ) ) { 00034 cerr << "Failed to add the zip file" << endl ; 00035 return 1 ; 00036 } 00037 if ( ! collcoll_orig.addCollection( dircoll ) ) { 00038 cerr << "Failed to add the zip file" << endl ; 00039 return 1 ; 00040 } 00041 00042 CollectionCollection collcoll( collcoll_orig ) ; // Test copy constructor 00043 CColl::inst() = collcoll ; // test copy-assignment and Singleton instance inst(). 00044 00045 // if ( ! collcoll.addCollection( new ZipFile( "test.zip" ) ) ) { 00046 // cerr << "Failed to add the zip file" << endl ; 00047 // return 1 ; 00048 // } 00049 // if ( ! collcoll.addCollection( new DirectoryCollection( "." ) ) ) { 00050 // cerr << "Failed to add the zip file" << endl ; 00051 // return 1 ; 00052 // } 00053 00054 // cout << "list length : " << collcoll.size() << endl ; 00055 00056 // ConstEntries entries ; 00057 // entries = collcoll.entries() ; 00058 00059 00060 // ConstEntries::iterator it ; 00061 // for( it = entries.begin() ; it != entries.end() ; it++) 00062 // cout << *(*it) << endl ; 00063 00064 ConstEntryPointer ent = CColl::inst().getEntry( "file2.txt" ) ; 00065 if ( ent != 0 ) { 00066 auto_ptr< istream > is( CColl::inst().getInputStream( ent ) ) ; 00067 00068 cout << "Contents of entry, " << ent->getName() << " :" << endl ; 00069 00070 cout << is->rdbuf() ; 00071 } 00072 00073 ent = CColl::inst().getEntry( "flistentry.cpp" ) ; 00074 if ( ent != 0 ) { 00075 auto_ptr< istream > is( CColl::inst().getInputStream( ent ) ) ; 00076 00077 cout << "Contents of entry, " << ent->getName() << " :" << endl ; 00078 00079 cout << is->rdbuf() ; 00080 } 00081 cout << "end of main()" << endl ; 00082 00083 return 0 ; 00084 } 00085 catch( exception &excp ) { 00086 cerr << "Exception caught in main() :" << endl ; 00087 cerr << excp.what() << endl ; 00088 } 00089 return -1; 00090 } 00091 00098 /* 00099 Zipios++ - a small C++ library that provides easy access to .zip files. 00100 Copyright (C) 2000 Thomas Søndergaard 00101 00102 This library is free software; you can redistribute it and/or 00103 modify it under the terms of the GNU Lesser General Public 00104 License as published by the Free Software Foundation; either 00105 version 2 of the License, or (at your option) any later version. 00106 00107 This library is distributed in the hope that it will be useful, 00108 but WITHOUT ANY WARRANTY; without even the implied warranty of 00109 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00110 Lesser General Public License for more details. 00111 00112 You should have received a copy of the GNU Lesser General Public 00113 License along with this library; if not, write to the Free Software 00114 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00115 */