]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/string-data.hh
* The grand 2005-2006 replace.
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #ifndef STRINGDATA_HH
10 #define STRINGDATA_HH
11
12 #include "flower-proto.hh"
13
14 /**Internal String struct.
15    the data itself. Handles simple tasks (resizing, resetting)
16 */
17 class String_data
18 {
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 #ifdef STRING_UTILS_INLINED
86 #ifndef INLINE
87 #define INLINE inline
88 #endif
89 #include "string-data.icc"
90
91 #endif
92
93 #endif // STRING_DATA_HH