-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.cpp
More file actions
64 lines (60 loc) · 1.46 KB
/
util.cpp
File metadata and controls
64 lines (60 loc) · 1.46 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
#include "util.h"
namespace Util {
// Taken from
// https://stackoverflow.com/questions/21842849/how-to-generate-a-random-string-in-c
std::string gen_rand_str(int len){
const char* charmap = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const int charmapLength = std::strlen(charmap);
auto generator = [&](){ return charmap[rand()%charmapLength]; };
std::string result;
result.reserve(len);
generate_n(back_inserter(result), len, generator);
return result;
}
std::pair<int,int> getSide(std::pair<int,int> c,int d){
std::pair<int,int> new_loc = c;
switch(d){
case Util::North:
new_loc.second++;
break;
case Util::South:
new_loc.second--;
break;
case Util::East:
new_loc.first++;
break;
case Util::West:
new_loc.first--;
break;
};
return new_loc;
}
std::string getDirName(int d){
switch(d){
case North:
return "North";
case South:
return "South";
case East:
return "East";
case West:
return "West";
default:
return "";
};
/*
std::map<int, std::string> DirNames = {
{Util::North, "North"},
{Util::South, "South"},
{Util::East, "East"},
{Util::West, "West"}
};
auto search = DirNames.find(d);
if (search != DirNames.end()){
return search->second;
} else {
return "";
}
*/
};
}