nasal::Object: Simplify with C++11

C++11 variadic templates finally allow us to get rid of the
ugly boost preprocessor workaround.
This commit is contained in:
Thomas Geymayer
2017-11-15 19:31:29 +01:00
parent b766ce76ff
commit 4f63c3f8a8
3 changed files with 14 additions and 46 deletions

View File

@@ -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
)

View File

@@ -23,9 +23,6 @@
#include "NasalObjectHolder.hxx"
#include "Ghost.hxx"
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
namespace nasal
{
/**
@@ -48,14 +45,21 @@ namespace nasal
bool valid() const;
// Build dependency for CMake, gcc, etc.
#define SG_DONT_DO_ANYTHING
# include <simgear/nasal/cppbind/detail/NasalObject_callMethod_templates.hxx>
#undef SG_DONT_DO_ANYTHING
template<class Ret, class ... Args>
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 <simgear/nasal/cppbind/detail/NasalObject_callMethod_templates.hxx>
#include BOOST_PP_ITERATE()
Context ctx;
auto func = get_member<boost::function<Ret (nasal::Me, Args...)>>(
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);

View File

@@ -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<typename boost::call_traits<A##n>::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<Ret (nasal::Me BOOST_PP_ENUM_TRAILING_PARAMS(n, A))>
MemFunc;
Context ctx;
MemFunc f = get_member<MemFunc>(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