lilypond-1.5.8
[lilypond.git] / flower / stringhandle.inl
blobbc84cd868bfd025ec6a1493af238f0074d257d9a
1 /* -*-c++-*-
2    
3   stringhandle.inl -- implement String_handle
5   source file of Flower lib
7   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
8 */
10 #ifndef STRINGHANDLE_INL
11 #define STRINGHANDLE_INL
13 #include <assert.h>
14 #include <memory.h>
16 #include "stringdata.hh"
17 #include "stringhandle.hh"
19 INLINE void 
20 String_handle::down() 
21
22     if (!(--data->references)) delete data; data = 0; 
25 /// increase ref count
26 INLINE void 
27 String_handle::up(String_data *d) 
28
29     data=d; data->references ++; 
32 INLINE void 
33 String_handle::copy() 
35     if (data->references !=1){
36         String_data *newdata = new String_data(*data);
37         down();
38         up(newdata);
39     }
42 INLINE
43 String_handle::String_handle() 
45     up(new String_data);
48 INLINE
49 String_handle::~String_handle() 
50 {       
51     down();
52 }    
54 INLINE
55 String_handle::String_handle(String_handle const & src) 
56 {       
57     up(src.data);
60 INLINE Byte* 
61 String_handle::byte_l() 
63     copy();
64     return data->byte_l();
67 INLINE char* 
68 String_handle::ch_l() 
70     copy();
71     return (char*)data->byte_l();
74 INLINE Byte 
75 const* String_handle::byte_c_l() const 
77     return data->byte_c_l();
80 INLINE char const* 
81 String_handle::ch_c_l() const 
83     return (char const*)data->byte_c_l();
86 INLINE void 
87 String_handle::operator =(String_handle const &src) 
89     if (this == &src)
90         return;
91     down();
92     up(src.data);
95 INLINE void 
96 String_handle::operator += (char const *s) 
97 {       
98     copy();
99     *data += s;
100 }    
103 INLINE Byte 
104 String_handle::operator[](int j) const 
106     return (*data)[j]; 
109 // !NOT SAFE!
110 // don't use this for loops. Use byte_c_l()
111 INLINE Byte &
112 String_handle::operator[](int j) 
114     copy();     // hmm. Not efficient
115     return data->byte_l()[j];
118 INLINE void 
119 String_handle::append( Byte const* byte_c_l, int length_i ) 
121     copy();
122     data->append( byte_c_l, length_i );
124                            
125 INLINE void 
126 String_handle::set( Byte const* byte_c_l, int length_i ) 
128     copy();
129     data->set( byte_c_l, length_i );
131                            
132 INLINE void 
133 String_handle::operator = (char const *p) 
135     copy();
136     data->set( p );
138                            
139 INLINE void 
140 String_handle::trunc(int j) 
142     copy(); data->trunc(j); 
145 INLINE int 
146 String_handle::length_i() const 
148     return data->length_i_; 
151 #endif