#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 BiconnectedComponentsCmd(SCM g)
{
    Graph *gr;
    if (!(gr = getGraph(g)))
	Err("biconnected-components: bad arg 1, graph expected", g);
    Set< Set<Vertex*> > s = BiconnectedComponents(gr);
    Set< Set<Vertex*> >* sp = new Set< Set<Vertex*> >(s);
    
    return STk_make_CXXwrapper(Wrapper<Set< Set<Vertex*> > >::type,
			       Wrapper<Set< Set<Vertex*> > >::name, 
			       (void *) sp, LINK_DYNAMIC);
}

static PRIMITIVE BiconnectedComponentsAnimCmd(SCM g, SCM view) 
{
    Graph *gr;
    
    if (!(gr = getGraph(g)))
	Err("biconnected-components: bad arg 1, graph expected", g);
    char *name = getViewName(view);
    int k = initAnimation();
    animationWindows(k, name);
    Set< Set<Vertex*> > s = BiconnectedComponents(gr,name);
    Set< Set<Vertex*> >* sp = new Set< Set<Vertex*> >(s);
    return STk_make_CXXwrapper(Wrapper<Set< Set<Vertex*> > >::type,
			       Wrapper<Set< Set<Vertex*> > >::name, 
			       (void *) sp, LINK_DYNAMIC);
}

void gen_BiconnectedComponents_Wrapper()
{
    STk_add_new_cpp_primitive("bcc", tc_subr_1,
		 (PRIMITIVE (*)(...))BiconnectedComponentsCmd);
    STk_add_new_cpp_primitive("bcc*", tc_subr_2,
		 (PRIMITIVE (*)(...))BiconnectedComponentsAnimCmd);
    STk_add_new_cpp_primitive("biconnected-components", tc_subr_1,
		 (PRIMITIVE (*)(...))BiconnectedComponentsCmd);
    STk_add_new_cpp_primitive("biconnected-components*", tc_subr_2,
		 (PRIMITIVE (*)(...))BiconnectedComponentsAnimCmd);
}
