UTILLib 2.0
Common C++ library with utilities.
Loading...
Searching...
No Matches
util::log::TempDir Class Reference

#include <tempdir.h>

Public Member Functions

 TempDir (const std::string &sub_dir, bool unique_dir)
 Creates a temporary directory.
virtual ~TempDir ()
 The destructor removes the temporary directory.
const std::string & Path () const
 Full path to the temporary directory.
std::string TempFile (const std::string &stem, const std::string &extension, bool unique_file) const
 Generates a temporary and optional unique file name.

Detailed Description

The class creates a directory on the temporary path on the computer. The directory can be used for storing temporary files.

The directory is removed when the destructor is called.

Constructor & Destructor Documentation

◆ TempDir()

util::log::TempDir::TempDir ( const std::string & sub_dir,
bool unique_dir )

Creates a temporary directory in the default temporary directory. Normally the new directory name would be the application name. If multiple application using this function, are running on this computer, it is recommended that the unique_dir flag is set.

A unique directory is named 'sub_dir_XXXX' where X is a random hexadecimal digit. If the unique_dir flag is false, the director is named 'sub_dir'

The temporary directory and its files are removed when the destructor is called.

Parameters
sub_dirRecommended sub-directory base name. If empt a directory 'utillib' is created.
unique_dirIf set to true, a unique directory name is created.

◆ ~TempDir()

virtual util::log::TempDir::~TempDir ( )
virtual

The destructor removes the created directory and its files

Member Function Documentation

◆ Path()

const std::string & util::log::TempDir::Path ( ) const
inlinenodiscard

Returns full path to the temporary directory.

Returns
Path to temporary directory.

◆ TempFile()

std::string util::log::TempDir::TempFile ( const std::string & stem,
const std::string & extension,
bool unique_file ) const
nodiscard

Generates a temporary file name with path and extension.

Parameters
stemBase name of the file.
extensionFile extension
unique_fileSet to true if a unique file name should be generated.
Returns
File name with path and extension.

The documentation for this class was generated from the following file: