// Generated by gmmproc 2.88.0 -- DO NOT MODIFY!


#include <glibmm.h>

#include <glibmm/bytearray.h>
#include <glibmm/private/bytearray_p.h>


/* Copyright (C) 2013 The glibmm 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, see <http://www.gnu.org/licenses/>.
 */

namespace
{
extern "C"
{
// Non-static functions with C linkage get external linkage, even if they are
// defined in an anonymous namespace.
//TODO: Declare 'static' when we can break ABI.
int
ByteArray_Compare_Data_Func(gconstpointer a, gconstpointer b, gpointer user_data)
{
  Glib::ByteArray::SlotCompare* slot = static_cast<Glib::ByteArray::SlotCompare*>(user_data);

  return (*slot)(static_cast<const guint8*>(a), static_cast<const guint8*>(b));
}
} // extern "C"
} // anonymous namespace

namespace Glib
{

guint
ByteArray::size() const
{
  return gobj()->len;
}

guint8*
ByteArray::get_data()
{
  return gobj()->data;
}

const guint8*
ByteArray::get_data() const
{
  return gobj()->data;
}

} // namespace Glib

namespace
{
} // anonymous namespace


/* Why reinterpret_cast<ByteArray*>(gobject) is needed:
 *
 * A ByteArray instance is in fact always a GByteArray instance.
 * Unfortunately, GByteArray cannot be a member of ByteArray,
 * because it is an opaque struct.  Also, the C interface does not provide
 * any hooks to install a destroy notification handler, thus we cannot
 * wrap it dynamically either.
 *
 * The cast works because ByteArray does not have any member data, and
 * it is impossible to derive from it.  This is ensured by using final on the
 * class and by using = delete on the default constructor.
 */

namespace Glib
{

Glib::RefPtr<Glib::ByteArray> wrap(GByteArray* object, bool take_copy)
{
  if(take_copy && object)
    g_byte_array_ref(object);

  // See the comment at the top of this file, if you want to know why the cast works.
  return Glib::make_refptr_for_instance<Glib::ByteArray>(reinterpret_cast<Glib::ByteArray*>(object));
}

} // namespace Glib


namespace Glib
{

// static
GType ByteArray::get_type()
{
  return g_byte_array_get_type();
}

void ByteArray::reference() const
{
  // See the comment at the top of this file, if you want to know why the cast works.
  g_byte_array_ref(reinterpret_cast<GByteArray*>(const_cast<ByteArray*>(this)));
}

void ByteArray::unreference() const
{
  // See the comment at the top of this file, if you want to know why the cast works.
  g_byte_array_unref(reinterpret_cast<GByteArray*>(const_cast<ByteArray*>(this)));
}

GByteArray* ByteArray::gobj()
{
  // See the comment at the top of this file, if you want to know why the cast works.
  return reinterpret_cast<GByteArray*>(this);
}

const GByteArray* ByteArray::gobj() const
{
  // See the comment at the top of this file, if you want to know why the cast works.
  return reinterpret_cast<const GByteArray*>(this);
}

GByteArray* ByteArray::gobj_copy() const
{
  // See the comment at the top of this file, if you want to know why the cast works.
  const auto gobject = reinterpret_cast<GByteArray*>(const_cast<ByteArray*>(this));
  g_byte_array_ref(gobject);
  return gobject;
}


Glib::RefPtr<ByteArray> ByteArray::create()
{
  return Glib::wrap(g_byte_array_new());
}

Glib::RefPtr<ByteArray> ByteArray::append(const guint8* data, guint len)
{
  auto retvalue = Glib::wrap(g_byte_array_append(gobj(), data, len));
  if(retvalue)
    retvalue->reference(); //The function does not do a ref for us.
  return retvalue;
}

Glib::RefPtr<ByteArray> ByteArray::prepend(const guint8* data, guint len)
{
  auto retvalue = Glib::wrap(g_byte_array_prepend(gobj(), data, len));
  if(retvalue)
    retvalue->reference(); //The function does not do a ref for us.
  return retvalue;
}

Glib::RefPtr<ByteArray> ByteArray::remove_index(guint index)
{
  auto retvalue = Glib::wrap(g_byte_array_remove_index(gobj(), index));
  if(retvalue)
    retvalue->reference(); //The function does not do a ref for us.
  return retvalue;
}

Glib::RefPtr<ByteArray> ByteArray::remove_index_fast(guint index)
{
  auto retvalue = Glib::wrap(g_byte_array_remove_index_fast(gobj(), index));
  if(retvalue)
    retvalue->reference(); //The function does not do a ref for us.
  return retvalue;
}

Glib::RefPtr<ByteArray> ByteArray::remove_range(guint index, guint length)
{
  auto retvalue = Glib::wrap(g_byte_array_remove_range(gobj(), index, length));
  if(retvalue)
    retvalue->reference(); //The function does not do a ref for us.
  return retvalue;
}

void ByteArray::sort(const SlotCompare& slot)
{
  // Use the original slot (not a copy).
  auto slot_copy = const_cast<SlotCompare*>(&slot);

  g_byte_array_sort_with_data(gobj(), &ByteArray_Compare_Data_Func, slot_copy);
}

Glib::RefPtr<ByteArray> ByteArray::set_size(guint length)
{
  auto retvalue = Glib::wrap(g_byte_array_set_size(gobj(), length));
  if(retvalue)
    retvalue->reference(); //The function does not do a ref for us.
  return retvalue;
}


} // namespace Glib


