// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-

/* Copyright (C) 2007 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gio/gio.h>

namespace Gio
{

void MemoryInputStream::add_data(const std::string& data)
{
  char *data_copy = g_strdup (data.c_str ());
  g_memory_input_stream_add_data(gobj(), data_copy, -1, g_free);
}


void MemoryInputStream::add_data(const void* data, gssize len)
{
  char *data_copy = 0;

  // copy the data so that the caller doesn't need to keep the data alive
  if (len < 0)
    data_copy = g_strdup (static_cast<const gchar*>(data));
  else
    data_copy = static_cast<gchar*>(g_memdup (data, len));

  g_memory_input_stream_add_data(gobj(), data_copy, len, g_free);
}

void MemoryInputStream::add_data(const void* data, gssize len, GDestroyNotify destroy)
{
  g_memory_input_stream_add_data(gobj(), data, len, destroy);
}

} // namespace Gio
