]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/string-handle.icc
release: 0.0.46.jcn1
[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 Han-Wen Nienhuys <hanwen@stack.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->references)) delete data; data = 0; 
23 }
24
25 /// increase ref count
26 INLINE void 
27 String_handle::up(String_data *d) 
28
29     data=d; data->references ++; 
30 }
31
32 INLINE void 
33 String_handle::copy() 
34 {
35     if (data->references !=1){
36         String_data *newdata = new String_data(*data);
37         down();
38         up(newdata);
39     }
40 }
41
42 INLINE
43 String_handle::String_handle() 
44 {
45     up(new String_data);
46 }
47
48 INLINE
49 String_handle::~String_handle() 
50 {       
51     down();
52 }    
53
54 INLINE
55 String_handle::String_handle(String_handle const & src) 
56 {       
57     up(src.data);
58 }
59
60 INLINE Byte* 
61 String_handle::byte_l() 
62 {
63     copy();
64     return data->byte_l();
65 }
66
67 INLINE char* 
68 String_handle::ch_l() 
69 {
70     copy();
71     return (char*)data->byte_l();
72 }
73
74 INLINE Byte 
75 const* String_handle::byte_C() const 
76 {
77     return data->byte_C();
78 }
79
80 INLINE char const* 
81 String_handle::ch_C() const 
82 {
83     return (char const*)data->byte_C();
84 }
85
86 INLINE void 
87 String_handle::operator =(String_handle const &src) 
88 {
89     if (this == &src)
90         return;
91     down();
92     up(src.data);
93 }
94
95 INLINE void 
96 String_handle::operator += (char const *s) 
97 {       
98     copy();
99     *data += s;
100 }    
101
102
103 INLINE Byte 
104 String_handle::operator[](int j) const 
105
106     return (*data)[j]; 
107 }
108
109 // !NOT SAFE!
110 // don't use this for loops. Use byte_C()
111 INLINE Byte &
112 String_handle::operator[](int j) 
113 {
114     copy();     // hmm. Not efficient
115     return data->byte_l()[j];
116 }
117
118 INLINE void 
119 String_handle::append( Byte const* byte_C, int length_i ) 
120 {
121     copy();
122     data->append( byte_C, length_i );
123 }
124                            
125 INLINE void 
126 String_handle::set( Byte const* byte_C, int length_i ) 
127 {
128     copy();
129     data->set( byte_C, length_i );
130 }
131                            
132 INLINE void 
133 String_handle::operator = (char const *p) 
134 {
135     copy();
136     data->set( p );
137 }
138                            
139 INLINE void 
140 String_handle::trunc(int j) 
141 {
142     copy(); data->trunc(j); 
143 }
144
145 INLINE int 
146 String_handle::length_i() const 
147
148     return data->length_i_; 
149 }
150
151 INLINE bool
152 String_handle::is_binary_bo() const {
153     return data->is_binary_bo();
154 }
155
156 #endif