]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/string-handle.icc
* lily/melisma-engraver.cc (try_music): use melisma_busy()
[lilypond.git] / flower / include / string-handle.icc
1 /* -*-c++-*-
2    
3   stringhandle.inl -- implement String_handle
4
5   source file of Flower lib
6
7   (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9
10 #ifndef STRINGHANDLE_INL
11 #define STRINGHANDLE_INL
12
13 #include <assert.h>
14 #include <memory.h>
15
16 #include "string-data.hh"
17 #include "string-handle.hh"
18
19 INLINE void 
20 String_handle::down () 
21
22   if (! (--data->ref_count_))
23     delete data;
24   data = 0; 
25 }
26
27 /*
28   increase ref count
29
30   THIS does not have to be initialized.
31 */
32 INLINE void 
33 String_handle::up (String_data *d) 
34
35   data=d;
36   data->ref_count_ ++; 
37 }
38
39 INLINE void 
40 String_handle::copy () 
41 {
42   if (data->ref_count_ !=1)
43     {
44       String_data *newdata = new String_data (*data);
45       down ();
46       up (newdata);
47     }
48 }
49
50 INLINE
51 String_handle::String_handle () 
52 {
53   up (new String_data);
54 }
55
56 INLINE
57 String_handle::~String_handle () 
58 {       
59   down ();
60 }    
61
62 INLINE
63 String_handle::String_handle (String_handle const & src) 
64 {       
65   up (src.data);
66 }
67
68 INLINE Byte* 
69 String_handle::get_bytes () 
70 {
71   copy ();
72   return data->get_bytes ();
73 }
74
75 INLINE char* 
76 String_handle::get_str0 () 
77 {
78   copy ();
79   return (char*)data->get_bytes ();
80 }
81
82 INLINE Byte 
83 const* String_handle::to_bytes () const 
84 {
85   return data->to_bytes ();
86 }
87
88 INLINE char const* 
89 String_handle::to_str0 () const 
90 {
91   return (char const*)data->to_bytes ();
92 }
93
94 INLINE void 
95 String_handle::operator = (String_handle const &src) 
96 {
97   if (this == &src)
98     return;
99   down ();
100   up (src.data);
101 }
102
103 INLINE void 
104 String_handle::operator += (char const *s) 
105 {       
106   copy ();
107   *data += s;
108 }    
109
110
111 INLINE Byte 
112 String_handle::operator[] (int j) const 
113
114   return (*data)[j]; 
115 }
116
117 // !NOT SAFE!
118 // don't use this for loops. Use to_bytes ()
119 INLINE Byte &
120 String_handle::operator[] (int j) 
121 {
122   copy ();      // hmm. Not efficient
123   return data->get_bytes ()[j];
124 }
125
126 INLINE void 
127 String_handle::append (Byte const* byte, int length_i) 
128 {
129   copy ();
130   data->append (byte, length_i);
131 }
132                            
133 INLINE void 
134 String_handle::set (Byte const* byte, int length_i) 
135 {
136   copy ();
137   data->set (byte, length_i);
138 }
139                            
140 INLINE void 
141 String_handle::operator = (char const *p) 
142 {
143   copy ();
144   data->set (p);
145 }
146                            
147 INLINE void 
148 String_handle::trunc (int j) 
149 {
150   copy (); data->trunc (j); 
151 }
152
153 INLINE int 
154 String_handle::length () const 
155
156   return data->length_; 
157 }
158
159 INLINE bool
160 String_handle::is_binary_bo () const {
161   return data->is_binary_bo ();
162 }
163
164 #endif