Ignition Common

API Reference

4.4.0
TempDirectory Class Reference

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="ignition", 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. More...
 
 ~TempDirectory ()
 Destroy the temporary directory, removing from filesystem if cleanup is true. More...
 
void DoCleanup (bool _doCleanup)
 Set if the folder on disk should be cleaned. More...
 
bool DoCleanup () const
 Retrieve the current cleanup flag state. More...
 
std::string Path () const
 Retrieve the fully-expanded temporary directory path. More...
 
bool Valid () const
 Indicate if the TempDirectory object is in a valid state and that the folder exists on the filesystem. More...
 

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()

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 automatically cleaned up when the object goes out of scope.

The TempDirectory will have the form $TMPDIR/_subdir/_prefixXXXXX/

Parameters
[in]_prefixString to be expanded for the template
[in]_subDirSubdirectory in OS $TMPDIR, if desired
[in]_cleanupTrue to indicate that the filesystem should be cleaned as part of the destructor

◆ ~TempDirectory()

Destroy the temporary directory, removing from filesystem if cleanup is true.

Member Function Documentation

◆ DoCleanup() [1/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]_doCleanupTrue to indicate that the filesystem should be cleaned as part of the destructor

◆ DoCleanup() [2/2]

bool DoCleanup ( ) const

Retrieve the current cleanup flag state.

Returns
true if filesystem cleanup will occur

◆ 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: