/***************************************************************************
*                                                                          *
*  Copyright (C) Golaem S.A.  All Rights Reserved.                         *
*                                                                          *
****************************************************************************/
#pragma once

#include "glmAbstractDataFileParser.h"
#include <stack>

namespace rapidxml
{
	template<class Ch> class xml_node;
}

namespace glm
{
	//class TiXmlElement ;

	const int XMLDataFileParser_errorLength = 100;	

	/**
	* \brief Realization of the AbstractDataFileParser class for the tinyXML library
	*
	* \ingroup xml
	* \author Golaem <dev@golaem.com>
	*/
	class GLM_CORE_API XMLDataFileParser : public AbstractDataFileParser
	{
	public:

		/**
		* \brief default constructor
		*/
		XMLDataFileParser() ;

		/**
		* \brief constructor
		*/
		XMLDataFileParser( const char* fileName, DataItem& configurationItem ) ;

		/**
		* \brief destructor
		*/
		virtual ~XMLDataFileParser() ;

		/**
		* read an XML file and convert it to a DataItem hierarchy
		*/
		virtual void read( const char* fileName, DataItem& configurationItem ) ;

		/**
		* read a xml document from a memory buffer and convert it to a DataItem hierarchy
		*/
		virtual void readFromBuffer( const char* buffer, DataItem& configurationItem ) ;

		/**
		* read a xml document from a memory buffer and convert it to a DataItem hierarchy
		*/
		virtual void readFromBuffer( std::istream& buffer, DataItem& configurationItem ) ;

		/**
		* convert a DataItem hierarchy to a XML file
		*/
		virtual SaveXMLDataFileErrorCode::Value write( const char* fileName, DataItem& configurationItem) ;

		/**
		* convert a DataItem hierarchy to a char buffer
		*/
		virtual void writeToBuffer( std::ostream& buffer, DataItem& configurationItem ) ;


	private:

		/**
		* \brief add the children of a TiXmlElement to a DataItem
		*/
		void fromRapidXmlElementToDataItem( DataItem& root, rapidxml::xml_node<char>* element ) ;

		/**
		* \brief add the children of a DataItem to a TiXmlElement
		*/
		void fromDataItemToRapidXmlElement( rapidxml::xml_node<char>* element, const DataItem& root ) ;

		const char* getCharsAfter( char* errorLocation );

		char _tempCharsAfter[XMLDataFileParser_errorLength];
	} ;
}

