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