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