26#include <boost/filesystem/fstream.hpp>
27#include <boost/filesystem/operations.hpp>
28#include <boost/filesystem/path.hpp>
34using boost::filesystem::temp_directory_path;
46 using boost::filesystem::unique_path;
48 if (
m_motif.find(
'%') == string::npos) {
49 log.error() <<
"The '" << m_motif <<
"' motif is not random";
54 if (pattern.empty()) {
55 log.warn() <<
"The motif has been replaced by \"" << DEFAULT_TMP_MOTIF <<
"\"";
56 pattern = DEFAULT_TMP_MOTIF;
59 m_path /= unique_path(pattern);
67 log.debug() <<
"Automatic destruction of the " <<
path() <<
" temporary path";
68 const auto file_number = boost::filesystem::remove_all(
m_path);
69 log.debug() <<
"Number of files removed: " << file_number;
71 log.info() <<
m_keep_var <<
" set: I do not remove the " <<
m_path.string() <<
" temporary path";
85 log.debug() <<
"Creation of the " <<
path() <<
" temporary directory";
87 boost::filesystem::create_directory(
path());
94 log.debug() <<
"Creation of the " <<
path() <<
" temporary file";
96 boost::filesystem::ofstream ofs(
path());
Defines a class to handle the Environment.
provide functions to retrieve resources pointed by environment variables
Handling of temporary files, directories and environments.
Python dictionary-like Environment interface.
static bool hasKey(const std::string &)
static Logging getLogger(const std::string &name="")
TempDir(const std::string &motif=DEFAULT_TMP_MOTIF, const std::string &keep_var=DEFAULT_TMP_KEEP_VAR)
TempFile(const std::string &motif=DEFAULT_TMP_MOTIF, const std::string &keep_var=DEFAULT_TMP_KEEP_VAR)
const std::string m_keep_var
const std::string m_motif
TempPath(const std::string &motif=DEFAULT_TMP_MOTIF, const std::string &keep_var=DEFAULT_TMP_KEEP_VAR)
std::string motif() const