Use Boost to demangle type names in AnyValue casting errors

This commit is contained in:
Ray Speth 2018-12-10 14:03:53 -05:00
parent cb31c297cf
commit d476ad8e59
3 changed files with 13 additions and 1 deletions

View file

@ -1023,6 +1023,9 @@ print('INFO: Found Boost version {0}'.format(env['BOOST_LIB_VERSION']))
if not env['BOOST_LIB_VERSION']:
config_error("Boost could not be found. Install Boost headers or set"
" 'boost_inc_dir' to point to the boost headers.")
# demangle is availble in Boost 1.55 or newer
env['has_demangle'] = conf.CheckDeclaration("boost::core::demangle",
'#include <boost/core/demangle.hpp>', 'C++')
import SCons.Conftest, SCons.SConf
context = SCons.SConf.CheckContext(conf)
@ -1480,6 +1483,7 @@ cdefine('CT_USE_LAPACK', 'use_lapack')
cdefine('CT_USE_SYSTEM_EIGEN', 'system_eigen')
cdefine('CT_USE_SYSTEM_FMT', 'system_fmt')
cdefine('CT_USE_SYSTEM_YAMLCPP', 'system_yamlcpp')
cdefine('CT_USE_DEMANGLE', 'has_demangle')
config_h_build = env.Command('build/src/config.h.build',
'include/cantera/base/config.h.in',

View file

@ -45,6 +45,7 @@ typedef int ftnlen; // Fortran hidden string length type
%(CT_USE_SYSTEM_EIGEN)s
%(CT_USE_SYSTEM_FMT)s
%(CT_USE_SYSTEM_YAMLCPP)s
%(CT_USE_DEMANGLE)s
//--------- operating system --------------------------------------

View file

@ -6,6 +6,9 @@
#include "cantera/base/AnyMap.h"
#include "cantera/base/yaml.h"
#include "cantera/base/stringUtils.h"
#ifdef CT_USE_DEMANGLE
#include <boost/core/demangle.hpp>
#endif
#include <boost/algorithm/string.hpp>
@ -363,7 +366,11 @@ std::string AnyValue::demangle(const std::type_info& type) const
if (s_typenames.find(type.name()) != s_typenames.end()) {
return s_typenames[type.name()];
} else {
return type.name();
#ifdef CT_USE_DEMANGLE
return boost::core::demangle(type.name());
#else
return type.name();
#endif
}
}