PLot changes
This commit is contained in:
37
code/misc.h
37
code/misc.h
@@ -12,6 +12,43 @@
|
||||
|
||||
#include "Settings.h"
|
||||
|
||||
static std::string timeForFilename(const std::time_t& time)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::put_time(std::localtime(&time), "%F_%T"); // ISO 8601 without timezone information.
|
||||
auto s = ss.str();
|
||||
std::replace(s.begin(), s.end(), ':', '-');
|
||||
return s;
|
||||
}
|
||||
|
||||
static std::string currentTimeForFilename()
|
||||
{
|
||||
auto time = std::time(nullptr);
|
||||
return timeForFilename(time);
|
||||
}
|
||||
|
||||
static std::filesystem::path appendCurrentTimeToFilename(const std::filesystem::path& fileName)
|
||||
{
|
||||
return fileName.stem().string() + "_" + currentTimeForFilename() + fileName.extension().string();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline std::filesystem::path appendFileSuffixToPath(const std::filesystem::path& path, T value)
|
||||
{
|
||||
std::string filename = path.stem().string() + "_" + std::to_string(value) + path.extension().string();
|
||||
return path.parent_path() / filename;
|
||||
}
|
||||
|
||||
|
||||
static bool forceDirectories(const std::filesystem::path& path)
|
||||
{
|
||||
if (!std::filesystem::exists(path)) {
|
||||
return std::filesystem::create_directories(path);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<typename T, int Size>
|
||||
std::vector<T> asVector(const std::array<T, Size>& src)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user