]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/memory-stream.cc
Run grand-replace (issue 3765)
[lilypond.git] / flower / memory-stream.cc
index d73e808ee26d52946c5684d72088757a3490406b..71a61d44225fb37e8213846c0cd788dd47945f09 100644 (file)
@@ -1,32 +1,48 @@
 /*
-  memory-stream.cc --  implement Memory_out_stream
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
+  Copyright (C) 2005--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-  (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
 
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <assert.h>
-#include <string.h>
-#include <stdlib.h>
-#include <libio.h>
+#include <cassert>
+#include <cstring>
+#include <cstdlib>
+using namespace std;
+
 #include "memory-stream.hh"
 
+/*
+  TODO: add read support as well.
+*/
 const int Memory_out_stream::block_size_ = 1024;
 
-cookie_io_functions_t
-Memory_out_stream::functions_ = {
+lily_cookie_io_functions_t
+Memory_out_stream::functions_
+=
+{
   Memory_out_stream::reader,
   Memory_out_stream::writer,
   Memory_out_stream::seeker,
   Memory_out_stream::cleaner
 };
 
-int
+ssize_t
 Memory_out_stream::cleaner (void *cookie)
 {
-  Memory_out_stream *stream = (Memory_out_stream*) cookie;
+  Memory_out_stream *stream = (Memory_out_stream *) cookie;
 
   stream->file_ = 0;
   return 0;
@@ -35,12 +51,16 @@ Memory_out_stream::cleaner (void *cookie)
 Memory_out_stream::Memory_out_stream ()
 {
   size_ = 0;
-  buffer_ = 0; 
+  buffer_ = 0;
   buffer_blocks_ = 0;
-  file_ = fopencookie ((void*) this, "w", functions_);
+  file_ = 0;
+
+#if 0
+  file_ = fopencookie ((void *) this, "w", functions_);
+#endif
 }
 
-Memory_out_stream::~Memory_out_stream()
+Memory_out_stream::~Memory_out_stream ()
 {
   if (file_)
     fclose (file_);
@@ -48,7 +68,7 @@ Memory_out_stream::~Memory_out_stream()
   free (buffer_);
 }
 
-FILE*
+FILE *
 Memory_out_stream::get_file () const
 {
   return file_;
@@ -60,21 +80,20 @@ Memory_out_stream::get_length () const
   return size_;
 }
 
-const char *
+char const *
 Memory_out_stream::get_string () const
 {
   return buffer_;
 }
 
-
 ssize_t
 Memory_out_stream::writer (void *cookie,
-                          const char *buffer,
-                          size_t size)
+                           char const *buffer,
+                           size_t size)
 {
-  Memory_out_stream * stream = (Memory_out_stream*) cookie;
-  
-  ssize_t newsize = stream->size_ + size;
+  Memory_out_stream *stream = (Memory_out_stream *) cookie;
+
+  ssize_t newsize = stream->size_ + (ssize_t) size;
 
   bool change = false;
   while (newsize > stream->buffer_blocks_ * block_size_)
@@ -85,32 +104,29 @@ Memory_out_stream::writer (void *cookie,
     }
 
   if (change)
-    stream->buffer_ = (char*) realloc (stream->buffer_, stream->buffer_blocks_ * block_size_);
+    stream->buffer_ = (char *) realloc (stream->buffer_,
+                                        (size_t) (stream->buffer_blocks_ * block_size_));
 
   memcpy (stream->buffer_ + stream->size_, buffer, size);
   stream->size_ = newsize;
 
-  return size;
+  return (ssize_t) size;
 }
 
-
 ssize_t
-Memory_out_stream::reader (void *cookie,
-                          char *buffer,
-                          size_t size)
+Memory_out_stream::reader (void * /* cookie */,
+                           char * /* buffer */,
+                           size_t /* size */)
 {
-  (void) cookie;
-  (void) buffer;
-  (void) size;
-  
   assert (false);
+  return 0;
 }
 
-
-int
-Memory_out_stream::seeker (void*, off64_t *, int whence)
+ssize_t
+Memory_out_stream::seeker (void *,
+                           off64_t *,
+                           size_t)
 {
   assert (false);
-  (void)whence;
   return 0;
 }