Gazebo Common

API Reference

7.4.0
Filesystem.hh
Go to the documentation of this file.
1/*
2 * Copyright 2017 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18#ifndef GZ_COMMON_FILESYSTEM_HH_
19#define GZ_COMMON_FILESYSTEM_HH_
20
21#include <string>
22
23#include <gz/common/Export.hh>
24
25#include <gz/utils/ImplPtr.hh>
26
27namespace gz
28{
29 namespace common
30 {
44
48 bool GZ_COMMON_VISIBLE exists(const std::string &_path);
49
53 bool GZ_COMMON_VISIBLE isDirectory(const std::string &_path);
54
58 bool GZ_COMMON_VISIBLE isFile(const std::string &_path);
59
63 bool GZ_COMMON_VISIBLE isRelativePath(const std::string &_path);
64
69 bool GZ_COMMON_VISIBLE createDirectory(const std::string &_path);
70
74 bool GZ_COMMON_VISIBLE createDirectories(const std::string &_path);
75
80 std::string GZ_COMMON_VISIBLE const separator(
81 std::string const &_s);
82
96 void GZ_COMMON_VISIBLE changeFromUnixPath(std::string &_path);
97
104 std::string GZ_COMMON_VISIBLE copyFromUnixPath(
105 const std::string &_path);
106
113 void GZ_COMMON_VISIBLE changeToUnixPath(std::string &_path);
114
121 std::string GZ_COMMON_VISIBLE copyToUnixPath(
122 const std::string &_path);
123
128 std::string GZ_COMMON_VISIBLE absPath(const std::string &_path);
129
136 std::string GZ_COMMON_VISIBLE joinPaths(const std::string &_path1,
137 const std::string &_path2);
138
140 inline std::string joinPaths(const std::string &_path)
141 {
142 return _path;
143 }
144
145 // The below is C++ variadic template magic to allow a joinPaths
146 // method that takes 1-n number of arguments to append together.
147
154 template<typename... Args>
155 inline std::string joinPaths(const std::string &_path1,
156 const std::string &_path2,
157 Args const &..._args)
158 {
159 return joinPaths(joinPaths(_path1, _path2),
160 joinPaths(_args...));
161 }
162
165 std::string GZ_COMMON_VISIBLE cwd();
166
170 bool GZ_COMMON_VISIBLE chdir(const std::string &_dir);
171
175 std::string GZ_COMMON_VISIBLE basename(
176 const std::string &_path);
177
182 std::string GZ_COMMON_VISIBLE parentPath(
183 const std::string &_path);
184
190 bool GZ_COMMON_VISIBLE copyFile(
191 const std::string &_existingFilename,
192 const std::string &_newFilename,
193 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
194
200 bool GZ_COMMON_VISIBLE copyDirectory(
201 const std::string &_existingDirname,
202 const std::string &_newDirname,
203 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
204
210 bool GZ_COMMON_VISIBLE moveFile(
211 const std::string &_existingFilename,
212 const std::string &_newFilename,
213 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
214
220 bool GZ_COMMON_VISIBLE removeDirectory(
221 const std::string &_path,
222 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
223
228 bool GZ_COMMON_VISIBLE removeFile(
229 const std::string &_existingFilename,
230 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
231
236 bool GZ_COMMON_VISIBLE removeDirectoryOrFile(
237 const std::string &_path,
238 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
239
244 bool GZ_COMMON_VISIBLE removeAll(
245 const std::string &_path,
246 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
247
255 std::string GZ_COMMON_VISIBLE uniqueFilePath(
256 const std::string &_pathAndName, const std::string &_extension);
257
262 const std::string &_dir);
263
266 class GZ_COMMON_VISIBLE DirIter
267 {
269 public: DirIter();
270
273 public: explicit DirIter(const std::string &_in);
274
278 public: std::string operator*() const;
279
282 public: const DirIter &operator++();
283
288 public: bool operator!=(const DirIter &_other) const;
289
291 GZ_UTILS_IMPL_PTR(dataPtr)
292 };
293 }
294}
295
296#endif