XmlDocument.cpp 1.8 KB

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