[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/5] Add Callback0_wrapper and Callback2_wrapper class
From: |
David Kastrup |
Subject: |
[PATCH 2/5] Add Callback0_wrapper and Callback2_wrapper class |
Date: |
Tue, 3 May 2016 00:58:29 +0200 |
Those are for callbacks with 0 and 2 SCM arguments, respectively. The
former are needed mainly for translator callbacks, the second for
acknowledgers.
---
lily/callback.cc | 2 ++
lily/include/callback.hh | 81 +++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 82 insertions(+), 1 deletion(-)
diff --git a/lily/callback.cc b/lily/callback.cc
index 5310295..fac40a0 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 b797baf..7151d04 100644
--- a/lily/include/callback.hh
+++ b/lily/include/callback.hh
@@ -44,7 +44,8 @@ class Callback_wrapper : public Simple_smob<Callback_wrapper>
// 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<Callback2_wrapper>
+{
+ // 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 <SCM (*trampoline) (SCM, SCM, SCM)>
+ static SCM make_smob ()
+ {
+ static SCM res =
+ scm_permanent_object (Callback2_wrapper (trampoline).smobbed_copy ());
+ return res;
+ }
+};
+
+class Callback0_wrapper : public Simple_smob<Callback0_wrapper>
+{
+ // 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 <SCM (*trampoline) (SCM)>
+ 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 <class T, SCM (T::*p)()>
+ static SCM trampoline (SCM target)
+ {
+ T *t = LY_ASSERT_SMOB (T, target, 1);
+ return (t->*p) ();
+ }
+
+ template <class T, void (T::*p)()>
+ static SCM trampoline (SCM target)
+ {
+ T *t = LY_ASSERT_SMOB (T, target, 1);
+ (t->*p) ();
+ return SCM_UNSPECIFIED;
+ }
+
+ template <class T, SCM (T::*p)()>
+ static SCM make_smob ()
+ {
+ return make_smob<trampoline<T, p> > ();
+ }
+
+ template <class T, void (T::*p)()>
+ static SCM make_smob ()
+ {
+ return make_smob<trampoline<T, p> > ();
+ }
+};
#endif
--
2.7.4
- Moving a number of C++ constructs to SCM, David Kastrup, 2016/05/02
- [PATCH 3/5] Add Method_instance class, David Kastrup, 2016/05/02
- [PATCH 1/5] Issue 4840: Make Translator/Performer/Engraver abstract base classes, David Kastrup, 2016/05/02
- [PATCH 4/5] Replace Engraver_dispatch_entry with Method_instance, David Kastrup, 2016/05/02
- [PATCH 2/5] Add Callback0_wrapper and Callback2_wrapper class,
David Kastrup <=
- [PATCH 5/5] Replace Translator_method et al, David Kastrup, 2016/05/02
- Re: Moving a number of C++ constructs to SCM, David Kastrup, 2016/05/03
- Re: Moving a number of C++ constructs to SCM, James Lowe, 2016/05/04