/* * Author: Patrick-Christopher Mattulat * Company: Lynar Studios * E-Mail: webmaster@lynarstudios.com * Created: 2020-09-24 * Changed: 2023-02-08 * * */ #ifndef LS_STD_XML_NODE_HPP #define LS_STD_XML_NODE_HPP #include "XmlAttribute.hpp" #include #include #include #include namespace ls::std::io { class LS_STD_DYNAMIC_GOAL XmlNode : public ls::std::core::Class { public: explicit XmlNode(::std::string _name); ~XmlNode() override; bool addAttributeAfter(const ::std::shared_ptr &_attribute, const ::std::string &_name); // nodiscard is optional here bool addAttributeBefore(const ::std::shared_ptr &_attribute, const ::std::string &_name); // nodiscard is optional here bool addAttributeToBeginning(const ::std::shared_ptr &_attribute); // nodiscard is optional here bool addAttributeToEnd(const ::std::shared_ptr &_attribute); // nodiscard is optional here bool addChildAfter(const ::std::shared_ptr &_child, const ::std::shared_ptr &_search); // nodiscard is optional here bool addChildBefore(const ::std::shared_ptr &_child, const ::std::shared_ptr &_search); // nodiscard is optional here bool addChildToBeginning(const ::std::shared_ptr &_child); // nodiscard is optional here bool addChildToEnd(const ::std::shared_ptr &_child); // nodiscard is optional here void clearValue(); [[nodiscard]] ::std::list<::std::shared_ptr> getAttributes(); [[nodiscard]] ::std::list<::std::shared_ptr> getChildren(); [[nodiscard]] ::std::list<::std::shared_ptr> getChildren(const ::std::string &_name); [[nodiscard]] ::std::string getName(); [[nodiscard]] ::std::string getValue(); [[nodiscard]] bool hasAttribute(const ::std::string &_name); [[nodiscard]] bool hasChild(const ::std::string &_name); [[nodiscard]] bool hasChild(const ::std::shared_ptr &_child); bool removeFirstAttribute(); // nodiscard is optional here bool removeLastAttribute(); // nodiscard is optional here bool removeFirstChild(); // nodiscard is optional here bool removeLastChild(); // nodiscard is optional here void setName(const ::std::string &_name); void setValue(const ::std::string &_value); [[nodiscard]] ::std::string toXml(); protected: ::std::string _toXml_(uint8_t _tabSize); private: ::std::list<::std::shared_ptr> attributes{}; ::std::list<::std::shared_ptr> children{}; ::std::string name{}; const static uint8_t TAB_SIZE{4}; ::std::string value{}; void _assignName(const ::std::string &_name); void _assignValue(const ::std::string &_value); [[nodiscard]] static ::std::string _getTab(uint8_t _tabSize); [[nodiscard]] bool _hasAttribute(const ::std::string &_name); [[nodiscard]] bool _hasChild(const ::std::shared_ptr &_child); [[nodiscard]] bool _hasChild(const ::std::string &_name); [[nodiscard]] ::std::string _toXmlAttributes(); [[nodiscard]] ::std::string _toXmlChildren(uint8_t _tabSize); [[nodiscard]] ::std::string _toXmlCloseTag(); [[nodiscard]] ::std::string _toXmlOpenTag(); [[nodiscard]] ::std::string _toXmlOpenTagClose(); [[nodiscard]] ::std::string _toXmlValue(); }; } #endif