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
15 # include <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
23 # include <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 
45 namespace 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 
179  bool setCurrent();
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
BALL_EXPORT
#define BALL_EXPORT
Definition: COMMON/global.h:50
BALL::Directory::isCurrent
bool isCurrent() const
BALL::Directory::Directory
Directory(const String &directory_path, bool set_current=false)
BALL::Directory::Directory
Directory(const Directory &directory)
BALL::operator!=
BALL_EXPORT bool operator!=(const String &s1, const String &s2)
BALL::Directory::setCurrent
bool setCurrent(String directory_path)
BALL::Directory::getFirstEntry
bool getFirstEntry(String &entry)
BALL::String
Definition: string.h:57
BALL::Directory::renameTo
bool renameTo(String new_path)
BALL::Directory::getUserHomeDir
static String getUserHomeDir()
Get the home directory of the current user.
BALL::Directory::remove
bool remove(String old_path)
BALL
Definition: constants.h:13
BALL::Directory::getNextEntry
bool getNextEntry(String &entry)
BALL::Directory::set
void set(const Directory &directory)
BALL::Directory::setCurrent
bool setCurrent()
BALL::Directory::remove
bool remove()
BALL_SIZE_TYPE
BALL::Directory::set
bool set(const String &directory_path, bool set_current=false)
BALL::Directory::Directory
Directory()
BALL::Directory::countDirectories
Size countDirectories()
string.h
BALL::Directory::countFiles
Size countFiles()
processor.h
BALL::Directory::getPath
const String & getPath() const
BALL::Directory::changeToUserHomeDir
static bool changeToUserHomeDir()
Goto the home directory of the current user.
BALL::Directory::find
bool find(const String &filename, String &filepath)
BALL::operator==
BALL_EXPORT bool operator==(const String &s1, const String &s2)
BALL::Directory::isValid
bool isValid() const
common.h
BALL::Directory::create
bool create(String path, const mode_t &mode=0777)
BALL::Directory::has
bool has(const String &item)
BALL::Directory::clear
void clear()
BALL::Directory::get
void get(Directory &directory) const
BALL::Directory
Definition: directory.h:51
BALL::Directory::destroy
void destroy()
BALL::Directory::rename
bool rename(String old_path, String new_path)
BALL::Directory::MAX_PATH_LENGTH
static const Size MAX_PATH_LENGTH
Definition: directory.h:66
fileSystem.h
BALL::Directory::~Directory
~Directory()
BALL::Directory::countItems
Size countItems()
BALL::Directory::isEmpty
bool isEmpty()