]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/string-handle.hh
*** empty log message ***
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #ifndef STRINGHANDLE_HH
10 #define STRINGHANDLE_HH
11
12 #include "flower-proto.hh"
13
14 namespace std {
15 /**
16    Reference counting for strings.
17
18    handles ref. counting, and provides a very thin interface using
19    Byte *
20 */
21 class String_handle
22 {
23   String_data *data;
24
25   /// decrease ref count. Named kind of like a Tanenbaum semafore 
26   void down ();
27
28   void up (String_data *d);
29
30   /** make sure data has only one reference.
31       POST: data->ref_count_ == 1
32   */
33   void copy ();
34
35 public:
36   String_handle ();
37   ~String_handle ();
38   String_handle (String_handle const &src);
39
40   Byte const *to_bytes () const;
41   char const *c_str () const;
42   Byte *get_bytes ();
43   char *get_c_str ();
44   bool is_binary_bo () const;
45   void operator = (String_handle const &src);
46   void operator += (char const *s);
47   Byte operator [] (int j) const;
48
49   /** Access elements. WARNING: NOT SAFE
50       don't use this for loops. Use to_bytes ()
51   */
52   Byte &operator [] (int j);
53   void append (Byte const *byte, int length_i);
54   void set (Byte const *byte, int length_i);
55   void operator = (char const *p);
56   void trunc (int j);
57   int length () const;
58 };
59
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 #endif // STRINGHANDLE_HH