]> git.donarmstrong.com Git - lilypond.git/blob - lily/function-documentation.cc
Issue 4550 (2/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / function-documentation.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
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 #include <cstring>
21 #include <map>
22
23 #include "std-string.hh"
24 #include "lily-guile.hh"
25 #include "warn.hh"
26
27 /* type predicates. */
28 #include "global-context.hh"
29 #include "input.hh"
30 #include "item.hh"
31 #include "music.hh"
32 #include "music-function.hh"
33 #include "paper-score.hh"
34 #include "performance.hh"
35 #include "spanner.hh"
36 #include "stream-event.hh"
37 #include "unpure-pure-container.hh"
38
39 using std::map;
40 using std::string;
41
42 static SCM doc_hash_table;
43
44 void
45 ly_check_name (const string &cxx, const string &scm_name)
46 {
47   string mangle = mangle_cxx_identifier (cxx);
48   if (mangle != scm_name)
49     {
50       programming_error ("wrong cxx name: " + mangle + ", " + cxx + ", " + scm_name);
51     }
52 }
53
54 void
55 ly_add_function_documentation (SCM func,
56                                const string &fname,
57                                const string &varlist,
58                                const string &doc)
59 {
60   if (doc == "")
61     return;
62
63   if (!doc_hash_table)
64     doc_hash_table = scm_permanent_object (scm_c_make_hash_table (59));
65
66   string s = string (" - ") + "LilyPond procedure: " + fname + " " + varlist
67              + "\n" + doc;
68
69   scm_set_procedure_property_x (func, ly_symbol2scm ("documentation"),
70                                 ly_string2scm (s));
71   SCM entry = scm_cons (ly_string2scm (varlist), ly_string2scm (doc));
72   scm_hashq_set_x (doc_hash_table, ly_symbol2scm (fname.c_str ()), entry);
73 }
74
75 LY_DEFINE (ly_get_all_function_documentation, "ly:get-all-function-documentation",
76            0, 0, 0, (),
77            "Get a hash table with all LilyPond Scheme extension functions.")
78 {
79   return doc_hash_table;
80 }
81
82 map<void *, string> type_names;
83
84 void
85 ly_add_type_predicate (void *ptr,
86                        const string &name)
87 {
88   type_names[ptr] = name;
89 }
90
91 string
92 predicate_to_typename (void *ptr)
93 {
94   if (type_names.find (ptr) == type_names.end ())
95     {
96       programming_error ("Unknown type predicate");
97       return "unknown type";
98     }
99   else
100     return type_names[ptr];
101 }
102
103 void
104 init_func_doc ()
105 {
106   ly_add_type_predicate ((void *) &is_direction, "direction");
107   ly_add_type_predicate ((void *) &ly_is_port, "port");
108   ly_add_type_predicate ((void *) &ly_cheap_is_list, "list");
109   ly_add_type_predicate ((void *) &unsmob<Global_context>, "Global_context");
110   ly_add_type_predicate ((void *) &unsmob<Paper_score>, "Paper_score");
111   ly_add_type_predicate ((void *) &unsmob<Performance>, "Performance");
112   ly_add_type_predicate ((void *) &is_axis, "axis");
113   ly_add_type_predicate ((void *) &is_number_pair, "number pair");
114   ly_add_type_predicate ((void *) &ly_is_list, "list");
115   ly_add_type_predicate ((void *) &ly_is_procedure, "procedure");
116   ly_add_type_predicate ((void *) &ly_is_symbol, "symbol");
117   ly_add_type_predicate ((void *) &scm_is_bool, "boolean");
118   ly_add_type_predicate ((void *) &scm_is_integer, "integer");
119   ly_add_type_predicate ((void *) &scm_is_number, "number");
120   ly_add_type_predicate ((void *) &scm_is_pair, "pair");
121   ly_add_type_predicate ((void *) &scm_is_rational, "rational");
122   ly_add_type_predicate ((void *) &scm_is_string, "string");
123   ly_add_type_predicate ((void *) &scm_is_vector, "vector");
124   ly_add_type_predicate ((void *) &unsmob<Item>, "Item");
125   ly_add_type_predicate ((void *) &unsmob<Music>, "Music");
126   ly_add_type_predicate ((void *) &unsmob<Spanner>, "Spanner");
127   ly_add_type_predicate ((void *) &unsmob<Stream_event>, "Stream_event");
128 }
129
130 ADD_SCM_INIT_FUNC (func_doc, init_func_doc);