From 4f63c3f8a868d54ce4f8cd682591b4c68013b7a8 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Wed, 15 Nov 2017 19:31:29 +0100 Subject: [PATCH] nasal::Object: Simplify with C++11 C++11 variadic templates finally allow us to get rid of the ugly boost preprocessor workaround. --- simgear/nasal/cppbind/CMakeLists.txt | 1 - simgear/nasal/cppbind/NasalObject.hxx | 24 +++++++------ .../NasalObject_callMethod_templates.hxx | 35 ------------------- 3 files changed, 14 insertions(+), 46 deletions(-) delete mode 100644 simgear/nasal/cppbind/detail/NasalObject_callMethod_templates.hxx diff --git a/simgear/nasal/cppbind/CMakeLists.txt b/simgear/nasal/cppbind/CMakeLists.txt index 9d005394..5ef4a5aa 100644 --- a/simgear/nasal/cppbind/CMakeLists.txt +++ b/simgear/nasal/cppbind/CMakeLists.txt @@ -17,7 +17,6 @@ set(DETAIL_HEADERS detail/from_nasal_helper.hxx detail/functor_templates.hxx detail/nasal_traits.hxx - detail/NasalObject_callMethod_templates.hxx detail/to_nasal_helper.hxx ) diff --git a/simgear/nasal/cppbind/NasalObject.hxx b/simgear/nasal/cppbind/NasalObject.hxx index 05543254..565c1670 100644 --- a/simgear/nasal/cppbind/NasalObject.hxx +++ b/simgear/nasal/cppbind/NasalObject.hxx @@ -23,9 +23,6 @@ #include "NasalObjectHolder.hxx" #include "Ghost.hxx" -#include -#include - namespace nasal { /** @@ -48,14 +45,21 @@ namespace nasal bool valid() const; - // Build dependency for CMake, gcc, etc. -#define SG_DONT_DO_ANYTHING -# include -#undef SG_DONT_DO_ANYTHING + template + Ret callMethod(const std::string& name, Args ... args) + { + if( !_nasal_impl.valid() ) + return Ret(); -#define BOOST_PP_ITERATION_LIMITS (0, 9) -#define BOOST_PP_FILENAME_1 -#include BOOST_PP_ITERATE() + Context ctx; + auto func = get_member>( + ctx, _nasal_impl.get_naRef(), name + ); + if( func ) + return func(nasal::to_nasal(ctx, this), args...); + + return Ret(); + } bool _set(naContext c, const std::string& key, naRef val); bool _get(naContext c, const std::string& key, naRef& out); diff --git a/simgear/nasal/cppbind/detail/NasalObject_callMethod_templates.hxx b/simgear/nasal/cppbind/detail/NasalObject_callMethod_templates.hxx deleted file mode 100644 index 41dd9fd4..00000000 --- a/simgear/nasal/cppbind/detail/NasalObject_callMethod_templates.hxx +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef SG_NASAL_OBJECT_HXX_ -# error Nasal cppbind - do not include this file! -#endif - -#ifndef SG_DONT_DO_ANYTHING -#define n BOOST_PP_ITERATION() - -#define SG_CALL_ARG(z, n, dummy)\ - to_nasal::param_type>(ctx, a##n) - - template< - class Ret - BOOST_PP_ENUM_TRAILING_PARAMS(n, class A) - > - Ret callMethod( const std::string& name - BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(n, A, a) ) - { - if( !_nasal_impl.valid() ) - return Ret(); - - typedef boost::function - MemFunc; - - Context ctx; - MemFunc f = get_member(ctx, _nasal_impl.get_naRef(), name.c_str()); - if( f ) - return f(nasal::to_nasal(ctx, this) BOOST_PP_ENUM_TRAILING_PARAMS(n, a)); - - return Ret(); - } - -#undef SG_CALL_ARG - -#undef n -#endif // SG_DONT_DO_ANYTHING