XmlNode.hpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-24
  6. * Changed: 2021-07-16
  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. bool removeFirstAttribute();
  40. bool removeLastAttribute();
  41. bool removeFirstChild();
  42. bool removeLastChild();
  43. void setName(const std::string &_name);
  44. void setValue(const 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. void _assignName(const std::string &_name);
  55. void _assignValue(const std::string &_value);
  56. static void _checkIfAttributeReferenceIsValid(const std::shared_ptr<ls_std::XmlAttribute> &_attribute);
  57. static void _checkIfNameIsNotEmpty(const std::string &_name);
  58. static void _checkIfNodeReferenceIsValid(const std::shared_ptr<ls_std::XmlNode> &_child);
  59. static std::string _getTab(uint8_t _tabSize);
  60. bool _hasAttribute(const std::string &_name);
  61. bool _hasChild(const std::shared_ptr<ls_std::XmlNode> &_child);
  62. bool _hasChild(const std::string &_name);
  63. std::string _toXmlAttributes();
  64. std::string _toXmlChildren(uint8_t _tabSize);
  65. std::string _toXmlCloseTag();
  66. std::string _toXmlOpenTag();
  67. std::string _toXmlOpenTagClose();
  68. std::string _toXmlValue();
  69. };
  70. }
  71. #endif