/* libgeglmm - a C++ wrapper for libgegl
 *
 * (c) 2008-2009 Hubert Figuiere
 *
 * 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 3 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 GEGL; if not, see <http://www.gnu.org/licenses/>.
 */

#include <gegl.h>

#include <glibmm/object.h>
#include <geglmm/node.h>
#include <geglmm/rectangle.h>
#include <geglmm/processor.h>


namespace  Gegl {

    Glib::RefPtr<Node> Node::new_child(const Glib::ustring & first_property_name, const Glib::ustring & first_value)
	{
		Glib::RefPtr<Node> node(Glib::wrap(
									gegl_node_new_child(gobj(),
														first_property_name.c_str(),
														first_value.c_str(), NULL)));
        // the node is refcounted owned by the node. Make sure the pointer won't free it too early.
        node->reference();
		return node;
	}

	Glib::RefPtr<Node> Node::get_producer(const Glib::ustring & input_pad_name, Glib::ustring * output_pad_name) const
	{
		gchar *s = NULL;
		Glib::RefPtr<Node> node(Glib::wrap(gegl_node_get_producer(const_cast<GeglNode*>(gobj()), 
																  (gchar*)input_pad_name.c_str(), 
																  output_pad_name?&s:NULL)));
		if(output_pad_name) {
			*output_pad_name = s;
		}
		return node;
	}


  Glib::RefPtr<Node> Node::link(const Glib::RefPtr<Node> & sink)
  {
    gegl_node_link(gobj(), sink->gobj());
    return sink;
  }


  void Node::set(const Glib::ustring & first_property_name, ...) 
  {
    va_list var_args;

    va_start (var_args, first_property_name);
    gegl_node_set_valist(gobj(), first_property_name.c_str(), var_args);
    va_end (var_args);
  }


  void Node::get(const Glib::ustring & first_property_name, ...)
  {
    va_list var_args;

    va_start (var_args, first_property_name);
    gegl_node_get_valist(gobj(), first_property_name.c_str(), var_args);
    va_end (var_args);
  }

}

