]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/include/smobs.tcc
Issue 4550 (2/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / include / smobs.tcc
index c0a62535f5e4f830200c8b4a249ae955032d414f..dd815e59db2fea6cf6582f6895db6a25049b2f3c 100644 (file)
 // 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)
 {
-  return (Super::unsmob (arg))->mark_smob ();
+  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)
 {
-  return (Super::unsmob (arg))->print_smob (port, p);
+  Super *ptr = unsmob<Super> (arg);
+  if (ptr)
+    return ptr->print_smob (port, p);
+  return 0;
 }
 
 template <class Super>
@@ -59,7 +63,7 @@ Smob_base<Super>::register_ptr (Super *p)
 // Defaults, should not actually get called
 template <class Super>
 SCM
-Smob_base<Super>::mark_smob ()
+Smob_base<Super>::mark_smob () const
 {
   return SCM_UNSPECIFIED;
 }
@@ -82,7 +86,7 @@ Smob_base<Super>::equal_p (SCM, SCM)
 
 template <class Super>
 int
-Smob_base<Super>::print_smob (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);
@@ -96,6 +100,7 @@ Smob_base<Super>::unregister_ptr (SCM obj)
 {
   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;
 }
 
@@ -103,10 +108,10 @@ template <class Super>
 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_;
+std::string Smob_base<Super>::smob_name_;
 
 template <class Super>
 void Smob_base<Super>::init ()
@@ -128,13 +133,7 @@ void Smob_base<Super>::init ()
 
   if (&Super::free_smob != &Smob_base<Super>::free_smob)
     scm_set_smob_free (smob_tag_, Super::free_smob);
-  // Old GCC versions get their type lattice for pointers-to-members
-  // tangled up to a degree where we need to typecast _both_ covariant
-  // types in order to be able to compare them.  The other comparisons
-  // are for static member functions and thus are ordinary function
-  // pointers which work without those contortions.
-  if (static_cast<SCM (Super::*)()>(&Super::mark_smob) !=
-      static_cast<SCM (Super::*)()>(&Smob_base<Super>::mark_smob))
+  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)
@@ -143,18 +142,13 @@ void Smob_base<Super>::init ()
     {
       SCM subr = scm_c_define_gsubr (Super::type_p_name_, 1, 0, 0,
                                      (scm_t_subr) smob_p);
-      string fundoc = string("Is @var{x} a @code{") + smob_name_
+      std::string fundoc = std::string("Is @var{x} a @code{") + smob_name_
         + "} object?";
       ly_add_function_documentation (subr, Super::type_p_name_, "(SCM x)",
                                      fundoc);
       scm_c_export (Super::type_p_name_, NULL);
     }
   ly_add_type_predicate ((void *) is_smob, smob_name_.c_str ());
-  if (Super::smob_proc_signature_ >= 0)
-    scm_set_smob_apply (smob_tag_,
-                        (scm_t_subr)Super::smob_proc,
-                        Super::smob_proc_signature_ >> 8,
-                        (Super::smob_proc_signature_ >> 4)&0xf,
-                        Super::smob_proc_signature_ & 0xf);
+  Super::smob_proc_init (smob_tag_);
 }
 #endif