2 memory-stream.cc -- implement Memory_out_stream
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
14 #include "memory-stream.hh"
17 TODO: add read support as well.
19 const int Memory_out_stream::block_size_
= 1024;
21 lily_cookie_io_functions_t
22 Memory_out_stream::functions_
24 Memory_out_stream::reader
,
25 Memory_out_stream::writer
,
26 Memory_out_stream::seeker
,
27 Memory_out_stream::cleaner
31 Memory_out_stream::cleaner (void *cookie
)
33 Memory_out_stream
*stream
= (Memory_out_stream
*) cookie
;
39 Memory_out_stream::Memory_out_stream ()
47 file_
= fopencookie ((void *) this, "w", functions_
);
51 Memory_out_stream::~Memory_out_stream ()
60 Memory_out_stream::get_file () const
66 Memory_out_stream::get_length () const
72 Memory_out_stream::get_string () const
78 Memory_out_stream::writer (void *cookie
,
82 Memory_out_stream
*stream
= (Memory_out_stream
*) cookie
;
84 ssize_t newsize
= stream
->size_
+ size
;
87 while (newsize
> stream
->buffer_blocks_
* block_size_
)
89 stream
->buffer_blocks_
*= 2;
90 stream
->buffer_blocks_
+= 1;
95 stream
->buffer_
= (char *) realloc (stream
->buffer_
,
96 stream
->buffer_blocks_
* block_size_
);
98 memcpy (stream
->buffer_
+ stream
->size_
, buffer
, size
);
99 stream
->size_
= newsize
;
105 Memory_out_stream::reader (void *cookie
,
118 Memory_out_stream::seeker (void *, off64_t
*, int whence
)