comparison Framework/Toolbox/LinearAlgebra.cpp @ 860:238693c3bc51 am-dev

merge default -> am-dev
author Alain Mazy <alain@mazy.be>
date Mon, 24 Jun 2019 14:35:00 +0200
parents 61ba4b504e9a
children 32eaf4929b08
comparison
equal deleted inserted replaced
856:a6e17a5a39e7 860:238693c3bc51
61 61
62 bool ParseVector(Vector& target, 62 bool ParseVector(Vector& target,
63 const std::string& value) 63 const std::string& value)
64 { 64 {
65 std::vector<std::string> items; 65 std::vector<std::string> items;
66 Orthanc::Toolbox::TokenizeString(items, value, '\\'); 66 Orthanc::Toolbox::TokenizeString(items, Orthanc::Toolbox::StripSpaces(value), '\\');
67 67
68 target.resize(items.size()); 68 target.resize(items.size());
69 69
70 for (size_t i = 0; i < items.size(); i++) 70 for (size_t i = 0; i < items.size(); i++)
71 { 71 {
72 /**
73 * We try and avoid the use of "boost::lexical_cast<>" here,
74 * as it is very slow. As we are parsing many doubles, we
75 * prefer to use the standard "std::stod" function if
76 * available: http://www.cplusplus.com/reference/string/stod/
77 **/
78
79 #if __cplusplus >= 201103L // Is C++11 enabled?
72 try 80 try
73 { 81 {
74 target[i] = boost::lexical_cast<double>(Orthanc::Toolbox::StripSpaces(items[i])); 82 target[i] = std::stod(items[i]);
75 } 83 }
76 catch (boost::bad_lexical_cast&) 84 catch (std::exception&)
77 { 85 {
78 target.clear(); 86 target.clear();
79 return false; 87 return false;
80 } 88 }
89 #else // Fallback implementation using Boost
90 try
91 {
92 target[i] = boost::lexical_cast<double>(items[i]);
93 }
94 catch (boost::bad_lexical_cast&)
95 {
96 target.clear();
97 return false;
98 }
99 #endif
81 } 100 }
82 101
83 return true; 102 return true;
84 } 103 }
85 104