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

#pragma once

#include "glmFileName.h"
#include "glmTypes.h"

namespace glm
{
	class DataItem ;

	/**
	* \brief Abstract class for configuration file parsers.
	*
	* This class groups together common functionnalities for configuration file parsers, i.e. being able to 
	* use a file in order to fill a DataItems tree. This reduces the dependencies between an application
	* and the configuration file format; currently, the only supported file format by glmSystem is XML, as handled by the 
	* XMLDataFileParser. However, if another file format was to be chosen, we would only have to define 
	* a new class for this format.
	*
	* \ingroup dataItem
	* \author Golaem <dev@golaem.com>
	*/
	class GLM_CORE_API AbstractDataFileParser
	{
	public:

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

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

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

		/**
		* \brief get accessor to the current file name
		* \return the current file name
		*/
		const FileName& getFileName() const ;

	protected:

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

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

		/**
		* \brief set accessor to the current file name
		* \param fileName the current fileName
		*/
		void setFileName( const FileName& fileName ) ;

	private:

		/**
		* \brief copy constructor
		*/
		AbstractDataFileParser( const AbstractDataFileParser& fileParser ) ;

		/**
		* \brief assignment operator
		*/
		const AbstractDataFileParser& operator=( const AbstractDataFileParser& fileParser ) ;

		/// name of the parsed file
		FileName _fileName ;
	} ;

	//-------------------------------------------------------------------------
	// getFileName()
	//-------------------------------------------------------------------------
	inline const FileName& 
		AbstractDataFileParser::getFileName() const
	{
		return _fileName ;
	}

	//-------------------------------------------------------------------------
	// setFileName()
	//-------------------------------------------------------------------------
	inline void
		AbstractDataFileParser::setFileName( const FileName& fileName )
	{
		_fileName = fileName ;
	}
}

