/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: include/sgx/core/xml/xmlbase.hpp

*/

#ifndef SGX_CORE_XML_XMLBASE_HPP
#define SGX_CORE_XML_XMLBASE_HPP	1

//
// Raw functionality for all XML features
//
class sgxXMLBase {
public:
	static void			validate(sgxString &out, const sgxString &text);
	static sgxString	getTab(int tab);
};

//
// Features of an XML tag
//
class sgxXMLAttribute : public sgxXMLBase {
public:
	sgxString		m_Name;
	sgxString		m_Value;	

	sgxXMLAttribute(const sgxString &name, const sgxString &value) 
	{
		m_Name = name;
		m_Value = value;
	}
};

class sgxXMLElement : public sgxXMLBase {
public:
	sgxXMLElement() : m_Name("") { }
	sgxXMLElement(const char *name) : m_Name(name) { }
	sgxXMLElement(const sgxString &name) : m_Name(name) { }

	sgxString		m_Name;
};

//
// Nodes of a DOM tree
//
class sgxXMLNode : public sgxXMLBase {
public:
	sgxXMLElement					m_Element;
	sgxVector<sgxXMLAttribute>		m_Attribute;
	sgxString						m_Data;
	sgxVector<sgxXMLNode *>	m_ChildNodes;

	sgxXMLNode() {}
	~sgxXMLNode();

	sgxXMLNode *getChild(const sgxString &child);
	const sgxXMLNode *getChild(const sgxString &child) const;


	void	setData(const sgxString &data)				{ m_Data = data; }
	void	getData(sgxString &data)					{ data = m_Data; }
	void	appendData(const sgxString &data)			{ m_Data += data; }
	void	setElement(const sgxXMLElement &ele)		{ m_Element = ele; }
	sgxXMLNode *addNode(sgxXMLNode *pNode)				{ m_ChildNodes.push_back(pNode); return m_ChildNodes.back(); }
	void	addAttribute(const sgxXMLAttribute &attr)	{ m_Attribute.push_back(attr); }
	void	addAttribute(const sgxString &name, const sgxString &value)	{ m_Attribute.push_back(sgxXMLAttribute(name,value)); }
	tBOOL	doesAttributeExist(const sgxString &name) const;

	tBOOL	setAttribute(const sgxString &name, tINT32 &value);

	tBOOL	getAttribute(const sgxString &name, sgxString &value) const;
	tBOOL	getAttribute(const sgxString &name, tINT32 &value) const;
	tBOOL	getAttribute(const sgxString &name, tUINT32 &value) const;
	tBOOL	getAttribute(const sgxString &name, tREAL32 &value) const;
	tBOOL	getAttribute(const sgxString &name, sgxString &value, const sgxString &default_string) const;
	tBOOL	getAttribute(const sgxString &name, tINT32 &value, const tINT32 default_value) const;
	tBOOL	getAttribute(const sgxString &name, tUINT32 &value, const tUINT32 default_value) const;
	tBOOL	getAttribute(const sgxString &name, tREAL32 &value, const tREAL32 default_value) const;

private:
	tBOOL	getAttributeImpl(const sgxString &name, sgxString &value) const;
	tBOOL	setAttributeImpl(const sgxString &name, sgxString &value);

};

#endif /* SGX_CORE_XML_XMLBASE_HPP */
