12 inline int str2int(std::string str) {
13 std::stringstream ss(str);
24 inline unsigned int str2uint(std::string str) {
25 std::stringstream ss(str);
37 inline std::vector<unsigned int> str2vec_uint(std::string line) {
39 std::vector<unsigned int> values;
42 for(
unsigned int i = 0, count = line.size(); i < count; i++) {
44 values.push_back(str2uint(val));
46 }
else val += line[i];
57 inline std::string vec_uint2str(std::vector<unsigned int> vec) {
58 std::string line =
"";
59 for(
auto v : vec) line += std::to_string(v) +
":";
74 inline float timeSince(
const clock_t t) {
75 return ((
float)(clock()-t) / CLOCKS_PER_SEC);
84 inline void waitFor(
const int milliseconds) {
86 sleep((
float)milliseconds / 1000.);
103 inline void clogs(
const std::string log) {
104 std::ofstream fl(FILE_LOGS, std::ios::app);
106 fl << log << std::endl;
109 std::cerr <<
"ERROR: FILE_LOGS can't opened !" << std::endl;
118 inline void clogs(
const int order) {
120 std::ofstream fl(FILE_LOGS);
121 if(fl != NULL) fl.close();
122 else std::cerr <<
"ERROR: FILE_LOGS can't opened !" << std::endl;
138 inline int randN(
const int N) {
139 return (
int) (rand() / (double)RAND_MAX * (N));
148 inline bool aChanceOn(
const unsigned int n) {
149 return (randN(n) == 0);
176 enum termcolor { BLACK=0, RED=1, GREEN=2, ORANGE=3, BLUE=4, MAGENTA=5, CYAN=6, WHITE=7 };
177 inline void term_color(
const int textc = 7,
const int backc = 0) {
178 std::cout <<
"\033[" << textc+30 <<
";" << backc+40 <<
"m";
185 inline void term_reset() {
186 std::cout <<
"\033[0m";
193 inline void term_clear() {
194 std::cout <<
"\033[H\033[2J";