- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gdirectory.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
20
21 #ifndef G_DIRECTORY_H
22 #define G_DIRECTORY_H
23
24 #include "gdef.h"
25 #include "gpath.h"
26 #include "gexception.h"
27 #include <string>
28 #include <vector>
29 #include <sys/types.h>
30
32 namespace G
33 {
34 class DirectoryIteratorImp ;
35 class Directory ;
36 class DirectoryIterator ;
37 class DirectoryList ;
38 }
39
46 class G::Directory
47 {
48 public:
49 Directory() ;
51
52 explicit Directory( const char * path ) ;
54
55 explicit Directory( const Path & path ) ;
57
58 explicit Directory( const std::string & path ) ;
60
61 ~Directory() ;
63
64 bool valid( bool for_creating_files = false ) const ;
73
74 bool writeable( std::string probe_filename = tmp() ) const ;
78
79 Path path() const ;
81
82 Directory( const Directory & other ) ;
84
85 Directory & operator=( const Directory & ) ;
87
88 static Directory root() ;
91
92 static std::string tmp() ;
97
98 private:
99 Path m_path ;
100 } ;
101
108 class G::DirectoryIterator
109 {
110 public:
111 DirectoryIterator( const Directory & dir , const std::string & wc ) ;
119
120 explicit DirectoryIterator( const Directory & dir ) ;
123
124 ~DirectoryIterator() ;
126
127 bool error() const ;
129
130 bool more() ;
132
133 bool isDir() const ;
135
136 std::string modificationTimeString() const ;
139
140 std::string sizeString() const ;
143
144 Path filePath() const ;
146
147 Path fileName() const ;
149
150 private:
151 DirectoryIterator( const DirectoryIterator & ) ; // not implemented
152 void operator=( const DirectoryIterator & ) ; // not implemented
153
154 private:
155 DirectoryIteratorImp * m_imp ;
156 } ;
157
164 class G::DirectoryList
165 {
166 public:
167 DirectoryList() ;
170
171 void readAll( const Path & dir ) ;
175
176 void readType( const Path & dir , const std::string & suffix , unsigned int limit = 0U ) ;
180
181 bool more() ;
183
184 bool isDir() const ;
186
187 G::Path filePath() const ;
189
190 G::Path fileName() const ;
192
193 private:
194 DirectoryList( const DirectoryList & ) ;
195 void operator=( const DirectoryList & ) ;
196
197 private:
198 bool m_first ;
199 unsigned int m_index ;
200 std::vector<int> m_is_dir ;
201 std::vector<G::Path> m_path ;
202 std::vector<G::Path> m_name ;
203 } ;
204
205 #endif
G::DirectoryIterator::sizeString
std::string sizeString() const
Returns the file size as a decimal string.
Definition: gdirectory_unix_glob.cpp:113
G::DirectoryList::more
bool more()
Returns true if more and advances by one.
Definition: gdirectory.cpp:110
G::DirectoryIterator::filePath
Path filePath() const
Returns the path of the current item.
Definition: gdirectory_unix_glob.cpp:93
G::DirectoryList::filePath
G::Path filePath() const
Returns the current path.
Definition: gdirectory.cpp:131
G::DirectoryList::readAll
void readAll(const Path &dir)
An initialiser that is to be used after default construction.
Definition: gdirectory.cpp:82
G::DirectoryIterator::DirectoryIterator
DirectoryIterator(const Directory &dir, const std::string &wc)
Constructor taking a directory reference and a wildcard specification.
Definition: gdirectory_unix_glob.cpp:74
G::Directory::path
Path path() const
Returns the directory's path.
Definition: gdirectory.cpp:69
G::Directory::valid
bool valid(bool for_creating_files=false) const
Returns true if the object represents a valid directory.
Definition: gdirectory_unix.cpp:39
G::Directory::Directory
Directory()
Default constructor for the current directory.
Definition: gdirectory.cpp:27
G::Directory::writeable
bool writeable(std::string probe_filename=tmp()) const
Tries to create and then delete an empty test file in the directory.
Definition: gdirectory_unix.cpp:76
G::DirectoryIterator::~DirectoryIterator
~DirectoryIterator()
Destructor.
Definition: gdirectory_unix_glob.cpp:118
G::DirectoryList::readType
void readType(const Path &dir, const std::string &suffix, unsigned int limit=0U)
An initialiser that is to be used after default construction.
Definition: gdirectory.cpp:87
G::Directory
An encapsulation of a file system directory which allows for iterating through the set of contained f...
Definition: gdirectory.h:46
G::DirectoryIterator::fileName
Path fileName() const
Returns the name of the current item.
Definition: gdirectory_unix_glob.cpp:98
G
Low-level classes.
G::DirectoryList
A Directory iterator that does all file i/o in one go.
Definition: gdirectory.h:164
G::Directory::tmp
static std::string tmp()
A convenience function for constructing a filename for writeable().
Definition: gdirectory_unix.cpp:69
G::DirectoryIterator::more
bool more()
Returns true if more and advances by one.
Definition: gdirectory_unix_glob.cpp:88
gexception.h
G::DirectoryIterator::isDir
bool isDir() const
Returns true if the current item is a directory.
Definition: gdirectory_unix_glob.cpp:103
gpath.h
G::DirectoryIterator
A Directory iterator.
Definition: gdirectory.h:108
G::DirectoryIterator::modificationTimeString
std::string modificationTimeString() const
Returns the last-modified time for the file in an undefined format – used for comparison.
Definition: gdirectory_unix_glob.cpp:108
G::Directory::~Directory
~Directory()
Destructor.
Definition: gdirectory.cpp:54
G::DirectoryList::fileName
G::Path fileName() const
Returns the current filename.
Definition: gdirectory.cpp:136
G::DirectoryIteratorImp
A pimple-pattern implementation class for DirectoryIterator.
Definition: gdirectory_unix_glob.cpp:42
G::Directory::root
static Directory root()
Returns a root directory object.
Definition: gdirectory.cpp:32
G::DirectoryList::isDir
bool isDir() const
Returns true if the current item is a directory.
Definition: gdirectory.cpp:126
G::Directory::operator=
Directory & operator=(const Directory &)
Assignment operator.
Definition: gdirectory.cpp:63
G::DirectoryIterator::error
bool error() const
Returns true on error. The caller should stop the iteration.
Definition: gdirectory_unix_glob.cpp:83
G::Path
A Path object represents a file system path.
Definition: gpath.h:44
G::DirectoryList::DirectoryList
DirectoryList()
Default constructor for an empty list.
Definition: gdirectory.cpp:76