4 #include "zipios++/zipios-config.h"
13 /** FilePath represents a path to a file or directory name. FilePath has
14 member functions to check if the file path is a valid file system entity,
15 and to check what kind of file system entity it is, e.g. is it a file, a
16 directory, a pipe etc.
21 @param path A string representation of the path.
22 @param check_exists If true is specified the constructor will
23 check the existence and type of the path immediately, instead of
24 deferring that task until it is needed. */
25 FilePath( const string &path = "", bool check_exists = false ) ;
27 inline FilePath &operator= ( const string &rhs ) ;
29 inline operator string() const ;
31 inline std::string asString() const ;
33 /** Concatenates FilePath objects. A file separator is inserted
35 inline FilePath operator+ ( const FilePath &name ) const ;
37 /** Returns filename of the FilePath object by pruning the path
39 inline FilePath filename() const ;
42 /** @return true If the path is a valid file system entity. */
43 inline bool exists() const ;
45 /** @return true if the path is a regular file. */
46 inline bool isRegular() const ;
48 /** @return true if the path is a directory. */
49 inline bool isDirectory() const ;
51 /** @return true if the path is character special (a character
53 inline bool isCharSpecial() const ;
55 /** @return true if the path is block special (a block device
57 inline bool isBlockSpecial() const ;
59 /** @return true if the path is a socket. */
60 inline bool isSocket() const ;
62 /** @return true if the path is a Fifo (a pipe). */
63 inline bool isFifo() const ;
67 /** Prunes the trailing separator of a specified path. */
68 inline void pruneTrailingSeparator() ;
70 /** This function sets _checked to true, stats the path, to see if
71 it exists and to determine what type of file it is. All the query
72 functions check if _checked is true, and if it isn't they call
73 check(). This means stat'ing is deferred until it becomes
77 static const char _separator;
79 // FIXME: Should be bitfield
80 mutable bool _checked ;
81 mutable bool _exists ;
82 mutable bool _is_reg ;
83 mutable bool _is_dir ;
84 mutable bool _is_char ;
85 mutable bool _is_block ;
86 mutable bool _is_socket ;
87 mutable bool _is_fifo ;
93 // Inline member functions
96 FilePath &FilePath::operator= ( const string &rhs ) {
98 pruneTrailingSeparator() ;
102 void FilePath::pruneTrailingSeparator() {
103 if ( _path.size() > 0 )
104 if ( _path[ _path.size() -1 ] == _separator )
105 _path.erase( _path.size() - 1 ) ;
108 FilePath::operator string() const {
112 std::string FilePath::asString() const {
117 FilePath FilePath::operator+ ( const FilePath &name ) const {
118 if ( _path.size() > 0 )
119 return _path + _separator + name._path ;
125 FilePath FilePath::filename() const {
126 string::size_type pos ;
127 pos = _path.find_last_of( _separator ) ;
128 if ( pos != string::npos )
129 return _path.substr( pos + 1);
135 bool FilePath::exists() const {
142 bool FilePath::isRegular() const {
149 bool FilePath::isDirectory() const {
156 bool FilePath::isCharSpecial() const {
163 bool FilePath::isBlockSpecial() const {
170 bool FilePath::isSocket() const {
177 bool FilePath::isFifo() const {
188 Header file that defines FilePath.
192 Zipios++ - a small C++ library that provides easy access to .zip files.
193 Copyright (C) 2000 Thomas Søndergaard
195 This library is free software; you can redistribute it and/or
196 modify it under the terms of the GNU Lesser General Public
197 License as published by the Free Software Foundation; either
198 version 2 of the License, or (at your option) any later version.
200 This library is distributed in the hope that it will be useful,
201 but WITHOUT ANY WARRANTY; without even the implied warranty of
202 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
203 Lesser General Public License for more details.
205 You should have received a copy of the GNU Lesser General Public
206 License along with this library; if not, write to the Free Software
207 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA