collcoll.cpp
Go to the documentation of this file.00001
00002 #include "zipios-config.h"
00003
00004 #include "meta-iostreams.h"
00005
00006 #include "collcoll.h"
00007 #include "zipios_common.h"
00008
00009 namespace zipios {
00010
00011 using std::ifstream ;
00012
00013 CollectionCollection *CollectionCollection::_inst = 0 ;
00014
00015
00016 CollectionCollection::CollectionCollection() {
00017 _valid = true ;
00018 }
00019
00020
00021 bool CollectionCollection::addCollection( const FileCollection &collection ) {
00022 if ( ! _valid )
00023 throw InvalidStateException( "Attempt to add a FileCollection to an invalid CollectionCollection" ) ;
00024 if ( this == &collection || ! collection.isValid() )
00025 return false ;
00026 _collections.push_back( collection.clone() ) ;
00027 return true ;
00028
00029 }
00030
00031 bool CollectionCollection::addCollection( FileCollection *collection ) {
00032 if ( ! _valid )
00033 throw InvalidStateException( "Attempt to add a FileCollection to an invalid CollectionCollection" ) ;
00034 if ( collection == 0 || this == collection || ! collection->isValid() )
00035 return false ;
00036 _collections.push_back( collection ) ;
00037 return true ;
00038 }
00039
00040
00041 void CollectionCollection::close() {
00042 _valid = false ;
00043 }
00044
00045
00046 ConstEntries CollectionCollection::entries() const {
00047 if ( ! _valid )
00048 throw InvalidStateException( "Attempt to get entries from an invalid CollectionCollection" ) ;
00049
00050 ConstEntries all_entries ;
00051 std::vector< FileCollection * >::const_iterator it ;
00052 for ( it = _collections.begin() ; it != _collections.end() ; it++ )
00053 all_entries += (*it)->entries() ;
00054 return all_entries ;
00055 }
00056
00057
00058 ConstEntryPointer CollectionCollection::getEntry( const string &name,
00059 MatchPath matchpath ) const {
00060 if ( ! _valid )
00061 throw InvalidStateException( "Attempt to get an entry from an invalid CollectionCollection" ) ;
00062
00063 std::vector< FileCollection * >::const_iterator it ;
00064 ConstEntryPointer cep ;
00065
00066 getEntry( name, cep, it, matchpath ) ;
00067
00068 return cep ;
00069 }
00070
00071
00072 istream *CollectionCollection::getInputStream( const ConstEntryPointer &entry ) {
00073 if ( ! _valid )
00074 throw InvalidStateException( "Attempt to get an input stream from an invalid CollectionCollection" ) ;
00075
00076 return getInputStream( entry->getName() ) ;
00077 }
00078
00079
00080 istream *CollectionCollection::getInputStream( const string &entry_name,
00081 MatchPath matchpath ) {
00082 if ( ! _valid )
00083 throw InvalidStateException( "Attempt to get an input stream from an invalid CollectionCollection" ) ;
00084
00085 std::vector< FileCollection * >::const_iterator it ;
00086 ConstEntryPointer cep ;
00087
00088 getEntry( entry_name, cep, it, matchpath ) ;
00089
00090 if ( cep == 0 )
00091 return 0 ;
00092 else
00093 return (*it)->getInputStream( entry_name ) ;
00094
00095 }
00096
00097
00098 int CollectionCollection::size() const {
00099 if ( ! _valid )
00100 throw InvalidStateException( "Attempt to get the size of an invalid CollectionCollection" ) ;
00101 int sz = 0 ;
00102 std::vector< FileCollection * >::const_iterator it ;
00103 for ( it = _collections.begin() ; it != _collections.end() ; it++ )
00104 sz += (*it)->size() ;
00105 return sz ;
00106 }
00107
00108 FileCollection *CollectionCollection::clone() const {
00109 return new CollectionCollection( *this ) ;
00110 }
00111
00112 CollectionCollection::~CollectionCollection() {
00113 std::vector< FileCollection * >::iterator it ;
00114 for ( it = _collections.begin() ; it != _collections.end() ; ++it )
00115 delete *it ;
00116 }
00117
00118
00119
00120
00121
00122
00123 void CollectionCollection::getEntry( const string &name,
00124 ConstEntryPointer &cep,
00125 std::vector< FileCollection * >::const_iterator &it,
00126 MatchPath matchpath ) const {
00127
00128
00129 cep = 0 ;
00130 for ( it = _collections.begin() ; it != _collections.end() ; it++ ) {
00131 cep = (*it)->getEntry( name, matchpath ) ;
00132 if ( cep )
00133 break ;
00134 }
00135 }
00136
00137
00138
00139 }
00140
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162