/* -*- C++ -*-
This file is part of LilyPond, the GNU music typesetter.
- Copyright (C) 2005--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
LilyPond is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
// included from smobs.hh, but other template expansion systems might
// make it feasible to compile this only a single time.
-#include "lily-guile-macros.hh"
-#include "smobs.hh"
#include <typeinfo>
+template <class Super>
+SCM
+Smob_base<Super>::mark_trampoline (SCM arg)
+{
+ Super *ptr = unsmob<Super> (arg);
+ if (ptr)
+ return ptr->mark_smob ();
+ return SCM_UNDEFINED;
+}
+
+template <class Super>
+int
+Smob_base<Super>::print_trampoline (SCM arg, SCM port, scm_print_state *p)
+{
+ Super *ptr = unsmob<Super> (arg);
+ if (ptr)
+ return ptr->print_smob (port, p);
+ return 0;
+}
+
template <class Super>
SCM
Smob_base<Super>::register_ptr (Super *p)
return s;
}
+// Defaults, should not actually get called
+template <class Super>
+SCM
+Smob_base<Super>::mark_smob () const
+{
+ return SCM_UNSPECIFIED;
+}
+
+template <class Super>
+size_t
+Smob_base<Super>::free_smob (SCM)
+{
+ return 0;
+}
+
+template <class Super>
+SCM
+Smob_base<Super>::equal_p (SCM, SCM)
+{
+ return SCM_BOOL_F;
+}
+
+// Default, will often get called
+
template <class Super>
int
-Smob_base<Super>::print_smob (SCM, SCM p, scm_print_state *)
+Smob_base<Super>::print_smob (SCM p, scm_print_state *) const
{
scm_puts ("#<", p);
scm_puts (smob_name_.c_str (), p);
{
Super *p = Super::unchecked_unsmob (obj);
scm_gc_unregister_collectable_memory (p, sizeof (*p), smob_name_.c_str ());
+ SCM_SET_SMOB_DATA (obj, static_cast<Super *> (0));
return p;
}
scm_t_bits Smob_base<Super>::smob_tag_ = 0;
template <class Super>
-Scm_init Smob_base<Super>::scm_init_ = init;
+Scm_init Smob_base<Super>::scm_init_ (init);
template <class Super>
string Smob_base<Super>::smob_name_;
+template <class Super>
+const char * const Smob_base<Super>::type_p_name_ = 0;
+
template <class Super>
void Smob_base<Super>::init ()
{
// While that's not a consideration for type_p_name_, it's easier
// doing it like the rest.
- if (Super::free_smob != 0)
+ if (&Super::free_smob != &Smob_base<Super>::free_smob)
scm_set_smob_free (smob_tag_, Super::free_smob);
- if (Super::mark_smob != 0)
- scm_set_smob_mark (smob_tag_, Super::mark_smob);
- if (Super::print_smob != 0)
- scm_set_smob_print (smob_tag_, Super::print_smob);
- if (Super::equal_p != 0)
+ if (&Super::mark_smob != &Smob_base<Super>::mark_smob)
+ scm_set_smob_mark (smob_tag_, Super::mark_trampoline);
+ scm_set_smob_print (smob_tag_, Super::print_trampoline);
+ if (&Super::equal_p != &Smob_base<Super>::equal_p)
scm_set_smob_equalp (smob_tag_, Super::equal_p);
if (Super::type_p_name_ != 0)
{
fundoc);
scm_c_export (Super::type_p_name_, NULL);
}
- ly_add_type_predicate ((void *) unsmob, smob_name_.c_str ());
+ ly_add_type_predicate ((void *) is_smob, smob_name_.c_str ());
+ Super::smob_proc_init (smob_tag_);
}
-
#endif