forked from miketardy-ynov-classroom/ynov-b2-cpp-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
67 lines (58 loc) · 1.78 KB
/
Utils.cpp
File metadata and controls
67 lines (58 loc) · 1.78 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
//
// Created by Théodore Orfèvres on 14/03/2018.
//
#include <iostream>
#include <fstream>
#include <vector>
#include <ctime>
#include <boost/algorithm/string.hpp>
#include "Utils.h"
Utils::Utils(const std::string path) {
ifstream fileOfNames(path);
string line;
while (getline(fileOfNames, line)) {
names.push_back(line);
}
fileOfNames.close();
}
//------------------------------------------------------------------------------------------------------------------O
/**
* Tell if a vector has a certain int value (index)
* @param v vector
* @param x index (int)
* @return hasIndex (bool)
*/
bool Utils::hasIndex(vector<int> v, int x) {
for (int y : v) {
if (y == x) return true;
}
return false;
}
//------------------------------------------------------------------------------------------------------------------O
/**
* Translate amount of days played into a date
* @return readable date
*/
string Utils::getReadableCustomDate(int days) {
return to_string(days / 360) + "Y-" +
std::to_string((days / 30) % 12) + "M-" +
std::to_string(days % 30) + "D";
}
//------------------------------------------------------------------------------------------------------------------O
/**
* Get a random name from the list built with a txt file
* @return name (char *)
*/
string Utils::getRandName(bool isMale) {
string name;
vector<string> values;
do {
name = names.at(rand() % names.size());
boost::split(values,name,boost::is_any_of(","));
} while (values.at(1) == (isMale ? "Boy" : "Girl"));
return values.at(0);
}
//------------------------------------------------------------------------------------------------------------------O
vector<string> Utils::getNames() const {
return names;
}