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

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

static PRIMITIVE BridgesCmd(SCM g)
{
        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("bridges: bad arg 1, graph expected", g);
        Set<Edge*> s = Bridges(gr,0);
        Set<Edge*>* sp = new Set<Edge*>(s);

        return STk_make_CXXwrapper(Wrapper<Set<Edge*> >::type,
                Wrapper<Set<Edge*> >::name, (void *) sp, LINK_DYNAMIC);
}

static PRIMITIVE BridgesAnimCmd(SCM g, SCM view)
{
        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("bridges: bad arg 1, graph expected", g);
	char *name = getViewName(view);
	int k = initAnimation();
	animationWindows(k, name);
        Set<Edge*> s = Bridges(gr,name);
        Set<Edge*>* sp = new Set<Edge*>(s);

        return STk_make_CXXwrapper(Wrapper<Set<Edge*> >::type,
                Wrapper<Set<Edge*> >::name, (void *) sp, LINK_DYNAMIC);
}

void gen_Bridges_Wrapper()
{
        STk_add_new_cpp_primitive("bridges", tc_subr_1,
                               (PRIMITIVE (*)(...))BridgesCmd);
        STk_add_new_cpp_primitive("bridges*", tc_subr_2,
                               (PRIMITIVE (*)(...))BridgesAnimCmd);
}
