/*!
 	@file 
 	@brief	ＸＭＬ読み込みクラス
 */

#ifndef CXMLReader_h
#define CXMLReader_h

#include"../../Setup/CompileMode.h"
#include"../Macro.h"

#include"CXMLNode.h"
#include"CXMLDocument.h"

#include<stack>

namespace Maid
{
	class CXMLReader
	{
	public:
		void Load( const mstring& FileName );
		void LoadText( const MySTL::vector<unt08>& TextImage  );

		void NextNode();
		bool IsEndNode();
		void AscendNode();
		void DescendNode();

		bool IsTopNode();

		enum NODETYPE
		{
			NODETYPE_EMPTY,		//	改行のみとか空っぽ
			NODETYPE_ELEMENT,	//	データがある<a>cccc</a> 等
			NODETYPE_TAG,		//	子持ちデータ<a>・・・(中にいろいろある)・・・</a> 等
		};

		NODETYPE GetNodeType()const;


		mstring GetNodeName()const;
		mstring GetString()const;
		int GetInteger()const;
		float GetFloat()const;
		CXMLText GetAttribute( const mstring& Name )const;

	private:
		CXMLNode& GetCurrentNode()const;
		CXMLNode& GetTextNode( CXMLNode& parent )const;

	private:
		CXMLDocument	m_Docment;

		struct NODESTACK
		{
			NODESTACK( CXMLNode& n )
				:ParentNode(n)
			{

				ChildPos = 0;
			}

			CXMLNode& ParentNode;
			int	ChildPos;
		};

		MySTL::stack<NODESTACK>	m_ParentStack;
	};

	class CXMLReaderAutoDescend_base
	{
	public:
		CXMLReaderAutoDescend_base( CXMLReader& r )
			:m_Reader(r)
		{
			m_Reader.AscendNode();
		}

		~CXMLReaderAutoDescend_base()
		{
			m_Reader.DescendNode();
		}
	private:
		CXMLReader& m_Reader;
	};

	#define CXMLReaderAutoDescend2( a, writer ) CXMLReaderAutoDescend_base p##a(writer)
	#define CXMLReaderAutoDescend( writer )  CXMLReaderAutoDescend2(__LINE__, writer)

}
#endif
