
#include "Entities/EntityMemoryPool.h"
#include <Entities/EntityView.h>
#include <Entities/Entity.h>
#include <utility.h>

EntityView::EntityView(EntityMemoryPool& data, index_t start, index_t size)
	: m_data(data)
	, m_start(start)
	, m_size(size)
{ }

Entity EntityView::operator[](index_t index) const
{
	return Entity(m_data, m_start + index);
}

//non-const iterator
EntityView::iterator::iterator(EntityMemoryPool& data, index_t index)
	: m_data(data)
	, m_currentEntity(index)
{ }

EntityView::iterator& EntityView::iterator::operator++()
{
	m_currentEntity++;
	return *this;
}

EntityView::iterator EntityView::iterator::operator++(int)
{
	m_currentEntity++;
	return iterator(m_data, m_currentEntity - 1);
}

EntityView::iterator& EntityView::iterator::operator--()
{
	m_currentEntity--;
	return *this;
}

EntityView::iterator EntityView::iterator::operator--(int)
{
	m_currentEntity--;
	return iterator(m_data, m_currentEntity + 1);
}

Entity EntityView::iterator::operator*()
{
	return Entity(m_data, m_currentEntity);
}

Entity EntityView::iterator::operator[](int index)
{
	return Entity(m_data, m_currentEntity + index);
}

bool EntityView::iterator::operator==(iterator other)
{
	return m_currentEntity == other.m_currentEntity;
}

bool EntityView::iterator::operator!=(iterator other)
{
	return m_currentEntity != other.m_currentEntity;
}

EntityView::iterator EntityView::begin() 
{ 
	return iterator(m_data, m_start); 
}

EntityView::iterator EntityView::end()   
{ 
	return iterator(m_data, m_start + m_size); 
}