BALL 1.5.0
directory.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 2; -*-
2// vi: set ts=2:
3//
4// $Id: directory.h,v 1.29.16.1 2007/03/25 21:25:38 oliver Exp $
5//
6
7#ifndef BALL_SYSTEM_DIRECTORY_H
8#define BALL_SYSTEM_DIRECTORY_H
9
10#ifndef BALL_COMMON_H
11# include <BALL/common.h>
12#endif
13
14#ifndef BALL_CONCEPT_PROCESSOR_H
16#endif
17
18#ifndef BALL_DATATYPE_STRING_H
19# include <BALL/DATATYPE/string.h>
20#endif
21
22#ifndef BALL_SYSTEM_FILESYSTEM_H
24#endif
25
26#ifdef BALL_HAS_DIRENT_H
27# include <dirent.h>
28#endif
29#ifdef BALL_HAS_UNISTD_H
30# include <unistd.h>
31#endif
32#ifdef BALL_HAS_SYS_STAT_H
33# include <sys/stat.h>
34#endif
35#ifdef BALL_HAS_DIRECT_H
36# include <direct.h>
37#endif
38#include <cstdio>
39#ifdef BALL_COMPILER_MSVC
40#define WINDOWS_LEAN_AND_MEAN
41#include <windows.h>
42#define mode_t int
43#endif
44
45namespace BALL
46{
51 {
52#ifndef BALL_OS_WINDOWS
53# define INVALID_HANDLE_VALUE 0
54#endif
55
56 public:
57
61
66 static const Size MAX_PATH_LENGTH;
67
69
72
80
89 Directory(const String& directory_path, bool set_current = false);
90
96 Directory(const Directory& directory);
97
101
106 void clear();
107
110 void destroy();
111
113
116
124 bool set(const String& directory_path, bool set_current = false);
125
130 void set(const Directory& directory);
131
135 Directory& operator = (const Directory& directory);
136
141 void get(Directory& directory) const;
143
147
153 const String& getPath() const;
154
162 bool rename(String old_path, String new_path);
163
168 bool renameTo(String new_path);
169
174 bool setCurrent(String directory_path);
175
180
188 bool create(String path, const mode_t& mode = 0777);
189
196 bool remove(String old_path);
197
202 bool remove();
203
208 bool getFirstEntry(String& entry);
209
214 bool getNextEntry(String& entry);
215
220
225
230
237 bool find(const String& filename, String& filepath);
238
240
243
248 bool has(const String& item);
249
255 bool isValid() const;
256
260 bool isCurrent() const;
261
265 bool isEmpty();
266
270 bool operator == (const Directory& directory) const;
271
275 bool operator != (const Directory& directory) const;
276
279
281 static bool changeToUserHomeDir();
282
284
285 private:
286
287 //_wrapper function around getcwd to handle different naming conventions in different OS
288 String getcwd_();
289
290 //_wrapper function around chdir to handle different naming conventions in different OS
291 int chdir_(const String& new_dir);
292
293 //_switch to this dir
294 void synchronize_();
295
296 //_switch back to the working directory
297 bool desynchronize_(bool result = true);
298#ifdef BALL_COMPILER_MSVC
299 HANDLE dirent_;
300 HANDLE dir_;
301#else
302 DIR* dir_;
303 dirent* dirent_;
304#endif
305 String directory_path_;
306 String backup_path_;
307 };
308
309# ifndef BALL_NO_INLINE_FUNCTIONS
310# include <BALL/SYSTEM/directory.iC>
311# endif
312
313} // namespace BALL
314
315#endif // BALL_SYSTEM_DIRECTORY_H
Definition: constants.h:13
BALL_EXPORT bool operator==(const String &s1, const String &s2)
BALL_EXPORT bool operator!=(const String &s1, const String &s2)
static const Size MAX_PATH_LENGTH
Definition: directory.h:66
static bool changeToUserHomeDir()
Goto the home directory of the current user.
bool getNextEntry(String &entry)
Directory(const Directory &directory)
bool getFirstEntry(String &entry)
Size countDirectories()
bool setCurrent(String directory_path)
bool find(const String &filename, String &filepath)
Directory(const String &directory_path, bool set_current=false)
bool rename(String old_path, String new_path)
bool renameTo(String new_path)
bool remove(String old_path)
void set(const Directory &directory)
bool has(const String &item)
bool isValid() const
const String & getPath() const
bool create(String path, const mode_t &mode=0777)
void get(Directory &directory) const
bool set(const String &directory_path, bool set_current=false)
bool isCurrent() const
static String getUserHomeDir()
Get the home directory of the current user.
#define BALL_EXPORT
Definition: COMMON/global.h:50