]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/string-handle.hh
* flower
[lilypond.git] / flower / include / string-handle.hh
1 /*
2   string-handle.hh -- declare String_handle
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #ifndef STRINGHANDLE_HH
10 #define STRINGHANDLE_HH
11
12 #include "flower-proto.hh"
13
14 /**
15    Reference counting for strings.
16
17    handles ref. counting, and provides a very thin interface using
18    Byte *
19 */
20 class String_handle
21 {
22   String_data *data;
23
24   /// decrease ref count. Named kind of like a Tanenbaum semafore 
25   void down ();
26
27   void up (String_data *d);
28
29   /** make sure data has only one reference.
30       POST: data->ref_count_ == 1
31   */
32   void copy ();
33
34 public:
35   String_handle ();
36   ~String_handle ();
37   String_handle (String_handle const &src);
38
39   Byte const *to_bytes () const;
40   char const *to_str0 () const;
41   Byte *get_bytes ();
42   char *get_str0 ();
43   bool is_binary_bo () const;
44   void operator= (String_handle const &src);
45   void operator+= (char const *s);
46   Byte operator[] (int j) const;
47
48   /** Access elements. WARNING: NOT SAFE
49       don't use this for loops. Use to_bytes ()
50   */
51   Byte &operator[] (int j);
52   void append (Byte const *byte, int length_i);
53   void set (Byte const *byte, int length_i);
54   void operator= (char const *p);
55   void trunc (int j);
56   int length () const;
57 };
58
59 #ifdef STRING_UTILS_INLINED
60 #ifndef INLINE
61 #define INLINE inline
62 #endif
63 #include "string-handle.icc"
64 /* we should be resetting INLINE. oh well. */
65 #endif
66
67 #endif // STRINGHANDLE_HH