XmlDocument.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-30
  6. * Changed: 2023-05-17
  7. *
  8. * */
  9. #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
  10. #include <ls-std/io/xml/XmlDocument.hpp>
  11. using ls::std::core::Class;
  12. using ls::std::core::NullPointerArgumentEvaluator;
  13. using ls::std::io::XmlDeclaration;
  14. using ls::std::io::XmlDocument;
  15. using ls::std::io::XmlNode;
  16. using std::shared_ptr;
  17. using std::string;
  18. XmlDocument::XmlDocument() : Class("XmlDocument")
  19. {}
  20. XmlDocument::~XmlDocument() noexcept = default;
  21. shared_ptr<XmlDeclaration> XmlDocument::getDeclaration() const
  22. {
  23. return this->declaration;
  24. }
  25. shared_ptr<XmlNode> XmlDocument::getRootElement() const
  26. {
  27. return this->rootElement;
  28. }
  29. void XmlDocument::setDeclaration(const shared_ptr<XmlDeclaration> &_declaration)
  30. {
  31. this->_assignDeclaration(_declaration);
  32. }
  33. void XmlDocument::setRootElement(const shared_ptr<XmlNode> &_rootElement)
  34. {
  35. this->_assignRootElement(_rootElement);
  36. }
  37. string XmlDocument::toXml() const
  38. {
  39. string xmlString{};
  40. if (this->declaration != nullptr)
  41. {
  42. xmlString = this->declaration->toXml();
  43. if (!xmlString.empty())
  44. {
  45. xmlString += "\n";
  46. }
  47. }
  48. return xmlString + this->rootElement->toXml();
  49. }
  50. void XmlDocument::_assignDeclaration(const shared_ptr<XmlDeclaration> &_declaration)
  51. {
  52. NullPointerArgumentEvaluator{_declaration, "xml declaration reference is null!"}.evaluate();
  53. this->declaration = _declaration;
  54. }
  55. void XmlDocument::_assignRootElement(const shared_ptr<XmlNode> &_rootElement)
  56. {
  57. NullPointerArgumentEvaluator{_rootElement, "xml root node reference is null!"}.evaluate();
  58. this->rootElement = _rootElement;
  59. }