#include<stk.h>
#include<LINK/stkWrapper/LINK_STk.h>
#include<LINK/stkWrapper/Wrapper.h>
#include<LINK/algorithm/Algorithms.h>
#include<LINK/basic/Sequence.h>
#include<LINK/graph/Graph.h>
#include<LINK/graph/Edge.h>

#include <stdio.h>
#include <stdlib.h>

static PRIMITIVE FleuryCmd(SCM g)
{
    Graph *gr;
    if (!(gr = getGraph(g)))
	Err("fleury: bad arg 1, graph expected", g);
    Sequence<Edge*> s = Fleury(gr);
    Sequence<Edge*>* sp = new Sequence<Edge*>(s);
    
    return STk_make_CXXwrapper(Wrapper<Sequence<Edge*> >::type,
			       Wrapper<Sequence<Edge*> >::name, 
			       (void *) sp, LINK_DYNAMIC);
}

static PRIMITIVE FleuryAnimCmd(SCM g, SCM view) 
{
    Graph *gr;
    
    if (!(gr = getGraph(g)))
	Err("fleury: bad arg 1, graph expected", g);
    char *name = getViewName(view);
    int k = initAnimation();
    animationWindows(k, name);
    Sequence<Edge*> s = Fleury(gr, name);
    Sequence<Edge*>* sp = new Sequence<Edge*>(s);
    return STk_make_CXXwrapper(Wrapper<Sequence<Edge*> >::type,
			       Wrapper<Sequence<Edge*> >::name, 
			       (void *) sp, LINK_DYNAMIC);
}

void gen_Fleury_Wrapper()
{
    STk_add_new_cpp_primitive("fleury", tc_subr_1,
		 (PRIMITIVE (*)(...))FleuryCmd);
    STk_add_new_cpp_primitive("fleury*", tc_subr_2,
		 (PRIMITIVE (*)(...))FleuryAnimCmd);
}
