///home/jon/link/bin/genMethods "-g" "-t" "double" "-d" "basic" "-y" "display_double" "-w" "free_double" 
#include <stk.h>
#include <LINK/stkWrapper/LINK_STk.h>

#include <LINK/stkWrapper/Wrapper.h>
#include <LINK/stkWrapper/Register.h>

void display_double(SCM, SCM, int);
void free_double(SCM);

typedef double _double;

#define _doubleDATA(x) ((double*) (EXTDATA(x)))
#define _doubleIS_DATA(x) (TYPEP(x, tc_CXXwrapper) && \
		TYPEP(STk_slot_ref(x,val_scm), tc_CXXwrapper) && \
		(EXTID(STk_slot_ref(x,val_scm)) == Wrapper<double >::type))
#define _doubleISNT_DATA(x) (!_doubleIS_DATA(x))

#define _doubleCXX_DATA(x) (*(double*) (EXTDATA(VAL(x))))
#define _doubleCXX_IS_DATA(x) (INSTANCEP(x) && \
		TYPEP(STk_slot_ref(x,val_scm), tc_CXXwrapper) && \
		(EXTID(STk_slot_ref(x,val_scm)) == Wrapper<double >::type))
#define _doubleCXX_ISNT_DATA(x) (!_doubleCXX_IS_DATA(x))



// define your new methods above 
// and register them using STk_add_new_cpp_primitive() below

void free_double(SCM p)
{
	//cout << "free_int" << endl;
        if (!EXTSTATICP(p))
                Register<double>::deleteEntry(_doubleDATA(p));
}
void display_double(SCM c, SCM port, int mode)
{
        ostrstream oss;
        if (_doubleDATA(c))
        	oss << *_doubleDATA(c);
        oss << ends;
        char *buffer = oss.str();
        Puts(buffer, (port));
        delete buffer;
}
PRIMITIVE MakeDoubleCmd(SCM num)
{
        Tcl_HashEntry *p;
        SCM objptr;
        double *ap;
        int not_found;
        if (_doubleDATA(num))
                Err("<number> expected", num);
        ap = new double(*_doubleDATA(num));
        Register<double>::createEntry(Wrapper<double>::type,
                                       Wrapper<double>::name, ap);
        return STk_make_CXXwrapper(Wrapper<double>::type,
                        Wrapper<double>::name, (void *) ap, LINK_DYNAMIC);
}

void genExtra_doubleMethods() 
{
        STk_add_new_cpp_primitive("make-double", tc_subr_1,
                                        (PRIMITIVE (*)(...))MakeDoubleCmd);
}
