XmlNode.hpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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::std::io
  17. {
  18. class LS_STD_DYNAMIC_GOAL XmlNode : public ls::std::core::Class
  19. {
  20. public:
  21. explicit XmlNode(::std::string _name);
  22. ~XmlNode() override = default;
  23. bool addAttributeAfter(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute, const ::std::string &_name);
  24. bool addAttributeBefore(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute, const ::std::string &_name);
  25. bool addAttributeToBeginning(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute);
  26. bool addAttributeToEnd(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute);
  27. bool addChildAfter(const ::std::shared_ptr<ls::std::io::XmlNode> &_child, const ::std::shared_ptr<ls::std::io::XmlNode> &_search);
  28. bool addChildBefore(const ::std::shared_ptr<ls::std::io::XmlNode> &_child, const ::std::shared_ptr<ls::std::io::XmlNode> &_search);
  29. bool addChildToBeginning(const ::std::shared_ptr<ls::std::io::XmlNode> &_child);
  30. bool addChildToEnd(const ::std::shared_ptr<ls::std::io::XmlNode> &_child);
  31. void clearValue();
  32. ::std::list<::std::shared_ptr<ls::std::io::XmlAttribute>> getAttributes();
  33. ::std::list<::std::shared_ptr<ls::std::io::XmlNode>> getChildren();
  34. ::std::list<::std::shared_ptr<ls::std::io::XmlNode>> getChildren(const ::std::string &_name);
  35. ::std::string getName();
  36. ::std::string getValue();
  37. bool hasAttribute(const ::std::string &_name);
  38. bool hasChild(const ::std::string &_name);
  39. bool hasChild(const ::std::shared_ptr<ls::std::io::XmlNode> &_child);
  40. bool removeFirstAttribute();
  41. bool removeLastAttribute();
  42. bool removeFirstChild();
  43. bool removeLastChild();
  44. void setName(const ::std::string &_name);
  45. void setValue(const ::std::string &_value);
  46. ::std::string toXml();
  47. protected:
  48. ::std::string _toXml_(uint8_t _tabSize);
  49. private:
  50. ::std::list<::std::shared_ptr<ls::std::io::XmlAttribute>> attributes{};
  51. ::std::list<::std::shared_ptr<ls::std::io::XmlNode>> children{};
  52. ::std::string name{};
  53. const static uint8_t TAB_SIZE{4};
  54. ::std::string value{};
  55. void _assignName(const ::std::string &_name);
  56. void _assignValue(const ::std::string &_value);
  57. static void _checkIfAttributeReferenceIsValid(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute);
  58. static void _checkIfNameIsNotEmpty(const ::std::string &_name);
  59. static void _checkIfNodeReferenceIsValid(const ::std::shared_ptr<ls::std::io::XmlNode> &_child);
  60. static ::std::string _getTab(uint8_t _tabSize);
  61. bool _hasAttribute(const ::std::string &_name);
  62. bool _hasChild(const ::std::shared_ptr<ls::std::io::XmlNode> &_child);
  63. bool _hasChild(const ::std::string &_name);
  64. ::std::string _toXmlAttributes();
  65. ::std::string _toXmlChildren(uint8_t _tabSize);
  66. ::std::string _toXmlCloseTag();
  67. ::std::string _toXmlOpenTag();
  68. ::std::string _toXmlOpenTagClose();
  69. ::std::string _toXmlValue();
  70. };
  71. }
  72. #endif