]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/translator.hh
release: 1.1.6
[lilypond.git] / lily / include / translator.hh
1 /*
2   translator.hh -- declare Translator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #ifndef TRANSLATOR_HH
11 #define TRANSLATOR_HH
12
13 #include "string.hh"
14 #include "lily-proto.hh"
15 #include "virtual-methods.hh"
16 #include "scalar.hh"
17 #include "dictionary.hh"
18 #include "parray.hh"
19 #include "input.hh"
20
21
22 /** Make some kind of #Element#s from Requests. Elements are made by
23   hierarchically grouped #Translator#s
24   */
25 class Translator : public Input {
26   Dictionary<Scalar> properties_dict_;
27 public:
28   Music_output_def * output_def_l_;
29   String  type_str_;
30
31   bool is_alias_b (String) const;
32   
33
34     
35   VIRTUAL_COPY_CONS(Translator);
36   Translator (Translator const &);
37   Translator ();
38   virtual ~Translator ();
39   
40   Translator_group * daddy_trans_l_ ;
41  
42   void print () const;
43   
44   /**
45     try to fit the request in this engraver
46
47     @return
48     false: not noted,  not taken.
49
50     true: request swallowed. Don't try to put the request elsewhere.
51
52     */
53   bool try_music (Music*);
54   void pre_move_processing();
55   void add_processing ();
56   void creation_processing ();
57   void process_requests();
58   void post_move_processing();
59   void removal_processing();
60   /**
61     ask daddy for a feature
62     */
63   Scalar get_property (String type_str);
64   void set_property (String var_name, Scalar value);
65   Music_output_def *output_def_l () const;
66   
67   virtual Moment now_moment () const;  
68
69 protected:
70    enum { 
71     ORPHAN,
72     VIRGIN,
73     CREATION_INITED,
74     MOVE_INITED,
75     ACCEPTED_REQS,
76     PROCESSED_REQS,
77     ACKED_REQS,
78     MOVE_DONE
79   } status;
80
81   /*    
82         @see{try_request}
83         Default: always return false
84         */
85   virtual void do_add_processing ();
86   virtual bool do_try_music (Music *req_l);
87   virtual void do_print () const;
88   virtual void do_pre_move_processing(){}
89   virtual void do_post_move_processing(){}
90   virtual void do_process_requests () {}
91   virtual void do_creation_processing() {}
92   virtual void do_removal_processing() {}
93 };
94
95
96 template<class T>
97 class Translator_adder
98 {
99 public:
100   static Translator *ctor ()
101     {
102       T *t = new T;
103       t->type_str_ = classname (t);
104       return t;
105     }
106   Translator_adder () { 
107     add_constructor (ctor);
108   }                             
109 };
110
111 /**
112   A macro to automate administration of translators.
113  */
114 #define ADD_THIS_TRANSLATOR(c)                          \
115   Translator_adder<c> _ ## c ## init;
116
117 typedef Translator *(*Translator_ctor) ();
118
119 extern Dictionary<Translator*> *global_translator_dict_p;
120 void add_translator (Translator*trans_p);
121 void add_constructor (Translator_ctor ctor);
122
123 Translator*get_translator_l (String s);
124
125 #endif // TRANSLATOR_HH