2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
25 #include "memory-stream.hh"
28 TODO: add read support as well.
30 const int Memory_out_stream::block_size_ = 1024;
32 lily_cookie_io_functions_t
33 Memory_out_stream::functions_
35 Memory_out_stream::reader,
36 Memory_out_stream::writer,
37 Memory_out_stream::seeker,
38 Memory_out_stream::cleaner
42 Memory_out_stream::cleaner (void *cookie)
44 Memory_out_stream *stream = (Memory_out_stream *) cookie;
50 Memory_out_stream::Memory_out_stream ()
58 file_ = fopencookie ((void *) this, "w", functions_);
62 Memory_out_stream::~Memory_out_stream ()
71 Memory_out_stream::get_file () const
77 Memory_out_stream::get_length () const
83 Memory_out_stream::get_string () const
89 Memory_out_stream::writer (void *cookie,
93 Memory_out_stream *stream = (Memory_out_stream *) cookie;
95 ssize_t newsize = stream->size_ + size;
98 while (newsize > stream->buffer_blocks_ * block_size_)
100 stream->buffer_blocks_ *= 2;
101 stream->buffer_blocks_ += 1;
106 stream->buffer_ = (char *) realloc (stream->buffer_,
107 stream->buffer_blocks_ * block_size_);
109 memcpy (stream->buffer_ + stream->size_, buffer, size);
110 stream->size_ = newsize;
116 Memory_out_stream::reader (void * /* cookie */,
125 Memory_out_stream::seeker (void *,