27 #include <boost/filesystem/operations.hpp>
28 #include <boost/filesystem/fstream.hpp>
35 using boost::filesystem::temp_directory_path;
44 m_motif(arg_motif), m_path(temp_directory_path()), m_keep_var(keep_var) {
46 using boost::filesystem::unique_path;
49 log.error() <<
"The '" <<
m_motif <<
"' motif is not random";
54 if (pattern.empty()) {
59 m_path /= unique_path(pattern);
67 log.debug() <<
"Automatic destruction of the " <<
path()
69 const auto file_number = boost::filesystem::remove_all(
m_path);
70 log.debug() <<
"Number of files removed: " << file_number;
72 log.info() <<
m_keep_var <<
" set: I do not remove the "
73 <<
m_path.string() <<
" temporary path";
89 log.debug() <<
"Creation of the " <<
path() <<
" temporary directory";
91 boost::filesystem::create_directory(
path());
101 log.debug() <<
"Creation of the " <<
path() <<
" temporary file";
103 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.
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
boost::filesystem::path Item
const std::string DEFAULT_TMP_MOTIF
The default random creation motif.