https://mooseframework.inl.gov
Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
Moose::UnitUtils::TempFile Class Reference

Create a temporary file and delete it upon destruction. More...

#include <MooseUnitUtils.h>

Public Member Functions

 TempFile ()
 
 ~TempFile ()
 
const std::filesystem::path & path () const
 

Static Private Member Functions

static std::filesystem::path generatePath ()
 

Private Attributes

const std::filesystem::path _path
 

Detailed Description

Create a temporary file and delete it upon destruction.

Definition at line 118 of file MooseUnitUtils.h.

Constructor & Destructor Documentation

◆ TempFile()

Moose::UnitUtils::TempFile::TempFile ( )

Definition at line 16 of file MooseUnitUtils.C.

16 : _path(generatePath()) {}
const std::filesystem::path _path
static std::filesystem::path generatePath()

◆ ~TempFile()

Moose::UnitUtils::TempFile::~TempFile ( )

Definition at line 18 of file MooseUnitUtils.C.

19 {
20  std::error_code ec;
21  std::filesystem::remove(path(), ec);
22 }
const std::filesystem::path & path() const

Member Function Documentation

◆ generatePath()

std::filesystem::path Moose::UnitUtils::TempFile::generatePath ( )
staticprivate

Definition at line 25 of file MooseUnitUtils.C.

26 {
27  static const std::string chars = "abcdefghijklmnopqrstuvwxyz0123456789";
28  static thread_local std::mt19937 generator{std::random_device{}()};
29  std::uniform_int_distribution<std::size_t> distribution(0, chars.size() - 1);
30  std::string result;
31  const std::size_t len = 10;
32  result.reserve(len);
33  for (std::size_t i = 0; i < len; ++i)
34  result += chars[distribution(generator)];
35  return std::filesystem::temp_directory_path() / std::filesystem::path("mooseunit." + result);
36 }

◆ path()

const std::filesystem::path& Moose::UnitUtils::TempFile::path ( ) const
inline
Returns
The path to the temporary file.

Definition at line 127 of file MooseUnitUtils.h.

Referenced by ~TempFile().

127 { return _path; }
const std::filesystem::path _path

Member Data Documentation

◆ _path

const std::filesystem::path Moose::UnitUtils::TempFile::_path
private

Definition at line 132 of file MooseUnitUtils.h.

Referenced by path().


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