Mantid
Loading...
Searching...
No Matches
FileResource.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include <boost/filesystem.hpp>
9#include <string>
10
11FileResource::FileResource(const std::string &fileName, bool debugMode) : m_debugMode(debugMode) {
12
13 const auto temp_dir = boost::filesystem::temp_directory_path();
14 auto temp_full_path = temp_dir;
15 // append full path to temp directory to user input file name
16 temp_full_path /= fileName;
17
18 // Check proposed location and throw std::invalid argument if file does
19 // not exist. otherwise set m_full_path to location.
20
21 if (boost::filesystem::is_directory(temp_dir)) {
22 m_full_path = temp_full_path;
23
24 } else {
25 throw std::invalid_argument("failed to load temp directory: " + temp_dir.generic_string());
26 }
27}
28
29void FileResource::setDebugMode(bool mode) { m_debugMode = mode; }
30std::string FileResource::fullPath() const { return m_full_path.generic_string(); }
31
33
34 // file is removed at end of file handle's lifetime
35 if (boost::filesystem::is_regular_file(m_full_path)) {
36 if (!m_debugMode)
37 boost::filesystem::remove(m_full_path);
38 else
39 std::cout << "Debug file at: " << m_full_path << " not removed. " << std::endl;
40 }
41}
void setDebugMode(bool mode)
std::string fullPath() const
FileResource(const std::string &fileName, bool debugMode=false)
bool m_debugMode
Definition: FileResource.h:29
boost::filesystem::path m_full_path
Definition: FileResource.h:30