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