XmlNode.hpp 3.9 KB

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