9 #include <boost/algorithm/string.hpp>
10 #include <boost/algorithm/string/predicate.hpp>
22 size_t count = std::count(theString.begin(), theString.end(), delimiter);
29 size_t signatureLen = 6;
30 if(theString.length() < signatureLen)
return false;
31 if(theString.substr(0, 6) !=
"sdm://")
return false;
38 boost::trim(theString);
39 if(theString.length() < 3)
return false;
40 if(theString.substr(0, 1) !=
"(")
return false;
41 if(theString.substr(theString.length() - 1, 1) !=
")")
return false;
52 boost::trim(cddString);
55 if(cddString.length() < 3) {
58 if(cddString.substr(0, 1) !=
"(") {
59 throw ChimeraTK::logic_error(
"Invalid ChimeraTK device descriptor (missing opening parenthesis): " + cddString);
61 if(cddString.substr(cddString.length() - 1, 1) !=
")") {
62 throw ChimeraTK::logic_error(
"Invalid ChimeraTK device descriptor (missing opening parenthesis): " + cddString);
66 size_t parenthesesLevel = 0;
67 enum class tokenType { backendType, address, parameters };
68 tokenType currentTokenType = tokenType::backendType;
69 bool escapeNext =
false;
71 size_t positionPlusOne = 0;
72 for(
auto& c : cddString) {
75 if(parenthesesLevel == 1) {
78 if(c ==
' ' || c ==
'?' || c ==
'&' || c ==
'(' || c ==
')' || c ==
'\\') {
92 else if(currentTokenType == tokenType::backendType && (c ==
':' || c ==
'?' || c ==
')')) {
95 if(token.length() == 0) {
97 "(backend type must be non-empty): " +
100 if(!boost::all(token, boost::is_alnum())) {
102 "(backend type must be alphanumeric): " +
110 currentTokenType = tokenType::address;
113 currentTokenType = tokenType::parameters;
116 else if(currentTokenType == tokenType::address && (c ==
'?' || c ==
')')) {
121 currentTokenType = tokenType::parameters;
123 else if(currentTokenType == tokenType::parameters && (c ==
'&' || c ==
')')) {
126 if(token.length() > 0) {
127 auto equalSign = token.find_first_of(
'=');
128 if(equalSign == std::string::npos) {
130 "specified as key=value pairs): " +
133 auto key = token.substr(0, equalSign);
134 auto value = token.substr(equalSign + 1);
136 if(key.length() == 0) {
141 if(!boost::all(key, boost::is_alnum())) {
144 "alphanumeric characters): " +
150 "' specified multiple times): " + cddString);
160 else if(parenthesesLevel > 1) {
169 if(parenthesesLevel == 0 && positionPlusOne != cddString.length()) {
172 "last closing parenthesis): " +
179 if(parenthesesLevel != 0) {
180 throw ChimeraTK::logic_error(
"Invalid ChimeraTK device descriptor (unmatched parenthesis): " + cddString);
191 size_t signatureLen = 6;
196 std::size_t found = sdmString.find_first_of(
'/', pos);
198 if(found != std::string::npos) {
199 sdmInfo.
host = sdmString.substr(pos, found - pos);
204 if(sdmString.length() < found + 1)
return sdmInfo;
205 subUri = sdmString.substr(found + 1);
219 std::vector<std::string> tokens;
220 boost::split(tokens, subUri, boost::is_any_of(
":;="));
221 size_t numOfTokens = tokens.size();
222 if(numOfTokens < 1)
return sdmInfo;
226 if(counter < numOfTokens) {
228 found = sdmString.find_first_of(
':', pos);
229 if(found != std::string::npos) {
234 if(counter < numOfTokens) {
236 found = sdmString.find_first_of(
';', pos);
237 if(found != std::string::npos) {
242 if(counter < numOfTokens) {
244 found = sdmString.find_first_of(
'=', pos);
245 if(found != std::string::npos) {
246 std::string parameters = tokens[counter];
247 std::vector<std::string> paramterTokens;
248 boost::split(paramterTokens, parameters, boost::is_any_of(
","));
249 for(
auto& paramterToken : paramterTokens) {
262 if(deviceString.substr(0, 5) ==
"/dev/") {
264 if(deviceString.length() > 5) {
265 sdmInfo.
instance = deviceString.substr(5);
268 else if((boost::ends_with(deviceString,
".map")) || (boost::ends_with(deviceString,
".mapp"))) {
289 deviceInfoPointer->getDeviceInfo(aliasName, deviceInfo);
297 if(dmapFileName.empty()) {
304 std::vector<std::string> listOfDeviceAliases;
305 listOfDeviceAliases.reserve(deviceInfoMap->getSize());
307 for(
auto&& deviceInfo : *deviceInfoMap) {
308 listOfDeviceAliases.push_back(deviceInfo.deviceName);
311 return listOfDeviceAliases;
314 std::cout << e.
what() << std::endl;
336 int i, trace_size = 0;
338 trace_size = backtrace(trace, 16);
339 messages = backtrace_symbols(trace, trace_size);
340 printf(
"[bt] Execution path:\n");
341 for(i = 0; i < trace_size; ++i) {
342 std::string msg(messages[i]);
343 size_t a = msg.find_first_of(
'(');
344 size_t b = msg.find_first_of(
'+');
345 std::string functionName = boost::core::demangle(msg.substr(a + 1, b - a - 1).c_str());
346 std::cout <<
"[bt] #" << i <<
" " << functionName << std::endl;