package de.grogra.c4d.model;

import de.grogra.c4d.BaseObject;
import de.grogra.xl.util.ObjectList;

public class C4DGenerator
{
	private BaseObject node;
	private ObjectList<BaseObject> stack = new ObjectList<BaseObject> ();
	int depth;

	public void initialize (BaseObject root)
	{
		node = root;
		stack.clear();
		depth = 0;
	}

	public int getDepth ()
	{
		return depth;
	}

	public C4DGenerator operator$space (BaseObject n)
	{
		n.insertUnderLast(node);
		node = n;
		return this;
	}

	public C4DGenerator producer$push ()
	{
		stack.push(node);
		depth--;
		return this;
	}

	public C4DGenerator producer$begin ()
	{
		depth++;
		return this;
	}

	public void producer$end ()
	{
		depth--;
	}

	public C4DGenerator producer$pop (Object oldProducer)
	{
		node = stack.pop();
		depth++;
		return this;
	}
}
