]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/string-data.hh
2404b24e3df59fe08124d8a102e68a5925ee38a7
[lilypond.git] / flower / include / string-data.hh
1 /*
2   string-data.hh -- declare  String_data
3
4   source file of the LilyPond music typesetter
5
6   (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #ifndef STRINGDATA_HH
11 #define STRINGDATA_HH
12
13
14 /**Internal String struct.
15    the data itself. Handles simple tasks (resizing, resetting)
16    */
17 class String_data {
18     // GNU malloc: storage overhead is 8 bytes anyway.
19
20 friend class String_handle;
21     int maxlen; // maxlen is arraysize-1
22     
23     int length_;
24     Byte* data_byte_;
25     int ref_count_;
26
27     /// init to ""
28     String_data ();
29
30     /// init from src. Conservative allocation.
31     String_data (String_data const &src); 
32     
33     ~String_data ();
34
35     /** POST: maxlen >= j.
36       @param j, maximum stringlength_.    
37       contents thrown away.
38     */
39     void setmax (int j);
40     
41     /** POST: maxlen >= j.
42       @param j, maximum stringlength_.
43       contents are kept if it grows.
44       */
45     void remax (int j);
46
47     /// check if writeable.
48     void OKW ();
49
50     /// check state.
51     void OK ();
52
53     /// reduce memory usage.
54     void tighten ();
55
56     // assignment.
57     void set (Byte const* byte, int length_i);
58
59     void set (char const* str0);
60     
61     /// concatenation.
62     void append (Byte const* byte, int length_i);
63
64     void operator += (char const* str0);
65
66     char const* to_str0 () const; 
67
68     char* get_str0 ();
69
70     Byte const* to_bytes () const;
71
72     // idem, non const
73     Byte* get_bytes ();
74
75     void trunc (int j);
76
77     /** access element. not really safe. Can alter length_ without
78       #String_data# knowing it.  */
79     Byte &operator [] (int j);
80     Byte operator [] (int j) const;
81     bool is_binary_bo () const;
82 };
83
84
85
86 #ifdef STRING_UTILS_INLINED
87 #ifndef INLINE
88 #define INLINE inline
89 #endif
90 #include "string-data.icc"
91
92 #endif
93
94
95 #endif // STRING_DATA_HH