2014-05-19 09:29:19 +08:00
|
|
|
#pragma once
|
|
|
|
|
2014-05-20 08:47:15 +08:00
|
|
|
#include <array>
|
2014-05-21 22:20:30 +08:00
|
|
|
#include <fstream>
|
2015-10-14 12:03:48 +08:00
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2014-05-20 08:47:15 +08:00
|
|
|
|
2016-10-19 07:27:26 +08:00
|
|
|
#include <xlnt/utils/path.hpp>
|
2015-11-03 21:38:09 +08:00
|
|
|
|
2017-01-21 23:12:08 +08:00
|
|
|
#define STRING_LITERAL2(a) #a
|
|
|
|
#define LSTRING_LITERAL2(a) L#a
|
|
|
|
#define U8STRING_LITERAL2(a) u8#a
|
|
|
|
#define STRING_LITERAL(a) STRING_LITERAL2(a)
|
|
|
|
#define LSTRING_LITERAL(a) STRING_LITERAL2(a)
|
|
|
|
#define U8STRING_LITERAL(a) STRING_LITERAL2(a)
|
|
|
|
|
2017-04-14 08:18:32 +08:00
|
|
|
#ifndef XLNT_BENCHMARK_DATA_DIR
|
|
|
|
#define XLNT_BENCHMARK_DATA_DIR ""
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef XLNT_SAMPLE_DATA_DIR
|
|
|
|
#define XLNT_SAMPLE_DATA_DIR ""
|
|
|
|
#endif
|
|
|
|
|
2016-07-21 07:04:44 +08:00
|
|
|
class path_helper
|
2014-05-19 09:29:19 +08:00
|
|
|
{
|
|
|
|
public:
|
2017-04-14 08:18:32 +08:00
|
|
|
static xlnt::path test_data_directory(const std::string &append = "")
|
2014-05-19 09:29:19 +08:00
|
|
|
{
|
2017-01-21 23:12:08 +08:00
|
|
|
static const std::string data_dir = STRING_LITERAL(XLNT_TEST_DATA_DIR);
|
2017-04-14 08:18:32 +08:00
|
|
|
return xlnt::path(data_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static xlnt::path test_file(const std::string &filename)
|
|
|
|
{
|
|
|
|
return test_data_directory().append(xlnt::path(filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
static xlnt::path benchmark_data_directory(const std::string &append = "")
|
|
|
|
{
|
|
|
|
static const std::string data_dir = STRING_LITERAL(XLNT_BENCHMARK_DATA_DIR);
|
|
|
|
return xlnt::path(data_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static xlnt::path benchmark_file(const std::string &filename)
|
|
|
|
{
|
|
|
|
return benchmark_data_directory().append(xlnt::path(filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
static xlnt::path sample_data_directory(const std::string &append = "")
|
|
|
|
{
|
|
|
|
static const std::string data_dir = STRING_LITERAL(XLNT_SAMPLE_DATA_DIR);
|
|
|
|
return xlnt::path(data_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static xlnt::path sample_file(const std::string &filename)
|
|
|
|
{
|
|
|
|
return sample_data_directory().append(xlnt::path(filename));
|
2014-05-19 09:29:19 +08:00
|
|
|
}
|
2017-09-13 20:48:22 +08:00
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
static void copy_file(const xlnt::path &source, const xlnt::path &destination, bool overwrite)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-08-03 12:12:18 +08:00
|
|
|
if(!overwrite && destination.exists())
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2017-09-13 20:48:22 +08:00
|
|
|
throw xlnt::exception("destination file already exists and overwrite==false");
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2017-09-13 20:48:22 +08:00
|
|
|
|
2016-08-12 12:22:14 +08:00
|
|
|
std::ifstream src(source.string(), std::ios::binary);
|
|
|
|
std::ofstream dst(destination.string(), std::ios::binary);
|
2017-09-13 20:48:22 +08:00
|
|
|
|
2014-05-21 22:20:30 +08:00
|
|
|
dst << src.rdbuf();
|
|
|
|
}
|
2014-06-05 06:42:17 +08:00
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
static void delete_file(const xlnt::path &path)
|
2014-06-05 06:42:17 +08:00
|
|
|
{
|
2016-08-12 12:22:14 +08:00
|
|
|
std::remove(path.string().c_str());
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2014-05-22 07:17:56 +08:00
|
|
|
};
|