basicentry.cpp

Go to the documentation of this file.
00001 
00002 #include "zipios-config.h"
00003 
00004 #include <cassert>
00005 
00006 #include "meta-iostreams.h"
00007 #include <string>
00008 
00009 #include "zipios_common.h"
00010 #include "basicentry.h"
00011 #include "zipios_defs.h"
00012 
00013 #include "outputstringstream.h"
00014 
00015 namespace zipios {
00016 
00017 using std::ifstream ;
00018 using std::ios ;
00019 
00020 //
00021 // Public definitions
00022 //
00023 
00024 BasicEntry::BasicEntry( const string &filename, const string &comment,
00025                        const FilePath &basepath ) 
00026   : _filename ( filename ),
00027     _comment  ( comment  ),
00028     _basepath ( basepath )
00029 {
00030   string full_path = _basepath + _filename ;
00031   ifstream is( full_path.c_str(), ios::in | ios::binary ) ;
00032   if ( ! is ) {
00033     _valid = false ;
00034   } else {
00035     is.seekg( 0, ios::end ) ;
00036     _size = is.tellg() ;
00037     is.close() ;
00038     _valid = true ;
00039   }
00040 }
00041 
00042 string BasicEntry::getComment() const {
00043   return _comment ;
00044 }
00045 
00046 uint32 BasicEntry::getCompressedSize() const {
00047   return getSize() ;
00048 }
00049 
00050 uint32 BasicEntry::getCrc() const {
00051   return 0 ;
00052 }
00053 
00054 vector< unsigned char > BasicEntry::getExtra() const {
00055   return vector< unsigned char > () ;
00056 }
00057 
00058 StorageMethod BasicEntry::getMethod() const {
00059   return STORED ;
00060 }
00061 
00062 string BasicEntry::getName() const {
00063   return _filename ;
00064 }
00065 
00066 string BasicEntry::getFileName() const {
00067   if ( isDirectory() )
00068     return string() ;
00069   string::size_type pos ;
00070   pos = _filename.find_last_of( separator ) ;
00071   if ( pos != string::npos ) { // separator found!
00072     // isDirectory() check means pos should not be last, so pos+1 is ok 
00073     return _filename.substr(pos + 1) ;
00074   } else {
00075     return _filename ;
00076   }
00077 }
00078 
00079 uint32 BasicEntry::getSize() const {
00080   return _size ;
00081 }
00082 
00083 int BasicEntry::getTime() const {
00084   return 0 ; // FIXME later
00085 }
00086 
00087 bool BasicEntry::isValid() const {
00088   return _valid ;
00089 }
00090 
00091 //     virtual int hashCode() const {}
00092 bool BasicEntry::isDirectory() const {
00093   assert( _filename.size() != 0 ) ;
00094   return  _filename[ _filename.size() - 1 ] == separator ;
00095 }
00096 
00097 
00098 void BasicEntry::setComment( const string &comment ) {
00099   _comment = comment ;
00100 }
00101 
00102 void BasicEntry::setCompressedSize( uint32  ) {
00103 }
00104 
00105 void BasicEntry::setCrc( uint32  ) {
00106 }
00107 
00108 void BasicEntry::setExtra( const vector< unsigned char > & ) {
00109 }
00110 
00111 void BasicEntry::setMethod( StorageMethod ) {
00112 }
00113 
00114 void BasicEntry::setName( const string &name ) {
00115   _filename = name ;
00116 }
00117 
00118 void BasicEntry::setSize( uint32 size ) {
00119   _size = size ;
00120 }
00121 
00122 void BasicEntry::setTime( int  ) {
00123 }
00124 
00125 
00126 string BasicEntry::toString() const {
00127   OutputStringStream sout ;
00128   sout << _filename << " (" << _size << " bytes)" ;
00129   return sout.str() ;
00130 }
00131 
00132 FileEntry *BasicEntry::clone() const {
00133   return new BasicEntry( *this ) ;
00134 }
00135 
00136 BasicEntry::~BasicEntry() {
00137 }
00138 
00139 
00140 } // namespace
00141 
00146 /*
00147   Zipios++ - a small C++ library that provides easy access to .zip files.
00148   Copyright (C) 2000  Thomas Søndergaard
00149   
00150   This library is free software; you can redistribute it and/or
00151   modify it under the terms of the GNU Lesser General Public
00152   License as published by the Free Software Foundation; either
00153   version 2 of the License, or (at your option) any later version.
00154   
00155   This library is distributed in the hope that it will be useful,
00156   but WITHOUT ANY WARRANTY; without even the implied warranty of
00157   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00158   Lesser General Public License for more details.
00159   
00160   You should have received a copy of the GNU Lesser General Public
00161   License along with this library; if not, write to the Free Software
00162   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00163 */

Generated on Wed Nov 23 18:59:57 2011 for FreeCAD by  doxygen 1.6.1