]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/smobs.hh
release: 1.3.1
[lilypond.git] / lily / include / smobs.hh
1 /*   
2   smobs.hh -- declare smob related stuff.
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #ifndef SMOBS_HH
11 #define SMOBS_HH
12
13 #include "lily-guile.hh"
14
15 /**
16    A smob is a C++ class with static member functions to glue it with
17    Scheme. Every instance carries SELF_SCM_, a pointer to the Scheme
18    smob of itself.  Upon destruction, SELF_SCM_ is set to SCM_EOL.
19
20    smob_free() checks if SELF_SCM_ equals its argument, so we can also
21    use a smobbified object on the stack: the destruction will happen
22    before GC hits the object.
23
24    This is discouraged, though, because it causes memory leaks, and has
25    weird semantics.
26    
27
28 */
29
30 #define DECLARE_SMOBS                                   \
31         SCM smobify_self ();                                    \
32         static SCM mark_smob (SCM);                             \
33         static scm_sizet free_smob (SCM s);                     \
34         static int print_smob (SCM s, SCM p, scm_print_state*); \
35         static long smob_tag_;                                  \
36         static SCM equal_p (SCM a, SCM b);\
37         static void init_smobs();                               \
38         void unsmobify_self ();\
39         void do_smobify_self();\
40         SCM self_scm_;
41
42
43 /**
44    Check if S is of the specified C++ class.
45  */
46 #define SMOB_IS_TYPE_B(TYPE, S)  (SCM_NIMP((S)) && SCM_CAR((S)) == TYPE::smob_tag_)
47
48 /// Cast S.  No checks are done.
49 #define SMOB_TO_TYPE(TYPE, S)  ((TYPE*) SCM_CDR((S)))
50 #endif /* SMOBS_HH */
51