XmlNode.hpp 2.7 KB

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