]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/object-key.hh
755b72f1228b8ad5c8d35f06572eed2a4f3ee96f
[lilypond.git] / lily / include / object-key.hh
1 /*
2   object-key.hh -- declare Object_key
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #ifndef OBJECT_KEY_HH
11 #define OBJECT_KEY_HH
12
13 #include "smobs.hh"
14
15 /*
16   Object_keys are read-only values, suitable for storing references to
17   transient objects (such as grobs or contexts) on disk.
18
19   In the future, they might also act as handles for external processes
20   requesting notation to be drawn.
21  */
22 class Object_key
23 {
24   DECLARE_SMOBS(Object_key, );
25
26 protected:
27   Object_key();
28   virtual void derived_mark () const;
29   virtual int get_type () const;
30   virtual int do_compare (Object_key const * other) const;
31   virtual SCM as_scheme () const;
32 public:
33   static Object_key *from_scheme (SCM);
34   static Object_key *undump (SCM);
35   int compare (Object_key const *other) const;
36   SCM dump () const;
37 };
38
39 enum Object_key_type {
40   BASE_KEY,
41   COPIED_KEY,
42   GENERAL_KEY, 
43   GROB_KEY,
44   CONTEXT_KEY,
45   KEY_COUNT,
46 };
47
48 class Copied_key : public Object_key
49 {
50
51 private:
52   Object_key const * original_;
53   int copy_count_;
54
55 protected:
56   virtual void derived_mark () const;
57   virtual int get_type () const;
58   virtual int do_compare (Object_key const * other) const;
59   virtual SCM as_scheme () const;
60 public:
61   static Object_key *from_scheme (SCM);
62   Copied_key (Object_key const*, int); 
63 };
64
65 DECLARE_UNSMOB(Object_key, key);
66
67 struct Object_key_less {
68   bool operator () (Object_key const *const &t1, Object_key const *const &t2) const
69   {
70     return t1->compare (t2);
71   }
72 };
73
74
75 #endif /* OBJECT_KEY_HH */