Repository navigation
Expand file tree
/
Copy pathutils.cpp
More file actions
101 lines (85 loc) · 2.54 KB
/
Copy pathutils.cpp
File metadata and controls
101 lines (85 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "utils.hpp"
#include "metrics.hpp"
#include <cstdlib>
#include <fstream>
#include <string>
#include <vector>
#include <windows.h>
#include <winuser.h>
std::string vectorToString(const std::vector<unsigned int> &v) {
std::string s;
s.reserve(v.size() * 6);
for (size_t i = 0; i < v.size(); i++) {
s += std::to_string(v[i]);
if (i + 1 < v.size()) {
s += ", ";
}
}
return s;
}
void resetCounters() {
amountOfIterations = 0;
amountOfComparisons = 0;
steps.clear();
currentStep = 0;
}
std::string narrowPath(const std::wstring &wide) { return std::string(wide.begin(), wide.end()); }
void writeVectorToFile(const std::wstring &path, const std::vector<unsigned int> &data) {
if (path.empty()) {
return;
}
std::ofstream file(narrowPath(path));
if (!file.is_open()) {
return;
}
for (size_t i = 0; i < data.size(); i++) {
if (i != 0) {
file << ",";
}
file << data[i];
}
}
int readIntFromEdit(HWND hwnd, int controlId, int fallback) {
HWND control = GetDlgItem(hwnd, controlId);
if (!control) {
return fallback;
}
int len = GetWindowTextLength(control);
if (len <= 0) {
return fallback;
}
std::string buffer((size_t)(len + 1), '\0');
GetWindowTextA(control, buffer.data(), len + 1);
try {
return std::stoi(buffer);
} catch (...) {
return fallback;
}
}
HWND createNumericEdit(HWND hwnd, int x, int y, int width, int height, int id, int limit) {
HWND control =
CreateWindow("EDIT", 0, WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOVSCROLL | ES_MULTILINE | ES_NUMBER, x, y,
width, height, hwnd, reinterpret_cast<HMENU>(static_cast<intptr_t>(id)), NULL, NULL);
SendMessage(control, EM_SETLIMITTEXT, limit, 0);
return control;
}
HWND createReadOnlyEdit(HWND hwnd, int x, int y, int width, int height, int id) {
HWND control = CreateWindow("EDIT", 0, WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOVSCROLL | ES_MULTILINE, x, y, width,
height, hwnd, reinterpret_cast<HMENU>(static_cast<intptr_t>(id)), NULL, NULL);
SendMessage(control, EM_SETREADONLY, TRUE, 0);
return control;
}
std::vector<unsigned int> makeRandomVector(int count) {
if (count <= 0) {
return {};
}
std::vector<unsigned int> result;
result.reserve(count);
for (int i = 0; i < count; i++) {
result.push_back(rand() % 10000);
}
return result;
}
void displayVector(HWND hwnd, int controlId, const std::vector<unsigned int> &data) {
SendMessage(GetDlgItem(hwnd, controlId), WM_SETTEXT, 0, (LPARAM)vectorToString(data).c_str());
}