From: David Kastrup Date: Wed, 27 Apr 2016 20:59:20 +0000 (+0200) Subject: Issue 4842/1: Add Callback0_wrapper and Callback2_wrapper class X-Git-Tag: release/2.19.42-1~15 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=60f6cf0a5769ef2c9dc48aefa0abfa1e243445e7;p=lilypond.git Issue 4842/1: Add Callback0_wrapper and Callback2_wrapper class Those are for callbacks with 0 and 2 SCM arguments, respectively. The former are needed mainly for translator callbacks, the second for acknowledgers. --- diff --git a/lily/callback.cc b/lily/callback.cc index 531029543b..fac40a02de 100644 --- a/lily/callback.cc +++ b/lily/callback.cc @@ -20,3 +20,5 @@ #include "callback.hh" const char * const Callback_wrapper::type_p_name_ = 0; +const char * const Callback2_wrapper::type_p_name_ = 0; +const char * const Callback0_wrapper::type_p_name_ = 0; diff --git a/lily/include/callback.hh b/lily/include/callback.hh index b797baf062..7151d04478 100644 --- a/lily/include/callback.hh +++ b/lily/include/callback.hh @@ -44,7 +44,8 @@ class Callback_wrapper : public Simple_smob // this involves an adjustment of the this pointer from Smob_core to // the scope containing the callback. SCM (*trampoline_) (SCM, SCM); - Callback_wrapper (SCM (*trampoline) (SCM, SCM)) : trampoline_ (trampoline) + Callback_wrapper (SCM (*trampoline) (SCM, SCM)) + : trampoline_ (trampoline) { } // Private constructor, use only in make_smob public: static const char * const type_p_name_; // = 0 @@ -66,5 +67,83 @@ public: } }; +class Callback2_wrapper : public Simple_smob +{ + // See Callback_wrapper for the details. Callback2_wrapper just + // supports an additional SCM argument as compared to + // Callback_wrapper but is otherwise identical. + SCM (*trampoline_) (SCM, SCM, SCM); + Callback2_wrapper (SCM (*trampoline) (SCM, SCM, SCM)) + : trampoline_ (trampoline) + { } // Private constructor, use only in make_smob +public: + static const char * const type_p_name_; // = 0 + LY_DECLARE_SMOB_PROC (&Callback2_wrapper::call, 3, 0, 0) + SCM call (SCM target, SCM arg1, SCM arg2) + { + return trampoline_ (target, arg1, arg2); + } + + template + static SCM make_smob () + { + static SCM res = + scm_permanent_object (Callback2_wrapper (trampoline).smobbed_copy ()); + return res; + } +}; + +class Callback0_wrapper : public Simple_smob +{ + // See Callback_wrapper for the details. Callback0_wrapper does not + // pass arguments but is otherwise identical to Callback_wrapper. + SCM (*trampoline_) (SCM); + Callback0_wrapper (SCM (*trampoline) (SCM)) + : trampoline_ (trampoline) + { } // Private constructor, use only in make_smob +public: + static const char * const type_p_name_; // = 0 + LY_DECLARE_SMOB_PROC (&Callback0_wrapper::call, 1, 0, 0) + SCM call (SCM target) + { + return trampoline_ (target); + } + + template + static SCM make_smob () + { + static SCM res = + scm_permanent_object (Callback0_wrapper (trampoline).smobbed_copy ()); + return res; + } + // Since there are no arguments at all, we might as well provide + // default trampolines + template + static SCM trampoline (SCM target) + { + T *t = LY_ASSERT_SMOB (T, target, 1); + return (t->*p) (); + } + + template + static SCM trampoline (SCM target) + { + T *t = LY_ASSERT_SMOB (T, target, 1); + (t->*p) (); + return SCM_UNSPECIFIED; + } + + template + static SCM make_smob () + { + return make_smob > (); + } + + template + static SCM make_smob () + { + return make_smob > (); + } +}; #endif