//genMethods "-t" "Attribute<double>*" "-I" "LINK/graph/Attribute.h" "-d" "graph" "-y" "display_attribute_double" 
#include <stk.h>
#include <LINK/stkWrapper/LINK_STk.h>
#include <LINK/graph/Attribute.h>
#include <LINK/stkWrapper/Wrapper.h>
#include <LINK/stkWrapper/Register.h>
void display_attribute_doubleptr(SCM, SCM, int);
typedef Attribute<double>* _Attribute_double__;
#define _Attribute_double__DATA(x) ((Attribute<double>**) (EXTDATA(x)))
#define _Attribute_double__IS_DATA(x) (TYPEP(x, tc_CXXwrapper) && \
		TYPEP(STk_slot_ref(x,val_scm), tc_CXXwrapper) && \
		(EXTID(STk_slot_ref(x,val_scm)) == Wrapper<Attribute<double>* >::type))
#define _Attribute_double__ISNT_DATA(x) (!_Attribute_double__IS_DATA(x))
#define _Attribute_double__CXX_DATA(x) (*(Attribute<double>**) (EXTDATA(VAL(x))))
#define _Attribute_double__CXX_IS_DATA(x) (INSTANCEP(x) && \
		TYPEP(STk_slot_ref(x,val_scm), tc_CXXwrapper) && \
		(EXTID(STk_slot_ref(x,val_scm)) == Wrapper<Attribute<double>* >::type))
#define _Attribute_double__CXX_ISNT_DATA(x) (!_Attribute_double__CXX_IS_DATA(x))
#include <strstream.h>
#include <LINK/graph/GraphObject.h>
#define DOUBLE(s)    ((double) ((s)->storage_as.flonum.data))
void display_attribute_doubleptr(SCM c, SCM port, int mode)
{
        ostrstream oss;
	if (*_Attribute_double__DATA(c))
        	oss << **_Attribute_double__DATA(c);
        oss << ends;
        char *buffer = oss.str();
        Puts(buffer, (port));
        delete buffer;
}
static SCM findDoubleAttributeCmd(SCM name, SCM go)
{
	GraphObject *gobj;
	if (!SYMBOLP(name))
		Err("find-double-attribute: bad arg 1, symbol expected", name);
	if (!(gobj = getGraphObject(go)))
		Err("find-double-attribute: bad arg 2, graph, vertex, or edge"
		    "expected", go);
	char *nm = PNAME(name);
	
	double val;
	if (getAttribute(gobj, nm, val) == LINK_GET_ATTR_FAIL)
		Err("find-attribute: error retrieving attribute", name);
	
	SCM ret_val = STk_makenumber(val);
	return ret_val;
}
static SCM setDoubleAttributeCmd(SCM name, SCM val, SCM go)
{
	GraphObject *gobj;
	if (!SYMBOLP(name))
		Err("set-double-attribute!: bad arg 1, symbol expected", name);
	if (!NUMBERP(val))
		Err("set-double-attribute!: bad arg 2, number expected", val);
	if (!(gobj = getGraphObject(go)))
		Err("set-double-attribute!: bad arg 3, graph, vertex, or edge"
		    "expected", go);
	char *nm = PNAME(name);
	
	double value;
	if (INTEGERP(val))
		value = INTEGER(val);
	else
		value = DOUBLE(val);
	if (setAttribute(gobj, nm, value) == LINK_SET_ATTR_FAIL)
		Err("set-double-attribute: error setting attribute", name);
	
	return UNDEFINED;
}
static SCM newDoubleAttributeCmd(SCM name, SCM val, SCM go)
{
	Graph *g;
	if (!SYMBOLP(name))
		Err("new-double-attribute!: bad arg 1, symbol expected", name);
	if (!NUMBERP(val))
		Err("new-double-attribute!: bad arg 2, number expected", val);
	if (!(g = getGraph(go)))
		Err("new-attribute!: bad arg 3, graph expected", go);
	char *nm = PNAME(name);
	double value;
	if (INTEGERP(val))
		value = INTEGER(val);
	else
		value = DOUBLE(val);
	if (newAttribute(g, nm, value) == LINK_NEW_ATTR_FAIL)
		Err("new-attribute: error creating attribute", name);
	
	return UNDEFINED;
}
// define your new methods above 
// and register them using STk_add_new_cpp_primitive() below
void genExtra_Attribute_double__Methods() 
{
        STk_add_new_cpp_primitive("find-double-attribute", tc_subr_2,
                            (PRIMITIVE (*)(...))findDoubleAttributeCmd);
        STk_add_new_cpp_primitive("set-double-attribute!", tc_subr_3,
                            (PRIMITIVE (*)(...))setDoubleAttributeCmd);
        STk_add_new_cpp_primitive("new-double-attribute!", tc_subr_3,
                            (PRIMITIVE (*)(...))newDoubleAttributeCmd);
}
