Gazebo Common

API Reference

4.7.0
gz/common/TempDirectory.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2021 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 IGNITION_COMMON_TEMPDIRECTORY_HH_
19 #define IGNITION_COMMON_TEMPDIRECTORY_HH_
20 
21 #include <memory>
22 #include <string>
23 
24 #include <gz/common/config.hh>
25 #include <gz/common/Export.hh>
26 #include <gz/common/Filesystem.hh>
27 
28 namespace ignition
29 {
30  namespace common
31  {
32  class TempDirectoryPrivate;
33 
39  std::string IGNITION_COMMON_VISIBLE tempDirectoryPath();
40 
52  std::string IGNITION_COMMON_VISIBLE createTempDirectory(
53  const std::string &_baseName,
54  const std::string &_parentPath,
55  const FilesystemWarningOp _warningOp = FSWO_LOG_WARNINGS);
56 
63  class IGNITION_COMMON_VISIBLE TempDirectory
64  {
75  public: TempDirectory(const std::string &_prefix = "temp_dir",
76  const std::string &_subDir = "ignition",
77  bool _cleanup = true);
78 
81  public: ~TempDirectory();
82 
86  public: bool Valid() const;
87 
94  public: void DoCleanup(bool _doCleanup);
95 
98  public: bool DoCleanup() const;
99 
102  public: std::string Path() const;
103 
106  private: std::unique_ptr<TempDirectoryPrivate> dataPtr;
108  };
109  } // namespace common
110 } // namespace ignition
111 #endif // IGNITION_COMMON_TEMPDIRECTORY_HH_
Forward declarations for the common classes.
STL class.
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: gz/common/SuppressWarning.hh:65
std::string tempDirectoryPath()
Return the path to a directory suitable for temporary files.
@ FSWO_LOG_WARNINGS
Errors that occur during filesystem manipulation should be logged as warnings using ignwarn....
Definition: gz/common/Filesystem.hh:38
FilesystemWarningOp
Options for how to handle errors that occur in functions that manipulate the filesystem.
Definition: gz/common/Filesystem.hh:34
~TempDirectory()
Destroy the temporary directory, removing from filesystem if cleanup is true.
std::string createTempDirectory(const std::string &_baseName, const std::string &_parentPath, const FilesystemWarningOp _warningOp=FSWO_LOG_WARNINGS)
Create a directory in the tempDirectoryPath by expanding a name template.
bool Valid() const
Indicate if the TempDirectory object is in a valid state and that the folder exists on the filesystem...
Create a temporary directory in the OS temp location. Upon construction, the current working director...
Definition: gz/common/TempDirectory.hh:63
std::string Path() const
Retrieve the fully-expanded temporary directory path.
TempDirectory(const std::string &_prefix="temp_dir", const std::string &_subDir="ignition", bool _cleanup=true)
Create a directory in the tempDirectoryPath by expanding a name template. This directory can also be ...
bool DoCleanup() const
Retrieve the current cleanup flag state.
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: gz/common/SuppressWarning.hh:68