3#include "system/Config.hpp"
28 static bool showPicker(
Picker mode,
const std::string & startDir, std::string & outPath,
const std::string & extensions =
"");
56 static uint64_t
hash64(
const void* data,
size_t size);
63 static uint32_t
hash32(
const void* data,
size_t size);
72 template<
typename ThreadFunc>
73 static void forParallel(
size_t low,
size_t high, ThreadFunc func) {
76 const size_t temp = low;
82 const size_t availableThreadsCount = std::max(
int(std::thread::hardware_concurrency())-1, 1);
83 const size_t count = std::min(
size_t(availableThreadsCount), high - low);
84 std::vector<std::thread> threads;
85 threads.reserve(count);
88 const size_t span = std::max(
size_t(1), (high - low) / count);
90 auto launchThread = [&func](
size_t a,
size_t b) {
91 for(
size_t i = a; i < b; ++i) {
96 for(
size_t tid = 0; tid < count; ++tid) {
98 const size_t threadLow = tid * span;
99 const size_t threadHigh = tid == (count-1) ? high : ((tid + 1) * span);
100 threads.emplace_back(launchThread, threadLow, threadHigh);
103 std::for_each(threads.begin(), threads.end(), [](std::thread & x) { x.join(); });
112 static wchar_t *
widen(
const std::string & str);
118 static std::string
narrow(
wchar_t * str);
126 static const char *
widen(
const std::string & str);
132 static std::string
narrow(
char * str);
Performs system basic operations such as directory creation, timing, threading, file picking.
Definition: System.hpp:12
static void forParallel(size_t low, size_t high, ThreadFunc func)
Definition: System.hpp:73
static void ping()
Definition: System.cpp:75
static const char * widen(const std::string &str)
Definition: System.cpp:124
static uint32_t hash32(const void *data, size_t size)
Definition: System.cpp:101
static bool showPicker(Picker mode, const std::string &startDir, std::string &outPath, const std::string &extensions="")
Definition: System.cpp:27
static bool createDirectory(const std::string &directory)
Definition: System.cpp:69
Picker
Definition: System.hpp:15
@ Save
Save to a new or existing file.
@ Directory
open or create a directory.
@ Load
Load an existing file.
static uint64_t hash64(const void *data, size_t size)
Definition: System.cpp:97
static double time()
Definition: System.cpp:79
static std::string narrow(char *str)
Definition: System.cpp:127
static std::string timestamp()
Definition: System.cpp:83