flower-1.1.5
[lilypond.git] / flower / string-data.hh
blobd4f4b6b5b9b2c62d3bf5859363e65eafc0cc805b
1 /*
2 string-data.hh -- declare String_data
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
10 #ifndef STRINGDATA_HH
11 #define STRINGDATA_HH
14 /**Internal String struct.
15 the data itself. Handles simple tasks (resizing, resetting)
17 class String_data {
18 // GNU malloc: storage overhead is 8 bytes anyway.
20 friend class String_handle;
21 int maxlen; // maxlen is arraysize-1
23 int length_i_;
24 Byte* data_byte_p_;
25 int references;
27 /// init to ""
28 String_data();
30 /// init from src. Conservative allocation.
31 String_data(String_data const &src);
33 ~String_data();
35 /** POST: maxlen >= j.
36 @param j, maximum stringlength_i_.
37 contents thrown away.
39 void setmax(int j);
41 /** POST: maxlen >= j.
42 @param j, maximum stringlength_i_.
43 contents are kept if it grows.
45 void remax(int j);
47 /// check if writeable.
48 void OKW();
50 /// check state.
51 void OK();
53 /// reduce memory usage.
54 void tighten();
56 // assignment.
57 void set( Byte const* byte_c_l, int length_i );
59 void set( char const* ch_c_l );
61 /// concatenation.
62 void append( Byte const* byte_c_l, int length_i );
64 void operator += ( char const* ch_c_l );
66 char const* ch_c_l() const;
68 char* ch_l();
70 Byte const* byte_c_l() const;
72 // idem, non const
73 Byte* byte_l();
75 void trunc(int j);
77 /** access element. not really safe. Can alter length_i_ without
78 #String_data# knowing it. */
79 Byte &operator [](int j);
80 Byte operator [](int j) const;
81 bool null_terminated_b()const;
86 #ifdef STRING_UTILS_INLINED
87 #ifndef INLINE
88 #define INLINE inline
89 #endif
90 #include "string-data.inl"
92 #endif
95 #endif // STRING_DATA_HH