12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- /*
- * Author: Patrick-Christopher Mattulat
- * Company: Lynar Studios
- * E-Mail: webmaster@lynarstudios.com
- * Created: 2020-09-24
- * Changed: 2024-09-13
- *
- * */
- #ifndef LS_STD_XML_NODE_HPP
- #define LS_STD_XML_NODE_HPP
- #include "XmlAttribute.hpp"
- #include <list>
- #include <ls-std/core/Class.hpp>
- #include <ls-std/os/dynamic-goal.hpp>
- #include <memory>
- /*
- * @doc: class(name: 'XmlNode', package: 'io')
- * @doc: io.XmlNode.description('This class represents an XML node and can be serialized to an XML tree.')
- * */
- namespace ls::std::io
- {
- class LS_STD_DYNAMIC_GOAL XmlNode : public ls::std::core::Class
- {
- public:
- explicit XmlNode(::std::string _name);
- ~XmlNode() noexcept override;
- bool addAttributeAfter(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute, const ::std::string &_name); // nodiscard is optional here
- bool addAttributeBefore(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute, const ::std::string &_name); // nodiscard is optional here
- bool addAttributeToBeginning(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute); // nodiscard is optional here
- bool addAttributeToEnd(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute); // nodiscard is optional here
- bool addChildAfter(const ::std::shared_ptr<ls::std::io::XmlNode> &_child, const ::std::shared_ptr<ls::std::io::XmlNode> &_search); // nodiscard is optional here
- bool addChildBefore(const ::std::shared_ptr<ls::std::io::XmlNode> &_child, const ::std::shared_ptr<ls::std::io::XmlNode> &_search); // nodiscard is optional here
- bool addChildToBeginning(const ::std::shared_ptr<ls::std::io::XmlNode> &_child); // nodiscard is optional here
- bool addChildToEnd(const ::std::shared_ptr<ls::std::io::XmlNode> &_child); // nodiscard is optional here
- void clearValue();
- [[nodiscard]] ::std::list<::std::shared_ptr<ls::std::io::XmlAttribute>> getAttributes() const;
- [[nodiscard]] ::std::list<::std::shared_ptr<ls::std::io::XmlNode>> getChildren() const;
- [[nodiscard]] ::std::list<::std::shared_ptr<ls::std::io::XmlNode>> getChildren(const ::std::string &_name);
- [[nodiscard]] ::std::string getName() const;
- [[nodiscard]] ::std::string getValue() const;
- [[nodiscard]] bool hasAttribute(const ::std::string &_name);
- [[nodiscard]] bool hasChild(const ::std::string &_name);
- [[nodiscard]] bool hasChild(const ::std::shared_ptr<ls::std::io::XmlNode> &_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<ls::std::io::XmlAttribute>> attributes{};
- ::std::list<::std::shared_ptr<ls::std::io::XmlNode>> 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<ls::std::io::XmlNode> &_child);
- [[nodiscard]] bool _hasChild(const ::std::string &_name);
- [[nodiscard]] ::std::string _toXmlAttributes();
- [[nodiscard]] ::std::string _toXmlChildren(uint8_t _tabSize);
- [[nodiscard]] ::std::string _toXmlCloseTag() const;
- [[nodiscard]] ::std::string _toXmlOpenTag() const;
- [[nodiscard]] ::std::string _toXmlOpenTagClose() const;
- [[nodiscard]] ::std::string _toXmlValue() const;
- };
- }
- #endif
|