BDE 4.14.0 Production release
|
Provide a scoped guard that creates a unique temporary directory.
This component provides a scoped guard bdls::TempDirectoryGuard
, intended primarily for testing, which creates a uniquely named temporary directory. If possible, this is located in the system temp directory, otherwise it is created within the current working directory.
As this class is primarily intended for testing, any failures to build the directory name or create the temporary directory will be fatal.
This section illustrates intended use of this component.
Suppose an algorithm requires writing data to a temporary file on disk during processing:
A function looking to use this algorithm can obtain a directory in which to put this file, guaranteed to not be used by other processes and to be cleaned up on normal exit, using an instance of bdls::TempDirectoryGuard
:
After exiting, the scratch file (named "algorithm.scratch") and the temporary directory (with an unspecified name starting with "my_algo_"), possibly in the system temp directory or the current working directory, will be removed.