basicentry.cpp
Go to the documentation of this file.
#include "zipios++/zipios-config.h"
#include <cassert>
#include "zipios++/meta-iostreams.h"
#include <string>
#include "zipios_common.h"
#include "zipios++/basicentry.h"
#include "zipios++/zipios_defs.h"
#include "outputstringstream.h"
namespace zipios {
using std::ifstream ;
using std::ios ;
//
// Public definitions
//
BasicEntry::BasicEntry( const string &filename, const string &comment,
const FilePath &basepath )
: _filename ( filename ),
_comment ( comment ),
_basepath ( basepath )
{
string full_path = _basepath + _filename ;
ifstream is( full_path.c_str(), ios::in | ios::binary ) ;
if ( ! is ) {
_valid = false ;
} else {
is.seekg( 0, ios::end ) ;
_size = is.tellg() ;
is.close() ;
_valid = true ;
}
}
string BasicEntry::getComment() const {
return _comment ;
}
uint32 BasicEntry::getCompressedSize() const {
return getSize() ;
}
uint32 BasicEntry::getCrc() const {
return 0 ;
}
vector< unsigned char > BasicEntry::getExtra() const {
return vector< unsigned char > () ;
}
StorageMethod BasicEntry::getMethod() const {
return STORED ;
}
string BasicEntry::getName() const {
return _filename ;
}
string BasicEntry::getFileName() const {
if ( isDirectory() )
return string() ;
string::size_type pos ;
pos = _filename.find_last_of( separator ) ;
if ( pos != string::npos ) { // separator found!
// isDirectory() check means pos should not be last, so pos+1 is ok
return _filename.substr(pos + 1) ;
} else {
return _filename ;
}
}
uint32 BasicEntry::getSize() const {
return _size ;
}
int BasicEntry::getTime() const {
return 0 ; // FIXME later
}
bool BasicEntry::isValid() const {
return _valid ;
}
// virtual int hashCode() const {}
bool BasicEntry::isDirectory() const {
assert( _filename.size() != 0 ) ;
return _filename[ _filename.size() - 1 ] == separator ;
}
void BasicEntry::setComment( const string &comment ) {
_comment = comment ;
}
void BasicEntry::setCompressedSize( uint32 ) {
}
void BasicEntry::setCrc( uint32 ) {
}
void BasicEntry::setExtra( const vector< unsigned char > & ) {
}
void BasicEntry::setMethod( StorageMethod ) {
}
void BasicEntry::setName( const string &name ) {
_filename = name ;
}
void BasicEntry::setSize( uint32 size ) {
_size = size ;
}
void BasicEntry::setTime( int ) {
}
string BasicEntry::toString() const {
OutputStringStream sout ;
sout << _filename << " (" << _size << " bytes)" ;
return sout.str() ;
}
FileEntry *BasicEntry::clone() const {
return new BasicEntry( *this ) ;
}
BasicEntry::~BasicEntry() {
}
} // namespace
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
basicentry.h
Header file that defines BasicEntry.
zipios::BasicEntry::getComment
virtual string getComment() const
Returns the comment of the entry, if it has one.
Definition basicentry.cpp:42
zipios::BasicEntry::getMethod
virtual StorageMethod getMethod() const
Returns the method used to store the entry in the FileCollection.
Definition basicentry.cpp:58
zipios::BasicEntry::getSize
virtual uint32 getSize() const
Returns the (uncompressed) size of the entry data.
Definition basicentry.cpp:79
zipios::BasicEntry::toString
virtual string toString() const
Returns a human-readable string representation of the entry.
Definition basicentry.cpp:126
zipios::BasicEntry::setName
virtual void setName(const string &name)
Sets the name field for the entry.
Definition basicentry.cpp:114
zipios::BasicEntry::setCrc
virtual void setCrc(uint32 crc)
Sets the crc field.
Definition basicentry.cpp:105
zipios::BasicEntry::setMethod
virtual void setMethod(StorageMethod method)
Sets the storage method field for the entry.
Definition basicentry.cpp:111
zipios::BasicEntry::getName
virtual string getName() const
Returns the full filename of the entry, including a path if the entry is stored in a subfolder.
Definition basicentry.cpp:62
zipios::BasicEntry::getCrc
virtual uint32 getCrc() const
Returns the Crc for the entry, if it has one.
Definition basicentry.cpp:50
zipios::BasicEntry::isDirectory
virtual bool isDirectory() const
Returns true if the entry is a directory.
Definition basicentry.cpp:92
zipios::BasicEntry::clone
virtual FileEntry * clone() const
Create a heap allocated clone of the object this method is called for.
Definition basicentry.cpp:132
zipios::BasicEntry::isValid
virtual bool isValid() const
Any method or operator that initializes a FileEntry may set a flag, that specifies whether the read e...
Definition basicentry.cpp:87
zipios::BasicEntry::setTime
virtual void setTime(int time)
Sets the time field for the entry.
Definition basicentry.cpp:122
zipios::BasicEntry::BasicEntry
BasicEntry(const string &filename, const string &comment, const FilePath &basepath=FilePath())
Constructor.
Definition basicentry.cpp:24
zipios::BasicEntry::setSize
virtual void setSize(uint32 size)
Sets the size field for the entry.
Definition basicentry.cpp:118
zipios::BasicEntry::getFileName
virtual string getFileName() const
Returns the filename of the entry.
Definition basicentry.cpp:66
zipios::BasicEntry::getTime
virtual int getTime() const
Returns the date and time of FIXME: what?
Definition basicentry.cpp:83
zipios::BasicEntry::setCompressedSize
virtual void setCompressedSize(uint32 size)
Set the compressed size field of the entry.
Definition basicentry.cpp:102
zipios::BasicEntry::setExtra
virtual void setExtra(const vector< unsigned char > &extra)
Sets the extra field.
Definition basicentry.cpp:108
zipios::BasicEntry::getCompressedSize
virtual uint32 getCompressedSize() const
Returns the compressed size of the entry.
Definition basicentry.cpp:46
zipios::BasicEntry::getExtra
virtual vector< unsigned char > getExtra() const
Returns a vector of bytes of extra data that may be stored with the entry.
Definition basicentry.cpp:54
zipios::BasicEntry::setComment
virtual void setComment(const string &comment)
Sets the comment field for the FileEntry.
Definition basicentry.cpp:98
zipios::FileEntry
A FileEntry represents an entry in a FileCollection.
Definition fileentry.h:52
zipios::FilePath
FilePath represents a path to a file or directory name.
Definition filepath.h:18
zipios::OutputStringStream
OutputStringStream is typedefed to ostringstream if sstream is part of the standard library (unless Z...
Definition outputstringstream.h:24
zipios::OutputStringStream::str
string str()
Specialization of ostrstream::str() that takes care of null-terminating the string and unfreezing the...
Definition outputstringstream.h:29
zipios::StorageMethod
StorageMethod
The types used with FileEntry::setMethod and FileEntry::getMethod.
Definition fileentry.h:25
outputstringstream.h
Header file that defines OutputStringStream.
zipios_common.h
Header file containing miscellaneous small functions.
zipios_defs.h
Header file that defines some simple data types.