package speiger.src.coreengine.rendering.tesselation;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import speiger.src.collections.ints.lists.IntArrayList;
import speiger.src.collections.ints.lists.IntList;
import speiger.src.coreengine.rendering.tesselation.VertexElement.ElementUsage;
import speiger.src.coreengine.utils.collections.iterators.ReadOnlyIterator;

public class VertexList implements Iterable<VertexElement>
{
	List<VertexElement> elements = new ArrayList<VertexElement>();
	Set<ElementUsage> types = EnumSet.noneOf(ElementUsage.class);
	IntList offsets = new IntArrayList();
	int totalOffset;
	
	public VertexList()
	{
	}
	
	public VertexList(VertexList vertexList)
	{
		elements.addAll(vertexList.elements);
		offsets.addAll(vertexList.offsets);
		totalOffset = vertexList.totalOffset;
	}
	
	public void addElement(VertexElement element)
	{
		elements.add(element);
		offsets.add(totalOffset);
		totalOffset += element.getSize();
		types.add(element.getUsage());
	}
	
	public int getOffsets()
	{
		return totalOffset;
	}
	
	public int getElementCount()
	{
		return elements.size();
	}
	
	public VertexElement getElement(int index)
	{
		return elements.get(index);
	}
	
	public int getOffset(int index)
	{
		return offsets.getInt(index);
	}
	
	@Override
	public Iterator<VertexElement> iterator()
	{
		return new ReadOnlyIterator<VertexElement>(elements.iterator());
	}

	public boolean hasType(ElementUsage type)
	{
		return types.contains(type);
	}
	
}
