@@ -41,58 +41,52 @@ std::vector<std::string> tokenize(const std::string &Filter,
41
41
}
42
42
43
43
device_filter::device_filter (const std::string &FilterString) {
44
- std::string SubString;
44
+ std::vector<std::string> Tokens = tokenize (FilterString, " :" );
45
+ size_t I = 0 ;
45
46
46
47
auto FindElement = [&](auto Element) {
47
- size_t Found = SubString .find (Element.first );
48
+ size_t Found = Tokens[I] .find (Element.first );
48
49
if (Found == std::string::npos)
49
50
return false ;
50
51
return true ;
51
52
};
52
53
53
54
// Handle the optional 1st field of the filter, backend
54
55
// Check if the first entry matches with a known backend type
55
- std::vector<std::string> Tokens = tokenize (FilterString, " :" );
56
- size_t I = 0 ;
57
- SubString = Tokens[i];
58
56
auto It =
59
- std::find_if (std::begin (SyclBeMap), std::end (SyclBeMap), findElement );
57
+ std::find_if (std::begin (SyclBeMap), std::end (SyclBeMap), FindElement );
60
58
// If no match is found, set the backend type backend::all
61
59
// which actually means 'any backend' will be a match.
62
60
if (It == SyclBeMap.end ())
63
61
Backend = backend::all;
64
62
else {
65
63
Backend = It->second ;
66
- i++;
67
- if (i < Tokens.size ())
68
- SubString = Tokens[i];
64
+ I++;
69
65
}
70
66
71
67
// Handle the optional 2nd field of the filter - device type.
72
68
// Check if the 2nd entry matches with any known device type.
73
- if (i >= Tokens.size ()) {
69
+ if (I >= Tokens.size ()) {
74
70
DeviceType = info::device_type::all;
75
71
} else {
76
72
auto Iter = std::find_if (std::begin (SyclDeviceTypeMap),
77
- std::end (SyclDeviceTypeMap), findElement );
73
+ std::end (SyclDeviceTypeMap), FindElement );
78
74
// If no match is found, set device_type 'all',
79
75
// which actually means 'any device_type' will be a match.
80
76
if (Iter == SyclDeviceTypeMap.end ())
81
77
DeviceType = info::device_type::all;
82
78
else {
83
79
DeviceType = Iter->second ;
84
- i++;
85
- if (i < Tokens.size ())
86
- SubString = Tokens[i];
80
+ I++;
87
81
}
88
82
}
89
83
90
84
// Handle the optional 3rd field of the filter, device number
91
85
// Try to convert the remaining string to an integer.
92
86
// If succeessful, the converted integer is the desired device num.
93
- if (i < Tokens.size ()) {
87
+ if (I < Tokens.size ()) {
94
88
try {
95
- DeviceNum = stoi (SubString );
89
+ DeviceNum = stoi (Tokens[I] );
96
90
HasDeviceNum = true ;
97
91
} catch (...) {
98
92
std::string Message =
0 commit comments