/*
This file is part of LilyPond, the GNU music typesetter.
- Copyright (C) 1999--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ Copyright (C) 1999--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
// class) to make sure the variable is actually instantiated.
class Scm_init {
+ static const Scm_init * list_;
+ void (*const fun_)(void);
+ Scm_init const * const next_;
+ Scm_init (); // don't use default constructor, don't define
+ Scm_init (const Scm_init &); // don't define copy constructor
public:
- Scm_init () { }
- Scm_init (void (*fun) (void))
- {
- add_scm_init_func (fun);
- }
+ Scm_init (void (*fun) (void)) : fun_ (fun), next_ (list_)
+ { list_ = this; }
+ static void init ();
};
template <class Super>
}
};
+// derived_unsmob includes a dynamic_cast:
+
+template <class T>
+inline T *derived_unsmob (SCM arg)
+{
+ return dynamic_cast<T *> (T::unsmob (arg));
+}
+
// Simple smobs
template <class Super>
class Simple_smob : public Smob_base<Super> {
}
SCM unprotected_smobify_self ()
{
- self_scm_ = Smob_base<Super>::register_ptr (static_cast<Super *> (this));
- return self_scm_;
+ SCM s = Smob_base<Super>::register_ptr (static_cast<Super *> (this));
+ self_scm_ = s;
+ return s;
}
void protect ()
{
protect_smob (self_scm_, &protection_cons_);
}
+ void smobify_self () {
+ protect_smob (unprotected_smobify_self (), &protection_cons_);
+ }
SCM unprotect ()
{
- unprotect_smob (self_scm_, &protection_cons_);
- return self_scm_;
- }
- void smobify_self () {
- self_scm_ = unprotected_smobify_self ();
- protect ();
+ SCM s = self_scm_;
+ unprotect_smob (s, &protection_cons_);
+ return s;
}
SCM self_scm () const { return self_scm_; }
};