xlnt/tests/helpers/temporary_file.hpp

40 lines
626 B
C++
Raw Normal View History

2014-05-12 19:59:33 -04:00
#pragma once
#include <array>
#include <cstdio>
#include <string>
#include <detail/external/include_windows.hpp>
#include <helpers/path_helper.hpp>
2014-05-19 20:47:15 -04:00
2016-08-03 00:12:18 -04:00
namespace {
static std::string create_temporary_filename()
2014-05-12 19:59:33 -04:00
{
2016-11-19 19:41:21 -05:00
return "temp.xlsx";
2014-05-14 22:07:23 -04:00
}
2014-05-12 19:59:33 -04:00
2016-08-03 00:12:18 -04:00
} // namespace
class temporary_file
{
public:
temporary_file() : path_(create_temporary_filename())
2014-05-12 19:59:33 -04:00
{
2016-08-03 00:12:18 -04:00
if(path_.exists())
{
std::remove(path_.string().c_str());
}
2014-05-12 19:59:33 -04:00
}
~temporary_file()
2014-05-12 19:59:33 -04:00
{
std::remove(path_.string().c_str());
2014-05-12 19:59:33 -04:00
}
2016-08-03 00:12:18 -04:00
xlnt::path get_path() const { return path_; }
2014-05-12 19:59:33 -04:00
private:
2016-08-03 00:12:18 -04:00
const xlnt::path path_;
2014-05-14 22:07:23 -04:00
};