// Generated by gtkmmproc -- DO NOT MODIFY!


#include <glibmm.h>

#include <gstreamermm/xml.h>
#include <gstreamermm/private/xml_p.h>


/* gstreamermm - a C++ wrapper for gstreamer
 *
 * Copyright 2008 The gstreamermm 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 <gst/gstxml.h>
#include <gstreamermm/element.h>


namespace Gst
{

xmlDocPtr XML::write(const Glib::RefPtr<const Gst::Element>& element)
{
  return gst_xml_write(const_cast<GstElement*>(Glib::unwrap(element)));
}

void XML::write_to_stream(const Glib::RefPtr<const Gst::Element>& element, std::ostream& out)
{
  xmlDocPtr xmlDoc = write(element);
  xmlpp::Node rootNode(xmlDocGetRootElement(xmlDoc));

  xmlpp::Document doc;
  doc.create_root_node_by_import(&rootNode);
  doc.write_to_stream_formatted(out);

  xmlFreeDoc(xmlDoc);
}

bool XML::parse_memory(const std::string& buffer, const Glib::ustring& root)
{
  return gst_xml_parse_memory(gobj(),
    reinterpret_cast<guchar*>(const_cast<char*>(buffer.c_str())),
    buffer.size(), root.c_str());
}

} //namespace Gst

namespace
{


static void XML_signal_object_loaded_callback(GstXML* self, GstObject* p0,xmlNodePtr p1,void* data)
{
  using namespace Gst;
  typedef sigc::slot< void,const Glib::RefPtr<Gst::Object>&,xmlNodePtr > SlotType;

  // Do not try to call a signal on a disassociated wrapper.
  if(Glib::ObjectBase::_get_current_wrapper((GObject*) self))
  {
    #ifdef GLIBMM_EXCEPTIONS_ENABLED
    try
    {
    #endif //GLIBMM_EXCEPTIONS_ENABLED
      if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data))
        (*static_cast<SlotType*>(slot))(Glib::wrap(p0, true)
, p1);
    #ifdef GLIBMM_EXCEPTIONS_ENABLED
    }
    catch(...)
    {
      Glib::exception_handlers_invoke();
    }
    #endif //GLIBMM_EXCEPTIONS_ENABLED
  }
}

static const Glib::SignalProxyInfo XML_signal_object_loaded_info =
{
  "object-loaded",
  (GCallback) &XML_signal_object_loaded_callback,
  (GCallback) &XML_signal_object_loaded_callback
};


} // anonymous namespace


namespace Glib
{

Glib::RefPtr<Gst::XML> wrap(GstXML* object, bool take_copy)
{
  return Glib::RefPtr<Gst::XML>( dynamic_cast<Gst::XML*> (Glib::wrap_auto ((GObject*)(object), take_copy)) );
  //We use dynamic_cast<> in case of multiple inheritance.
}

} /* namespace Glib */


namespace Gst
{


/* The *_Class implementation: */

const Glib::Class& XML_Class::init()
{
  if(!gtype_) // create the GType if necessary
  {
    // Glib::Class has to know the class init function to clone custom types.
    class_init_func_ = &XML_Class::class_init_function;

    // This is actually just optimized away, apparently with no harm.
    // Make sure that the parent type has been created.
    //CppClassParent::CppObjectType::get_type();

    // Create the wrapper type, with the same class/instance size as the base type.
    register_derived_type(gst_xml_get_type());

    // Add derived versions of interfaces, if the C type implements any interfaces:

  }

  return *this;
}


void XML_Class::class_init_function(void* g_class, void* class_data)
{
  BaseClassType *const klass = static_cast<BaseClassType*>(g_class);
  CppClassParent::class_init_function(klass, class_data);


  klass->object_loaded = &object_loaded_callback;
}


void XML_Class::object_loaded_callback(GstXML* self, GstObject* p0, xmlNodePtr p1)
{
  Glib::ObjectBase *const 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_())
  {
    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
    if(obj) // This can be NULL during destruction.
    {
      #ifdef GLIBMM_EXCEPTIONS_ENABLED
      try // Trap C++ exceptions which would normally be lost because this is a C callback.
      {
      #endif //GLIBMM_EXCEPTIONS_ENABLED
        // Call the virtual member method, which derived classes might override.
        obj->on_object_loaded(Glib::wrap(p0, true)
, p1);
        return;
      #ifdef GLIBMM_EXCEPTIONS_ENABLED
      }
      catch(...)
      {
        Glib::exception_handlers_invoke();
      }
      #endif //GLIBMM_EXCEPTIONS_ENABLED
    }
  }

  BaseClassType *const base = static_cast<BaseClassType*>(
        g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
    );

  // Call the original underlying C function:
  if(base && base->object_loaded)
    (*base->object_loaded)(self, p0, p1);
}


Glib::ObjectBase* XML_Class::wrap_new(GObject* object)
{
  return new XML((GstXML*)object);
}


/* The implementation: */

GstXML* XML::gobj_copy()
{
  reference();
  return gobj();
}

XML::XML(const Glib::ConstructParams& construct_params)
:
  Object(construct_params)
{

}

XML::XML(GstXML* castitem)
:
  Object((GstObject*)(castitem))
{}


XML::~XML()
{}


XML::CppClassType XML::xml_class_; // initialize static member

GType XML::get_type()
{
  return xml_class_.init().get_type();
}


GType XML::get_base_type()
{
  return gst_xml_get_type();
}


XML::XML()
:
  // Mark this class as non-derived to allow C++ vfuncs to be skipped.
  Glib::ObjectBase(0),
  Object(Glib::ConstructParams(xml_class_.init()))
{
  

}

Glib::RefPtr<XML> XML::create()
{
  return Glib::RefPtr<XML>( new XML() );
}

bool XML::parse_doc(xmlpp::Document* doc, Glib::ustring& root)
{
  return gst_xml_parse_doc(gobj(), doc->cobj(), (const guchar*)(root.c_str()));
}

bool XML::parse_file(const std::string& filename, const Glib::ustring& root)
{
  return gst_xml_parse_file(gobj(), (const guchar*)(filename.c_str()), ((const guchar*)root.c_str()));
}

Glib::RefPtr<Gst::Element> XML::get_element(const Glib::ustring& name)
{
  return Glib::wrap(gst_xml_get_element(gobj(), ((const guchar*)name.c_str())));
}

Glib::RefPtr<const Gst::Element> XML::get_element(const Glib::ustring& name) const
{
  return const_cast<XML*>(this)->get_element(name);
}

Glib::ListHandle< Glib::RefPtr<Gst::Element> > XML::get_topelements()
{
  return Glib::ListHandle< Glib::RefPtr<Gst::Element> >(gst_xml_get_topelements(gobj()), Glib::OWNERSHIP_NONE);
}

Glib::ListHandle< Glib::RefPtr<const Gst::Element> > XML::get_topelements() const
{
  return Glib::ListHandle< Glib::RefPtr<const Gst::Element> >(gst_xml_get_topelements(const_cast<GstXML*>(gobj())), Glib::OWNERSHIP_NONE);
}

Glib::RefPtr<Gst::Element> XML::make_element(xmlpp::Node* curr, const Glib::RefPtr<Gst::Object>& parent)
{
  return Glib::wrap(gst_xml_make_element(curr->cobj(), Glib::unwrap(parent)));
}


Glib::SignalProxy2< void,const Glib::RefPtr<Gst::Object>&,xmlNodePtr > XML::signal_object_loaded()
{
  return Glib::SignalProxy2< void,const Glib::RefPtr<Gst::Object>&,xmlNodePtr >(this, &XML_signal_object_loaded_info);
}


void Gst::XML::on_object_loaded(const Glib::RefPtr<Gst::Object>& object, xmlNodePtr xml_node)
{
  BaseClassType *const base = static_cast<BaseClassType*>(
      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
  );

  if(base && base->object_loaded)
    (*base->object_loaded)(gobj(),Glib::unwrap(object),xml_node);
}


} // namespace Gst


