aGrUM  0.14.2
utils_dir.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #ifndef GUM_DIR_UTILS_H
28 #define GUM_DIR_UTILS_H
29 
30 #include <cstdio>
31 #include <cstdlib>
32 #include <iostream>
33 #include <string>
34 #include <vector>
35 
36 #include <agrum/agrum.h>
37 
38 #ifdef HAVE_UNISTD_H
39 # include <unistd.h>
40 #else
41 # include <agrum/core/mvsc/unistd.h>
42 #endif
43 
44 #ifdef HAVE_DIRENT_H
45 # include <dirent.h>
46 #else
47 # include <agrum/core/mvsc/dirent.h>
48 #endif
49 
50 
51 namespace gum {
52 
59  class Directory {
60  public:
68  static bool isDir(const std::string& path);
69 
73  Directory();
74 
79  Directory(const std::string& directory);
80 
85  Directory(const Directory& dir);
86 
90  ~Directory();
91 
96  bool isValid() const;
97 
102  std::vector< std::string > entries() const;
103 
108  Directory parent() const;
109 
114  std::string path() const;
115 
120  std::string absolutePath() const;
121 
127  Directory& operator=(const Directory& d);
128 
129  private:
131  std::string m_dirName;
132 
134  mutable DIR* m_dirPtr;
135 
136  }; // END CLASS DIRECTORY
137 
138 } // namespace gum
139 
140 #endif // GUM_DIR_UTILS_H
Cross-platform directory utility.
Definition: utils_dir.h:59
std::string m_dirName
The directory path.
Definition: utils_dir.h:131
Directory()
Contructor.
Definition: utils_dir.cpp:37
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
DIR * m_dirPtr
A pointer towards the Directory stream.
Definition: utils_dir.h:134
bool isValid() const
Returns true if directory has been opened, false otherwise.
Definition: utils_dir.cpp:59
Directory & operator=(const Directory &d)
Copy operator.
Definition: utils_dir.cpp:110
~Directory()
Destructor.
Definition: utils_dir.cpp:52
std::string absolutePath() const
Returns directory absolute path.
Definition: utils_dir.cpp:88
std::vector< std::string > entries() const
Return directory content.
Definition: utils_dir.cpp:62
Directory parent() const
Returns directory parent.
Definition: utils_dir.cpp:78
static bool isDir(const std::string &path)
&brief Return true if directory is a valid directory, false otherwise.
Definition: utils_dir.cpp:32
std::string path() const
Returns directory path.
Definition: utils_dir.cpp:85