Massive changes - see ChangeLog.
[lilypond.git] / flower / include / string-handle.icc
blobbb6524b34dbeba1d5dd59a66eeb6fc49a867eb3a
1 /* -*-c++-*-
2    
3   stringhandle.inl -- implement String_handle
5   source file of Flower lib
7   (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #ifndef STRINGHANDLE_INL
11 #define STRINGHANDLE_INL
13 #include <assert.h>
14 #include <memory.h>
16 #include "string-data.hh"
17 #include "string-handle.hh"
19 INLINE void 
20 String_handle::down () 
21
22   if (! (--data->ref_count_))
23     delete data;
24   data = 0; 
28   increase ref count
30   THIS does not have to be initialized.
32 INLINE void 
33 String_handle::up (String_data *d) 
34
35   data=d;
36   data->ref_count_ ++; 
39 INLINE void 
40 String_handle::copy () 
42   if (data->ref_count_ !=1)
43     {
44       String_data *newdata = new String_data (*data);
45       down ();
46       up (newdata);
47     }
50 INLINE
51 String_handle::String_handle () 
53   up (new String_data);
56 INLINE
57 String_handle::~String_handle () 
58 {       
59   down ();
60 }    
62 INLINE
63 String_handle::String_handle (String_handle const & src) 
64 {       
65   up (src.data);
68 INLINE Byte* 
69 String_handle::get_bytes () 
71   copy ();
72   return data->get_bytes ();
75 INLINE char* 
76 String_handle::get_str0 () 
78   copy ();
79   return (char*)data->get_bytes ();
82 INLINE Byte 
83 const* String_handle::to_bytes () const 
85   return data->to_bytes ();
88 INLINE char const* 
89 String_handle::to_str0 () const 
91   return (char const*)data->to_bytes ();
94 INLINE void 
95 String_handle::operator = (String_handle const &src) 
97   if (this == &src)
98     return;
99   down ();
100   up (src.data);
103 INLINE void 
104 String_handle::operator += (char const *s) 
105 {       
106   copy ();
107   *data += s;
108 }    
111 INLINE Byte 
112 String_handle::operator[] (int j) const 
114   return (*data)[j]; 
117 // !NOT SAFE!
118 // don't use this for loops. Use to_bytes ()
119 INLINE Byte &
120 String_handle::operator[] (int j) 
122   copy ();      // hmm. Not efficient
123   return data->get_bytes ()[j];
126 INLINE void 
127 String_handle::append (Byte const* byte, int length_i) 
129   copy ();
130   data->append (byte, length_i);
132                            
133 INLINE void 
134 String_handle::set (Byte const* byte, int length_i) 
136   copy ();
137   data->set (byte, length_i);
139                            
140 INLINE void 
141 String_handle::operator = (char const *p) 
143   copy ();
144   data->set (p);
146                            
147 INLINE void 
148 String_handle::trunc (int j) 
150   copy (); data->trunc (j); 
153 INLINE int 
154 String_handle::length () const 
156   return data->length_; 
159 INLINE bool
160 String_handle::is_binary_bo () const {
161   return data->is_binary_bo ();
164 #endif