/*  $Id: dom_named_node_map.cpp,v 1.5 2004/04/15 00:02:12 grumbel Exp $
**
**  ClanLib Game SDK
**  Copyright (C) 2003  The ClanLib Team
**  For a total list of contributers see the file CREDITS.
**
**  This library is free software; you can redistribute it and/or
**  modify it under the terms of the GNU Lesser General Public
**  License as published by the Free Software Foundation; either
**  version 2.1 of the License, or (at your option) any later version.
**
**  This library is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
**  Lesser General Public License for more details.
**
**  You should have received a copy of the GNU Lesser General Public
**  License along with this library; if not, write to the Free Software
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*/

#include "Core/precomp.h"
#include "API/Core/System/cl_assert.h"
#include "Core/XML/dom_named_node_map_generic.h"
#include "API/Core/XML/dom_named_node_map.h"
#include "API/Core/XML/dom_attr.h"
#include "API/Core/XML/dom_node.h"

/////////////////////////////////////////////////////////////////////////////
// CL_DomNamedNodeMap construction:

CL_DomNamedNodeMap::CL_DomNamedNodeMap()
{
	impl = new CL_DomNamedNodeMap_Generic();
}

CL_DomNamedNodeMap::CL_DomNamedNodeMap(CL_DomNode &node)
{
	// FIXME: Not sure what this should do
	cl_assert(0);
}

CL_DomNamedNodeMap::~CL_DomNamedNodeMap()
{
}

/////////////////////////////////////////////////////////////////////////////
// CL_DomNamedNodeMap attributes:

int CL_DomNamedNodeMap::get_length() const
{
	return impl->attributes.size();
}

/////////////////////////////////////////////////////////////////////////////
// CL_DomNamedNodeMap operations:

CL_DomNode CL_DomNamedNodeMap::get_named_item(const std::string &name) const
{
	int size = impl->attributes.size();
	for (int i=0; i<size; i++)
	{
		if (impl->attributes[i].first == name)
		{
			return CL_DomNode(impl->attributes[i].second);
		}
	}
	return CL_DomNode();
}

CL_DomNode CL_DomNamedNodeMap::set_named_item(const CL_DomNode &node)
{
	int size = impl->attributes.size();
	for (int i=0; i<size; i++)
	{
		if (impl->attributes[i].first == node.to_attr().get_name())
		{
			CL_DomNode oldnode(impl->attributes[i].second);
			impl->attributes[i].second = node;
			return oldnode;
		}
	}
	
	impl->attributes.push_back(std::pair<std::string, CL_DomNode>(node.to_attr().get_name(), node));

	return CL_DomNode();
}

CL_DomNode CL_DomNamedNodeMap::remove_named_item(const std::string &name)
{
	// FIXME: Implement me
	return CL_DomNode();
}

CL_DomNode CL_DomNamedNodeMap::item(unsigned long index) const
{
	return CL_DomNode(impl->attributes[index].second);
}

/////////////////////////////////////////////////////////////////////////////
// CL_DomNamedNodeMap implementation:
