Gazebo Common

API Reference

6.0.1
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
152 template<typename... Args>
153 inline std::string joinPaths(const std::string &_path1,
154 const std::string &_path2,
155 Args const &..._args)
156 {
157 return joinPaths(joinPaths(_path1, _path2),
158 joinPaths(_args...));
159 }
160
163 std::string GZ_COMMON_VISIBLE cwd();
164
168 bool GZ_COMMON_VISIBLE chdir(const std::string &_dir);
169
173 std::string GZ_COMMON_VISIBLE basename(
174 const std::string &_path);
175
180 std::string GZ_COMMON_VISIBLE parentPath(
181 const std::string &_path);
182
188 bool GZ_COMMON_VISIBLE copyFile(
189 const std::string &_existingFilename,
190 const std::string &_newFilename,
191 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
192
197 bool GZ_COMMON_VISIBLE copyDirectory(
198 const std::string &_existingDirname,
199 const std::string &_newDirname,
200 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
201
207 bool GZ_COMMON_VISIBLE moveFile(
208 const std::string &_existingFilename,
209 const std::string &_newFilename,
210 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
211
217 bool GZ_COMMON_VISIBLE removeDirectory(
218 const std::string &_path,
219 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
220
225 bool GZ_COMMON_VISIBLE removeFile(
226 const std::string &_existingFilename,
227 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
228
233 bool GZ_COMMON_VISIBLE removeDirectoryOrFile(
234 const std::string &_path,
235 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
236
241 bool GZ_COMMON_VISIBLE removeAll(
242 const std::string &_path,
243 const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
244
252 std::string GZ_COMMON_VISIBLE uniqueFilePath(
253 const std::string &_pathAndName, const std::string &_extension);
254
259 const std::string &_dir);
260
263 class GZ_COMMON_VISIBLE DirIter
264 {
266 public: DirIter();
267
270 public: explicit DirIter(const std::string &_in);
271
275 public: std::string operator*() const;
276
279 public: const DirIter &operator++();
280
285 public: bool operator!=(const DirIter &_other) const;
286
288 GZ_UTILS_IMPL_PTR(dataPtr)
289 };
290 }
291}
292
293#endif