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