-----------------------------------------------------------------------------
--
-- ObjectQueue.lua
--
-- ObjectQueue is a lua class that can be used as a FIFO queue of any kind
-- of lua variable.  Its exposed methods are;
--
--	local q = ObjectQueue()			Constructor
--
--	q.clear()				Removes all items from the
--						queue (they are lost)
--
--	local itemFromFront = q.popFront()	Reads the first item off the
--						front of the queue and
--						removes it
--
--	q.pushBack(itemToBack)			Writes itemToBack at the end
--						of the FIFO
--
--	local numItems = q.queueLength()	Returns the number of items
--						in the queue
--
--	local stringRep = q.toString()		Shows the number of items
--						in the queue as a string
--						(also used by the metamethod)
--
-----------------------------------------------------------------------------

function ObjectQueue()

	local meta = { }
	meta.__index = meta
	meta.__tostring =	function(obj)
					return obj.toString()
				end
	local o = { }
	setmetatable(o, meta)
	local self = { tab = { } }
	local clear =		function()
					self.tab = { }
				end
	local popFront =	function()
					local result
					if #self.tab ~= 0 then
						result = self.tab[1]
						table.remove(self.tab, 1)
					end
					return result
				end
	local pushBack =	function(obj)
					if obj == nil then error("ObjectQueue.pushBack: object cannot be nil") end
					table.insert(self.tab, obj)
				end
	local queueLength =	function()
					return #self.tab
				end
	local toString =	function()
					local result = "(ObjectQueue) "..tostring(o.queueLength()).." items"
					return result
				end
	o.clear = clear
	o.popFront = popFront
	o.pushBack = pushBack
	o.queueLength = queueLength
	o.toString = toString
	return o
	
end

