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