/*
 * D2F
 * Copyright (C) SatisKia. All rights reserved.
 */

#include "_Global.h"

class _Vector
{
	var _obj:Array;
	var _num:Number;

	function _Vector( len:Number )
	{
		_obj = new Array( len );
		_num = 0;
	}

	function size():Number
	{
		return _num;
	}

	function isEmpty():Boolean
	{
		return (_num == 0) ? true : false;
	}

	function elementAt( index:Number ):Object
	{
		return _obj[index];
	}

	function firstElement():Object
	{
		return _obj[0];
	}

	function lastElement():Object
	{
		return _obj[_num - 1];
	}

	function setElementAt( obj:Object, index:Number ):Void
	{
		if( (index >= 0) && (index < _num) )
		{
			_obj[index] = obj;
		}
	}

	function removeElementAt( index:Number ):Void
	{
		if( (index >= 0) && (index < _num) )
		{
			var i:Number;
			for( i = index; i < (_num - 1); i++ )
			{
				_obj[i] = _obj[i + 1];
			}
			_num--;
		}
	}

	function insertElementAt( obj:Object, index:Number ):Void
	{
		if( (index >= 0) && (index < _num) )
		{
			var i:Number;
			for( i = (_num - 1); i >= index; i-- )
			{
				_obj[i + 1] = _obj[i];
			}
			_obj[index] = obj;
			_num++;
		}
	}

	function addElement( obj:Object ):Void
	{
		_obj[_num] = obj;
		_num++;
	}

	function removeAllElements():Void
	{
		_num = 0;
	}
}
