#include<stk.h>
#include<strstream.h>
#include<LINK/basic/Set.h>
#include<LINK/stkWrapper/LINK_STk.h>
#include<LINK/stkWrapper/CollectionWrapper.h>
#include<LINK/layout/Layouts.h>
#include<LINK/algorithm/Algorithms.h>
#include<LINK/graph/Graph.h>

static PRIMITIVE ComponentLayoutCmd(SCM gparms, int len)
{
        SCM g, ssv, layout1, layout2;

        if (len < 4)
                return UNDEFINED;
        g = CAR(gparms);
        ssv = CAR(CDR(gparms));
        layout1 = CAR(CDR(CDR(gparms)));
        layout2 = CAR(CDR(CDR(CDR(gparms))));

        Graph *gr;
        if (!(gr = getGraph(g)))
                Err("component-layout!: bad arg 1, graph expected", g);
        Collection<Set<Vertex*> >* svc =
                        CollectionWrapper<Set<Vertex*> >::getCollection(ssv);
	if (!svc)
                Err("component-layout!: bad arg 2, <set<set<Vertex*>> expected",
					ssv);
        if (!STRINGP(layout1))
                Err("component-layout!: bad arg 3, string expected", layout1);
        if (!STRINGP(layout2))
                Err("component-layout!: bad arg 4, string expected", layout2);
        ComponentLayout(gr, *svc, getLayout(CHARS(layout1)), 
				  getLayout(CHARS(layout2)));

        return UNDEFINED;
}

void gen_ComponentLayout_Wrapper()
{
        STk_add_new_cpp_primitive("component-layout", tc_lsubr,
                               (PRIMITIVE (*)(...))ComponentLayoutCmd);
}
