XmlNode.hpp 3.6 KB

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