/*
PolyGun

Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef POLYGUN_XML_XML_NODE_HPP
#define POLYGUN_XML_XML_NODE_HPP

#include <string>
#include <vector>
#include <map>

namespace polygun::xml {
	class XMLNode final {
	public:
		XMLNode(const std::string& name);
		XMLNode();
		~XMLNode();

		void set_name(const std::string& name) { m_name = name; }
		const std::string& get_name() const { return m_name; }

		void add_attribute(const std::string& name, const std::string& value) { m_attributes[name] = value; }
		bool has_attribute(const std::string& name) const { return m_attributes.count(name)>0; }
		const std::string* get_attribute(const std::string& name);

		void set_text(const std::string& text) { m_text = text; }
		const std::string& get_text() const { return m_text; }

		void add_node(XMLNode* node) { m_subnodes.push_back(node); }
		XMLNode* next_node();
		XMLNode* next_node(const std::string& name);

	private:
		std::string m_name;
		std::map<std::string, std::string> m_attributes;
		std::string m_text;
		std::vector<XMLNode*> m_subnodes;
		size_t m_subnode_reading_counter;
		std::map<std::string, size_t> m_named_subnode_reading_counters;
	};
}

#endif // POLYGUN_XML_XML_NODE_HPP
