-
Notifications
You must be signed in to change notification settings - Fork 3
/
cuda_strings.cu
84 lines (69 loc) · 1.76 KB
/
cuda_strings.cu
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
#include "cuda_strings.hpp"
#include <algorithm>
#include <sstream>
#include <iostream>
std::string matchParam
(std::ifstream& input, const char* param_name)
{
std::string param_string;
std::string line;
/* read in line from file */
while (std::getline(input, line))
{
if (line.find("!") != std::string::npos) continue;
/* if it has the parameter name, its the line we want */
if (line.find(param_name) != std::string::npos)
{
if (line.find("=") != std::string::npos)
{
param_string = std::string(line.erase(0, 1+line.find("=")));
}
else
{
param_string = std::string(param_name);
}
break;
}
}
// getline() sets failbit - clear it
input.clear();
input.seekg(0);
return param_string;
}
std::string readString
(std::ifstream& input, const char * setting)
{
std::string plat_name = matchParam(input, setting);
// convert to lower case
std::transform(plat_name.begin(),
plat_name.end(),
plat_name.begin(),
tolower);
return plat_name;
}
int readInt
(std::ifstream& input, const char * setting)
{
std::string param_string = matchParam(input, setting);
int param_value;
if (param_string.size() == 0)
{
// not found in file
param_value = -1;
}
else
{
std::stringstream converter(param_string);
if (!(converter >> param_value))
{
param_value = -1;
}
}
return param_value;
}
bool paramEnabled
(std::ifstream& input, const char* param)
{
std::string param_string = matchParam(input, param);
return (param_string.size() != 0);
}