spdlog/tests/utils.cpp

46 lines
992 B
C++
Raw Normal View History

#include "includes.h"
void prepare_logdir()
{
spdlog::drop_all();
#ifdef _WIN32
2016-04-03 06:25:41 +08:00
auto rv = system("del /F /Q logs\\*");
#else
2016-04-03 06:25:41 +08:00
auto rv = system("rm -f logs/*");
#endif
2016-04-03 06:25:41 +08:00
(void)rv;
}
2015-12-13 20:59:48 +08:00
std::string file_contents(const std::string& filename)
{
std::ifstream ifs(filename);
if (!ifs)
throw std::runtime_error("Failed open file ");
return std::string((std::istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));
}
std::size_t count_lines(const std::string& filename)
{
std::ifstream ifs(filename);
if (!ifs)
throw std::runtime_error("Failed open file ");
std::string line;
size_t counter = 0;
while(std::getline(ifs, line))
counter++;
return counter;
}
2015-12-13 21:13:16 +08:00
std::size_t get_filesize(const std::string& filename)
2015-12-13 20:59:48 +08:00
{
std::ifstream ifs(filename, std::ifstream::ate | std::ifstream::binary);
if (!ifs)
throw std::runtime_error("Failed open file ");
return ifs.tellg();
}