-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
59 lines (51 loc) · 1.37 KB
/
Copy pathutils.cpp
File metadata and controls
59 lines (51 loc) · 1.37 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
#include "utils.h"
#include "genome.h"
#include <iostream>
#include <vector>
#include <string>
#include <memory>
void log ( const std::string msg ) {
std::cout << msg << std::endl;
}
bool assume ( const bool isGood, const std::string msg, bool fatal ) {
if (!isGood) {
if (fatal) {
std::cerr << "Error: " << msg << ", halting.\n";
std::exit(-1);
return false; // pro forma for compiler
}
else {
std::cerr << "Warning: " << msg << std::endl;
return false;
}
}
return true;
}
std::vector< std::string > strsplit ( const std::string input, const std::string& delim, bool keepEmpty ) {
std::string token, theStr(input);
int L = delim.length();
std::unique_ptr<std::vector< std::string >> result(new std::vector<std::string>());
int end(0);
int start(0);
while (end >= 0) {
end = theStr.find_first_of(delim, start);
// theStr = theStr.substr(end + L);
if (keepEmpty || end != start) {
token = theStr.substr(start, end-start);
result->push_back(token);
}
start = end + L;
}
return *result;
}
/*
* For numerical values. May be inexact for floating point numbers.
* If one of {b,c} < a and the other one > a, then
* b-a <= 0 ^ c-a >= 0
* or b-a >= 0 ^ c-a <= 0
* => (b-a) * (c-a) <= 0
*/
template <typename T>
bool isBetweenBC ( T a, T b, T c ) {
return (b-a) * (c-a) <= 0;
}