From fbe8a7cd3f3f0f1dadd1ddc1789e344b7c7610b7 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sat, 1 Nov 2014 00:13:39 +0000 Subject: [PATCH] Make common interface to shared_ptr available Use configure-time checks to find an available implementation of shared_ptr from the standard library (C++11), TR1 (C++03), or Boost. --- SConstruct | 20 ++++++++++++++++++- include/cantera/base/config.h.in | 6 ++++++ include/cantera/base/smart_ptr.h | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 include/cantera/base/smart_ptr.h diff --git a/SConstruct b/SConstruct index 4c1929873..82a59ac9b 100644 --- a/SConstruct +++ b/SConstruct @@ -794,6 +794,8 @@ def get_expression_value(includes, expression): '}\n')) return '\n'.join(s) +configh = {} + env['HAS_TIMES_H'] = conf.CheckCHeader('sys/times.h', '""') env['HAS_UNISTD_H'] = conf.CheckCHeader('unistd.h', '""') # @@ -814,6 +816,22 @@ boost_version_source = get_expression_value([''], 'BOOST_LIB_ retcode, boost_lib_version = conf.TryRun(boost_version_source, '.cpp') env['BOOST_LIB_VERSION'] = boost_lib_version.strip() +# Find shared pointer implementation +configh['CT_USE_STD_SHARED_PTR'] = None +configh['CT_USE_TR1_SHARED_PTR'] = None +configh['CT_USE_MSFT_SHARED_PTR'] = None +configh['CT_USE_BOOST_SHARED_PTR'] = None +if conf.CheckStatement('std::shared_ptr x', '#include '): + configh['CT_USE_STD_SHARED_PTR'] = 1 +elif conf.CheckStatement('std::tr1::shared_ptr x', '#include '): + configh['CT_USE_TR1_SHARED_PTR'] = 1 +elif conf.CheckStatement('std::tr1::shared_ptr x', '#include '): + configh['CT_USE_MSFT_SHARED_PTR'] = 1 +elif conf.CheckStatement('boost::shared_ptr x', '#include '): + configh['CT_USE_BOOST_SHARED_PTR'] = 1 +else: + config_error("Couldn't find a working shared_ptr implementation.") + import SCons.Conftest, SCons.SConf ret = SCons.Conftest.CheckLib(SCons.SConf.CheckContext(conf), ['sundials_cvodes'], @@ -1192,7 +1210,7 @@ else: # *** Set options needed in config.h *** # ************************************** -configh = {'CANTERA_VERSION': quoted(env['cantera_version'])} +configh['CANTERA_VERSION'] = quoted(env['cantera_version']) # Conditional defines def cdefine(definevar, configvar, comp=True, value=1): diff --git a/include/cantera/base/config.h.in b/include/cantera/base/config.h.in index 3ca18b392..bc2a20344 100644 --- a/include/cantera/base/config.h.in +++ b/include/cantera/base/config.h.in @@ -55,6 +55,12 @@ typedef int ftnlen; // Fortran hidden string length type %(LAPACK_NAMES_LOWERCASE)s %(LAPACK_FTN_TRAILING_UNDERSCORE)s +//--------- shared_ptr implementation --------- +%(CT_USE_STD_SHARED_PTR)s +%(CT_USE_TR1_SHARED_PTR)s +%(CT_USE_MSFT_SHARED_PTR)s +%(CT_USE_BOOST_SHARED_PTR)s + //-------- BOOST -------- %(USE_BOOST_MATH)s diff --git a/include/cantera/base/smart_ptr.h b/include/cantera/base/smart_ptr.h new file mode 100644 index 000000000..685cadb50 --- /dev/null +++ b/include/cantera/base/smart_ptr.h @@ -0,0 +1,33 @@ +#include "config.h" + +#if defined CT_USE_STD_SHARED_PTR +#include +namespace Cantera +{ + using std::shared_ptr; +} + +#elif defined CT_USE_TR1_SHARED_PTR +#include +namespace Cantera +{ + using std::tr1::shared_ptr; +} + +#elif defined CT_USE_MSFT_SHARED_PTR +#include +namespace Cantera +{ + using std::tr1::shared_ptr; +} + +#elif defined CT_USE_BOOST_SHARED_PTR +#include +namespace Cantera +{ + using boost::shared_ptr; +} + +#else +#error "No shared_ptr implementation available" +#endif