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-04-23
  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 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