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


#include <glibmm.h>

#include <giomm/listmodel.h>
#include <giomm/private/listmodel_p.h>


/* Copyright (C) 2016 The giomm 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/>.
 */

#include <gio/gio.h>

namespace Gio
{

} // namespace Gio

namespace
{


static void ListModel_signal_items_changed_callback(GListModel* self, guint p0,guint p1,guint p2,void* data)
{
  using namespace Gio;
  using SlotType = sigc::slot< void,guint,guint,guint >;

  auto obj = dynamic_cast<ListModel*>(Glib::ObjectBase::_get_current_wrapper((GObject*) self));
  // Do not try to call a signal on a disassociated wrapper.
  if(obj)
  {
    try
    {
      if(const auto slot = Glib::SignalProxyNormal::data_to_slot(data))
        (*static_cast<SlotType*>(slot))(p0, p1, p2);
    }
    catch(...)
    {
       Glib::exception_handlers_invoke();
    }
  }
}

static const Glib::SignalProxyInfo ListModel_signal_items_changed_info =
{
  "items-changed",
  (GCallback) &ListModel_signal_items_changed_callback,
  (GCallback) &ListModel_signal_items_changed_callback
};


} // anonymous namespace


namespace Glib
{

Glib::RefPtr<Gio::ListModel> wrap(GListModel* object, bool take_copy)
{
  return Glib::RefPtr<Gio::ListModel>( dynamic_cast<Gio::ListModel*> (Glib::wrap_auto_interface<Gio::ListModel> ((GObject*)(object), take_copy)) );
  //We use dynamic_cast<> in case of multiple inheritance.
}

} // namespace Glib


namespace Gio
{


/* The *_Class implementation: */

const Glib::Interface_Class& ListModel_Class::init()
{
  if(!gtype_) // create the GType if necessary
  {
    // Glib::Interface_Class has to know the interface init function
    // in order to add interfaces to implementing types.
    class_init_func_ = &ListModel_Class::iface_init_function;

    // We can not derive from another interface, and it is not necessary anyway.
    gtype_ = g_list_model_get_type();
  }

  return *this;
}

void ListModel_Class::iface_init_function(void* g_iface, void*)
{
  const auto klass = static_cast<BaseClassType*>(g_iface);

  //This is just to avoid an "unused variable" warning when there are no vfuncs or signal handlers to connect.
  //This is a temporary fix until I find out why I can not seem to derive a GtkFileChooser interface. murrayc
  g_assert(klass != nullptr);

  klass->get_item_type = &get_item_type_vfunc_callback;
  klass->get_n_items = &get_n_items_vfunc_callback;
  klass->get_item = &get_item_vfunc_callback;

}

GType ListModel_Class::get_item_type_vfunc_callback(GListModel* self)
{
  const auto obj_base = static_cast<Glib::ObjectBase*>(
      Glib::ObjectBase::_get_current_wrapper((GObject*)self));

  // Non-gtkmmproc-generated custom classes implicitly call the default
  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
  // generated classes can use this optimisation, which avoids the unnecessary
  // parameter conversions if there is no possibility of the virtual function
  // being overridden:
  if(obj_base && obj_base->is_derived_())
  {
    const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
    if(obj) // This can be NULL during destruction.
    {
      try // Trap C++ exceptions which would normally be lost because this is a C callback.
      {
        // Call the virtual member method, which derived classes might override.
        return obj->get_item_type_vfunc();
      }
      catch(...)
      {
        Glib::exception_handlers_invoke();
      }
    }
  }

  BaseClassType *const base = static_cast<BaseClassType*>(
      g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type()) // Get the interface.
)  );

  // Call the original underlying C function:
  if(base && base->get_item_type)
    return (*base->get_item_type)(self);

  using RType = GType;
  return RType();
}
guint ListModel_Class::get_n_items_vfunc_callback(GListModel* self)
{
  const auto obj_base = static_cast<Glib::ObjectBase*>(
      Glib::ObjectBase::_get_current_wrapper((GObject*)self));

  // Non-gtkmmproc-generated custom classes implicitly call the default
  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
  // generated classes can use this optimisation, which avoids the unnecessary
  // parameter conversions if there is no possibility of the virtual function
  // being overridden:
  if(obj_base && obj_base->is_derived_())
  {
    const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
    if(obj) // This can be NULL during destruction.
    {
      try // Trap C++ exceptions which would normally be lost because this is a C callback.
      {
        // Call the virtual member method, which derived classes might override.
        return obj->get_n_items_vfunc();
      }
      catch(...)
      {
        Glib::exception_handlers_invoke();
      }
    }
  }

  BaseClassType *const base = static_cast<BaseClassType*>(
      g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type()) // Get the interface.
)  );

  // Call the original underlying C function:
  if(base && base->get_n_items)
    return (*base->get_n_items)(self);

  using RType = guint;
  return RType();
}
gpointer ListModel_Class::get_item_vfunc_callback(GListModel* self, guint position)
{
  const auto obj_base = static_cast<Glib::ObjectBase*>(
      Glib::ObjectBase::_get_current_wrapper((GObject*)self));

  // Non-gtkmmproc-generated custom classes implicitly call the default
  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
  // generated classes can use this optimisation, which avoids the unnecessary
  // parameter conversions if there is no possibility of the virtual function
  // being overridden:
  if(obj_base && obj_base->is_derived_())
  {
    const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
    if(obj) // This can be NULL during destruction.
    {
      try // Trap C++ exceptions which would normally be lost because this is a C callback.
      {
        // Call the virtual member method, which derived classes might override.
        return obj->get_item_vfunc(position);
      }
      catch(...)
      {
        Glib::exception_handlers_invoke();
      }
    }
  }

  BaseClassType *const base = static_cast<BaseClassType*>(
      g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
g_type_interface_peek(G_OBJECT_GET_CLASS(self), CppObjectType::get_type()) // Get the interface.
)  );

  // Call the original underlying C function:
  if(base && base->get_item)
    return (*base->get_item)(self, position);

  using RType = gpointer;
  return RType();
}


Glib::ObjectBase* ListModel_Class::wrap_new(GObject* object)
{
  return new ListModel((GListModel*)(object));
}


/* The implementation: */

ListModel::ListModel()
:
  Glib::Interface(listmodel_class_.init())
{}

ListModel::ListModel(GListModel* castitem)
:
  Glib::Interface((GObject*)(castitem))
{}

ListModel::ListModel(const Glib::Interface_Class& interface_class)
: Glib::Interface(interface_class)
{
}

ListModel::ListModel(ListModel&& src) noexcept
: Glib::Interface(std::move(src))
{}

ListModel& ListModel::operator=(ListModel&& src) noexcept
{
  Glib::Interface::operator=(std::move(src));
  return *this;
}

ListModel::~ListModel() noexcept
{}

// static
void ListModel::add_interface(GType gtype_implementer)
{
  listmodel_class_.init().add_interface(gtype_implementer);
}

ListModel::CppClassType ListModel::listmodel_class_; // initialize static member

GType ListModel::get_type()
{
  return listmodel_class_.init().get_type();
}


GType ListModel::get_base_type()
{
  return g_list_model_get_type();
}


void ListModel::items_changed(guint position, guint removed, guint added)
{
  g_list_model_items_changed(gobj(), position, removed, added);
}

GType ListModel::get_item_type() const
{
  return g_list_model_get_item_type(const_cast<GListModel*>(gobj()));
}

guint ListModel::get_n_items() const
{
  return g_list_model_get_n_items(const_cast<GListModel*>(gobj()));
}

Glib::RefPtr<Glib::ObjectBase> ListModel::get_object(guint position)
{
  return Glib::RefPtr<Glib::ObjectBase>(Glib::wrap_auto(g_list_model_get_object(gobj(), position)));
}

Glib::RefPtr<const Glib::ObjectBase> ListModel::get_object(guint position) const
{
  return const_cast<ListModel*>(this)->get_object(position);
}


Glib::SignalProxy< void,guint,guint,guint > ListModel::signal_items_changed()
{
  return Glib::SignalProxy< void,guint,guint,guint >(this, &ListModel_signal_items_changed_info);
}


GType Gio::ListModel::get_item_type_vfunc() 
{
  const auto base = static_cast<BaseClassType*>(
      g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
g_type_interface_peek(G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type()) // Get the interface.
)  );

  if(base && base->get_item_type)
  {
    GType retval((*base->get_item_type)(gobj()));
    return retval;
  }

  using RType = GType;
  return RType();
}
guint Gio::ListModel::get_n_items_vfunc() 
{
  const auto base = static_cast<BaseClassType*>(
      g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
g_type_interface_peek(G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type()) // Get the interface.
)  );

  if(base && base->get_n_items)
  {
    guint retval((*base->get_n_items)(gobj()));
    return retval;
  }

  using RType = guint;
  return RType();
}
gpointer Gio::ListModel::get_item_vfunc(guint position) 
{
  const auto base = static_cast<BaseClassType*>(
      g_type_interface_peek_parent( // Get the parent interface of the interface (The original underlying C interface).
g_type_interface_peek(G_OBJECT_GET_CLASS(gobject_), CppObjectType::get_type()) // Get the interface.
)  );

  if(base && base->get_item)
  {
    gpointer retval((*base->get_item)(gobj(),position));
    return retval;
  }

  using RType = gpointer;
  return RType();
}


} // namespace Gio


