XMLNode.hpp 2.6 KB

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