XmlNode.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-24
  6. * Changed: 2024-05-25
  7. *
  8. * */
  9. #ifndef LS_STD_XML_NODE_HPP
  10. #define LS_STD_XML_NODE_HPP
  11. #include "XmlAttribute.hpp"
  12. #include <list>
  13. #include <ls-std/core/Class.hpp>
  14. #include <ls-std/os/dynamic-goal.hpp>
  15. #include <memory>
  16. /*
  17. * @class(name: 'XmlNode', package: 'io')
  18. * */
  19. namespace ls::std::io
  20. {
  21. class LS_STD_DYNAMIC_GOAL XmlNode : public ls::std::core::Class
  22. {
  23. public:
  24. explicit XmlNode(::std::string _name);
  25. ~XmlNode() noexcept override;
  26. bool addAttributeAfter(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute, const ::std::string &_name); // nodiscard is optional here
  27. bool addAttributeBefore(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute, const ::std::string &_name); // nodiscard is optional here
  28. bool addAttributeToBeginning(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute); // nodiscard is optional here
  29. bool addAttributeToEnd(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute); // nodiscard is optional here
  30. bool addChildAfter(const ::std::shared_ptr<ls::std::io::XmlNode> &_child, const ::std::shared_ptr<ls::std::io::XmlNode> &_search); // nodiscard is optional here
  31. bool addChildBefore(const ::std::shared_ptr<ls::std::io::XmlNode> &_child, const ::std::shared_ptr<ls::std::io::XmlNode> &_search); // nodiscard is optional here
  32. bool addChildToBeginning(const ::std::shared_ptr<ls::std::io::XmlNode> &_child); // nodiscard is optional here
  33. bool addChildToEnd(const ::std::shared_ptr<ls::std::io::XmlNode> &_child); // nodiscard is optional here
  34. void clearValue();
  35. [[nodiscard]] ::std::list<::std::shared_ptr<ls::std::io::XmlAttribute>> getAttributes() const;
  36. [[nodiscard]] ::std::list<::std::shared_ptr<ls::std::io::XmlNode>> getChildren() const;
  37. [[nodiscard]] ::std::list<::std::shared_ptr<ls::std::io::XmlNode>> getChildren(const ::std::string &_name);
  38. [[nodiscard]] ::std::string getName() const;
  39. [[nodiscard]] ::std::string getValue() const;
  40. [[nodiscard]] bool hasAttribute(const ::std::string &_name);
  41. [[nodiscard]] bool hasChild(const ::std::string &_name);
  42. [[nodiscard]] bool hasChild(const ::std::shared_ptr<ls::std::io::XmlNode> &_child);
  43. bool removeFirstAttribute(); // nodiscard is optional here
  44. bool removeLastAttribute(); // nodiscard is optional here
  45. bool removeFirstChild(); // nodiscard is optional here
  46. bool removeLastChild(); // nodiscard is optional here
  47. void setName(const ::std::string &_name);
  48. void setValue(const ::std::string &_value);
  49. [[nodiscard]] ::std::string toXml();
  50. protected:
  51. ::std::string _toXml_(uint8_t _tabSize);
  52. private:
  53. ::std::list<::std::shared_ptr<ls::std::io::XmlAttribute>> attributes{};
  54. ::std::list<::std::shared_ptr<ls::std::io::XmlNode>> children{};
  55. ::std::string name{};
  56. const static uint8_t TAB_SIZE{4};
  57. ::std::string value{};
  58. void _assignName(const ::std::string &_name);
  59. void _assignValue(const ::std::string &_value);
  60. [[nodiscard]] static ::std::string _getTab(uint8_t _tabSize);
  61. [[nodiscard]] bool _hasAttribute(const ::std::string &_name);
  62. [[nodiscard]] bool _hasChild(const ::std::shared_ptr<ls::std::io::XmlNode> &_child);
  63. [[nodiscard]] bool _hasChild(const ::std::string &_name);
  64. [[nodiscard]] ::std::string _toXmlAttributes();
  65. [[nodiscard]] ::std::string _toXmlChildren(uint8_t _tabSize);
  66. [[nodiscard]] ::std::string _toXmlCloseTag() const;
  67. [[nodiscard]] ::std::string _toXmlOpenTag() const;
  68. [[nodiscard]] ::std::string _toXmlOpenTagClose() const;
  69. [[nodiscard]] ::std::string _toXmlValue() const;
  70. };
  71. }
  72. #endif