]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/string-data.hh
release: 0.1.11
[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 Han-Wen Nienhuys <hanwen@stack.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_i_;
24     Byte* data_byte_p_;
25     int references;
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_i_.    
37       contents thrown away.
38     */
39     void setmax (int j);
40     
41     /** POST: maxlen >= j.
42       @param j, maximum stringlength_i_.
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_C, int length_i);
58
59     void set (char const* ch_C);
60     
61     /// concatenation.
62     void append (Byte const* byte_C, int length_i);
63
64     void operator += ( char const* ch_C);
65
66     char const* ch_C() const; 
67
68     char* ch_l();
69
70     Byte const* byte_C() const;
71
72     // idem, non const
73     Byte* byte_l();
74
75     void trunc (int j);
76
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 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