Create a temporary directory in the OS temp location. Upon construction, the current working directory will be set to this new temporary directory. Upon destruction, the current working directory will be restored to the location when the TempDirectory object was constructed. More...
#include <ignitin/common/TempDirectory.hh>
Public Member Functions | |
TempDirectory (const std::string &_prefix="temp_dir", const std::string &_subDir="gz", bool _cleanup=true) | |
Create a directory in the tempDirectoryPath by expanding a name template. This directory can also be automatically cleaned up when the object goes out of scope. | |
TempDirectory (const std::string &_root, const std::string &_prefix="temp_dir", const std::string &_subDir="gz", bool _cleanup=true) | |
Create a directory in the tempDirectoryPath by expanding a name template. This directory can also be automatically cleaned up when the object goes out of scope. | |
~TempDirectory () | |
Destroy the temporary directory, removing from filesystem if cleanup is true. | |
bool | DoCleanup () const |
Retrieve the current cleanup flag state. | |
void | DoCleanup (bool _doCleanup) |
Set if the folder on disk should be cleaned. | |
std::string | Path () const |
Retrieve the fully-expanded temporary directory path. | |
bool | Valid () const |
Indicate if the TempDirectory object is in a valid state and that the folder exists on the filesystem. | |
Detailed Description
Create a temporary directory in the OS temp location. Upon construction, the current working directory will be set to this new temporary directory. Upon destruction, the current working directory will be restored to the location when the TempDirectory object was constructed.
Constructor & Destructor Documentation
◆ TempDirectory() [1/2]
TempDirectory | ( | const std::string & | _prefix = "temp_dir" , |
const std::string & | _subDir = "gz" , |
||
bool | _cleanup = true |
||
) |
Create a directory in the tempDirectoryPath by expanding a name template. This directory can also be automatically cleaned up when the object goes out of scope.
The TempDirectory will have the form $TMPDIR/_subdir/_prefixXXXXX/
- Parameters
-
[in] _prefix String to be expanded for the template [in] _subDir Subdirectory in OS $TMPDIR, if desired [in] _cleanup True to indicate that the filesystem should be cleaned as part of the destructor
◆ TempDirectory() [2/2]
|
explicit |
Create a directory in the tempDirectoryPath by expanding a name template. This directory can also be automatically cleaned up when the object goes out of scope.
The TempDirectory will have the form _root/_subdir/_prefixXXXXX/
- Parameters
-
[in[ _root Explicitly set the root directory [in] _prefix String to be expanded for the template [in] _subDir Subdirectory in OS _root, if desired [in] _cleanup True to indicate that the filesystem should be cleaned as part of the destructor
◆ ~TempDirectory()
~TempDirectory | ( | ) |
Destroy the temporary directory, removing from filesystem if cleanup is true.
Member Function Documentation
◆ DoCleanup() [1/2]
bool DoCleanup | ( | ) | const |
Retrieve the current cleanup flag state.
- Returns
- true if filesystem cleanup will occur
◆ DoCleanup() [2/2]
void DoCleanup | ( | bool | _doCleanup | ) |
Set if the folder on disk should be cleaned.
This is useful if you wish to clean by default during a test, but retain the contents of the TempDirectory if the test fails.
- Parameters
-
[in] _doCleanup True to indicate that the filesystem should be cleaned as part of the destructor
◆ Path()
std::string Path | ( | ) | const |
Retrieve the fully-expanded temporary directory path.
- Returns
- the temporary directory path
◆ Valid()
bool Valid | ( | ) | const |
Indicate if the TempDirectory object is in a valid state and that the folder exists on the filesystem.
- Returns
- true if the TempDirectory is valid
The documentation for this class was generated from the following file: