XmlNode.hpp 3.6 KB

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