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