Mercurial > hg > orthanc
changeset 2967:146eaed9b02c
avoid boost::bad_lexical_cast exception in happy path
author | am@osimis.io |
---|---|
date | Wed, 05 Dec 2018 16:30:11 +0100 |
parents | 10c610e80b15 |
children | e361df74639f |
files | Core/EnumerationDictionary.h TODO |
diffstat | 2 files changed, 6 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/EnumerationDictionary.h Wed Dec 05 15:27:01 2018 +0100 +++ b/Core/EnumerationDictionary.h Wed Dec 05 16:30:11 2018 +0100 @@ -37,6 +37,7 @@ #include "Toolbox.h" #include <boost/lexical_cast.hpp> +#include <boost/lexical_cast/try_lexical_convert.hpp> #include <string> #include <map> @@ -84,12 +85,10 @@ Enumeration Translate(const std::string& str) const { - try + int numericalValue; // at this stage, we don't know if str is an alias or a numerical value + if (boost::conversion::try_lexical_convert<int>(str, numericalValue)) { - return static_cast<Enumeration>(boost::lexical_cast<int>(str)); - } - catch (boost::bad_lexical_cast&) - { + return static_cast<Enumeration>(numericalValue); } typename StringToEnumeration::const_iterator
--- a/TODO Wed Dec 05 15:27:01 2018 +0100 +++ b/TODO Wed Dec 05 16:30:11 2018 +0100 @@ -134,7 +134,8 @@ Release() and Acquire()) * Avoid direct calls to FromDcmtkBridge (make most of its methods private), go through ParsedDicomFile wherever possible - +* avoid boost::bad_lexical_cast exception at least in happy path + by using boost::conversion::try_lexical_convert ================= Platform-specific