filepath.h
Go to the documentation of this file.
#ifndef FILEPATH_H
#define FILEPATH_H
#include "zipios++/zipios-config.h"
#include <stdexcept>
#include <string>
namespace zipios {
using namespace std ;
class FilePath {
public:
FilePath( const string &path = "", bool check_exists = false ) ;
inline FilePath &operator= ( const string &rhs ) ;
inline operator string() const ;
inline FilePath operator+ ( const FilePath &name ) const ;
inline FilePath filename() const ;
inline bool exists() const ;
inline bool isRegular() const ;
inline bool isDirectory() const ;
inline bool isCharSpecial() const ;
inline bool isBlockSpecial() const ;
inline bool isSocket() const ;
inline bool isFifo() const ;
protected:
inline void pruneTrailingSeparator() ;
void check() const ;
static const char _separator;
// FIXME: Should be bitfield
mutable bool _checked ;
mutable bool _exists ;
mutable bool _is_reg ;
mutable bool _is_dir ;
mutable bool _is_char ;
mutable bool _is_block ;
mutable bool _is_socket ;
mutable bool _is_fifo ;
string _path ;
};
//
// Inline member functions
//
FilePath &FilePath::operator= ( const string &rhs ) {
_path = rhs ;
pruneTrailingSeparator() ;
return *this ;
}
void FilePath::pruneTrailingSeparator() {
if ( _path.size() > 0 )
if ( _path[ _path.size() -1 ] == _separator )
_path.erase( _path.size() - 1 ) ;
}
FilePath::operator string() const {
return _path ;
}
FilePath FilePath::operator+ ( const FilePath &name ) const {
if ( _path.size() > 0 )
return _path + _separator + name._path ;
else
return name._path ;
}
FilePath FilePath::filename() const {
string::size_type pos ;
pos = _path.find_last_of( _separator ) ;
if ( pos != string::npos )
return _path.substr( pos + 1);
else
return _path ;
}
bool FilePath::exists() const {
if ( ! _checked )
check() ;
return _exists ;
}
bool FilePath::isRegular() const {
if ( ! _checked )
check() ;
return _is_reg ;
}
bool FilePath::isDirectory() const {
if ( ! _checked )
check() ;
return _is_dir ;
}
bool FilePath::isCharSpecial() const {
if ( ! _checked )
check() ;
return _is_char ;
}
bool FilePath::isBlockSpecial() const {
if ( ! _checked )
check() ;
return _is_block ;
}
bool FilePath::isSocket() const {
if ( ! _checked )
check() ;
return _is_socket ;
}
bool FilePath::isFifo() const {
if ( ! _checked )
check() ;
return _is_fifo ;
}
} // namespace
#endif
/*
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
*/
zipios::FilePath
FilePath represents a path to a file or directory name.
Definition filepath.h:18
zipios::FilePath::isFifo
bool isFifo() const
Definition filepath.h:171
zipios::FilePath::check
void check() const
This function sets _checked to true, stats the path, to see if it exists and to determine what type o...
Definition filepath.cpp:27
zipios::FilePath::FilePath
FilePath(const string &path="", bool check_exists=false)
Constructor.
Definition filepath.cpp:18
zipios::FilePath::isCharSpecial
bool isCharSpecial() const
Definition filepath.h:150
zipios::FilePath::isBlockSpecial
bool isBlockSpecial() const
Definition filepath.h:157
zipios::FilePath::pruneTrailingSeparator
void pruneTrailingSeparator()
Prunes the trailing separator of a specified path.
Definition filepath.h:100
zipios::FilePath::isDirectory
bool isDirectory() const
Definition filepath.h:143
zipios::FilePath::exists
bool exists() const
Definition filepath.h:129
zipios::FilePath::filename
FilePath filename() const
Returns filename of the FilePath object by pruning the path off.
Definition filepath.h:119
zipios::FilePath::operator+
FilePath operator+(const FilePath &name) const
Concatenates FilePath objects.
Definition filepath.h:111
zipios::FilePath::isRegular
bool isRegular() const
Definition filepath.h:136
zipios::FilePath::isSocket
bool isSocket() const
Definition filepath.h:164