FileSystem.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
3 
4  This file is part of the TerraLib - a Framework for building GIS enabled
5  applications.
6 
7  TerraLib is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation, either version 3 of the License,
10  or (at your option) any later version.
11 
12  TerraLib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with TerraLib. See COPYING. If not, write to
19  TerraLib Team at <terralib-team@terralib.org>.
20  */
21 
22 /*!
23  \file terralib/core/filesystem/FileSystem.h
24 
25  \brief A class for handling system files and paths.
26 
27  \author Matheus Cavassan Zaglia
28 */
29 
30 #ifndef __TERRALIB_CORE_FILESYSTEM_FILESYSTEM_H__
31 #define __TERRALIB_CORE_FILESYSTEM_FILESYSTEM_H__
32 
33 // TerraLib
34 #include "../Config.h"
35 
36 // STL
37 #include <string>
38 #include <vector>
39 
40 namespace te
41 {
42  namespace core
43  {
44  /*!
45  \class FileSystem
46 
47  \brief A class for handling system files and paths using UTF-8 strings.
48  */
50  {
51  public:
52 
53  /*!
54  \brief Retrives the current working directory path in UTF-8.
55 
56  \return String in UTF-8 for the current working directory path.
57  */
58  static std::string currentPath();
59 
60  /*!
61  \brief Composes an absolute path for the given path in UTF-8.
62 
63  \param path Path in UTF-8.
64 
65  \return String in UTF-8 for the composed path.
66  */
67  static std::string systemCompletePath(const std::string& path);
68 
69  /*!
70  \brief Retrives the temp directory in UTF-8.
71 
72  \return String in UTF-8 for temp directory.
73  */
74  static std::string tempDirectoryPath();
75 
76  /*!
77  \brief Retrives an unique path generated by a given format.
78 
79  \param format The format used to create a unique path.
80  e.g.: "%%%%-%%%%-%%%%-%%%%"
81 
82  \return String in UTF-8 for the generated unique path.
83  */
84  static std::string uniquePath(
85  const std::string& format = "%%%%-%%%%-%%%%-%%%%");
86 
87  /*!
88  \brief Retrives the absolute path for the given path in UTF-8.
89 
90  \param path Path in UTF-8.
91 
92  \return String in UTF-8 for the absolute path.
93  */
94  static std::string absolutePath(const std::string& path);
95 
96  /*!
97  \brief Retrives the extension of a given file path in UTF-8.
98 
99  \param path File path in UTF-8.
100 
101  \return String in UTF-8 for the extension.
102  */
103  static std::string extension(const std::string& path);
104 
105  /*!
106  \brief Checks if a given path in UTF-8 is a directory.
107 
108  \param path Path in UTF-8.
109 
110  \return true if is a directory, otherwise false.
111  */
112  static bool isDirectory(const std::string& path);
113 
114  /*!
115  \brief Checks if a given path in UTF-8 is an empty directory.
116 
117  \param path Path in UTF-8.
118 
119  \return true if is a empty directory, otherwise false.
120  */
121  static bool isEmpty(const std::string& path);
122  /*!
123  \brief Checks if a given path in UTF-8 is a regular file.
124 
125  \param path File path in UTF-8.
126 
127  \return true if is a regular file, otherwise false.
128  */
129  static bool isRegularFile(const std::string& path);
130 
131  /*
132  \brief Returns the full directory to the currently running executable,
133  or an empty string in case of failure.
134 
135  \return String in UTF-8 of the running executable
136  */
137  static std::string executableDirectory();
138 
139  /*!
140  \brief Checks if a given path in UTF-8 exists.
141 
142  \param path Path in UTF-8.
143 
144  \return true if exists, otherwise false.
145  */
146  static bool exists(const std::string& path);
147 
148  /*!
149  \brief Creates a directory from a given path in UTF-8.
150 
151  \param path Path in UTF-8.
152 
153  \return true if a new directory was created, otherwise false.
154  */
155  static bool createDirectory(const std::string& path);
156 
157  /*!
158  \brief Creates a directory for any element of path that does not
159  exist.
160  \param path Path in UTF-8.
161 
162  \return true if a new directory was created, otherwise false.
163  */
164  static bool createDirectories(const std::string& path);
165 
166  /*!
167  \brief Copies a file
168 
169  \param from Path in UTF-8 for the file to be copied.
170  \param to Path in UTF-8 for the copy output.
171 
172  */
173  static void copyFile(const std::string& from, const std::string& to);
174 
175  /*!
176  \brief Removes a file or directory from a given path in UTF-8.
177 
178  \note This function will not remove if the directory is not empty.
179 
180  \param path Path in UTF-8.
181 
182  \return false if path did not exist in the first place, otherwise
183  true.
184  */
185  static bool remove(const std::string& path);
186 
187  /*!
188  \brief Renames a file or directory from a given path in UTF-8.
189 
190  \param old_p Old name in UTF-8.
191  \param new_p New name in UTF-8.
192  */
193  static void rename(const std::string& old_p, const std::string& new_p);
194 
195  /*!
196  \brief Lists a directory from a given path in UTF-8.
197 
198  \param path Path in UTF-8.
199 
200  \return Vector of strings in UTF-8 for directory content.
201  */
202  static std::vector<std::string> listDirectory(const std::string& path);
203 
204  private:
205 // Not instantiable
206  FileSystem();
207  ~FileSystem();
208 // No copy allowed
209  FileSystem(FileSystem const&);
210  FileSystem& operator=(FileSystem const&);
211  };
212  } // end namespace core
213 } // end namespace te
214 
215 #endif //__TERRALIB_CORE_FILESYSTEM_FILESYSTEM_H__
A class for handling system files and paths using UTF-8 strings.
Definition: FileSystem.h:49
#define TECOREEXPORT
Definition: Config.h:40
URI C++ Library.