]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/lily-modules.hh
Issue 5167/6: Changes: show \markup xxx = ... \etc assignments
[lilypond.git] / lily / include / lily-modules.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2015 by David Kastrup <dak@gnu.org>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef LILY_MODULES_HH
21 #define LILY_MODULES_HH
22
23 #include "lily-guile.hh"
24
25 class Scm_variable;
26
27 class Scm_module
28 {
29   const char *name_;
30   SCM module_;
31   class Variable_record;
32   Variable_record *variables_;
33   static void boot_init (void *);
34 public:
35   void boot (void (*init)() = 0);
36   void import ();
37   void register_variable (const char *name, Scm_variable *var);
38
39   Scm_module (const char *name);
40
41   operator SCM ()
42   {
43     assert (SCM_MODULEP (module_));
44     return module_;
45   }
46 };
47
48 class Scm_variable
49 {
50   SCM var_;
51   friend Scm_module;
52   void boot (const char *name);
53   void import (SCM module, const char *name);
54 public:
55   operator SCM & ()
56   {
57 #if 0
58     // One could conceivably work with variables even before the
59     // module is initialized
60     return SCM_VARIABLEP (var_) ? *SCM_VARIABLE_LOC (var_) : var_;
61 #endif
62 #if DEBUG
63     assert (SCM_VARIABLEP (var_));
64 #endif
65     return *SCM_VARIABLE_LOC (var_);
66   }
67   SCM operator () ()
68   {
69     return scm_call_0 (*this);
70   }
71   SCM operator () (SCM arg1)
72   {
73     return scm_call_1 (*this, arg1);
74   }
75   SCM operator () (SCM arg1, SCM arg2)
76   {
77     return scm_call_2 (*this, arg1, arg2);
78   }
79   SCM operator () (SCM arg1, SCM arg2, SCM arg3)
80   {
81     return scm_call_3 (*this, arg1, arg2, arg3);
82   }
83   SCM operator () (SCM arg1, SCM arg2, SCM arg3, SCM arg4)
84   {
85     return scm_call_4 (*this, arg1, arg2, arg3, arg4);
86   }
87   Scm_variable (Scm_module &m, const char *name, SCM value = SCM_UNDEFINED);
88 };
89
90 template <Scm_module &m>
91 class Module_variable : public Scm_variable
92 {
93 public:
94   Module_variable (const char *name, SCM value = SCM_UNDEFINED)
95     : Scm_variable (m, name, value)
96   { }
97 };
98
99 #endif