SerializableXMLStateConnection.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-20
  6. * Changed: 2020-09-20
  7. *
  8. * *//*
  9. #include "SerializableXMLStateConnection.hpp"
  10. #include "../../../boxing/String.hpp"
  11. #include "../../../boxing/Boolean.hpp"
  12. ls_std::SerializableXMLStateConnection::SerializableXMLStateConnection(std::shared_ptr<StateConnection> _value) :
  13. Class("SerializableXMLStateConnection"),
  14. value(std::move(_value))
  15. {}
  16. ls_std::byte_field ls_std::SerializableXMLStateConnection::marshal()
  17. {
  18. this->_update();
  19. tinyxml2::XMLPrinter printer {};
  20. this->document.Print(&printer);
  21. return ls_std::byte_field(printer.CStr());
  22. }
  23. void ls_std::SerializableXMLStateConnection::unmarshal(const ls_std::byte_field &_data)
  24. {
  25. ls_std::String data {_data};
  26. this->document.Parse(data.getByteData().data());
  27. this->_unmarshalConnectionId();
  28. this->_unmarshalCondition();
  29. this->_unmarshalId();
  30. }
  31. std::shared_ptr<ls_std::StateConnection> ls_std::SerializableXMLStateConnection::getValue()
  32. {
  33. return this->value;
  34. }
  35. void ls_std::SerializableXMLStateConnection::setValue(std::shared_ptr<StateConnection> _value)
  36. {
  37. this->value = std::move(_value);
  38. this->_clear();
  39. }
  40. void ls_std::SerializableXMLStateConnection::_clear()
  41. {
  42. this->document.Clear();
  43. }
  44. void ls_std::SerializableXMLStateConnection::_unmarshalCondition()
  45. {
  46. ls_std::Boolean condition {};
  47. const tinyxml2::XMLAttribute *attribute = this->document.RootElement()->FindAttribute("condition");
  48. if(attribute != nullptr) {
  49. condition.parse(attribute->Value());
  50. this->value->updatePassCondition(condition.getValue());
  51. }
  52. }
  53. void ls_std::SerializableXMLStateConnection::_unmarshalConnectionId()
  54. {
  55. const tinyxml2::XMLAttribute *attribute = this->document.RootElement()->FindAttribute("connectionId");
  56. if(attribute != nullptr) {
  57. this->value->setConnectionId(attribute->Value());
  58. }
  59. }
  60. void ls_std::SerializableXMLStateConnection::_unmarshalId()
  61. {
  62. const tinyxml2::XMLAttribute *attribute = this->document.RootElement()->FindAttribute("id");
  63. if(attribute != nullptr) {
  64. this->value->setStateId(attribute->Value());
  65. }
  66. }
  67. void ls_std::SerializableXMLStateConnection::_update()
  68. {
  69. this->_clear();
  70. tinyxml2::XMLNode* root = this->document.NewElement("connection");
  71. this->document.InsertFirstChild(root);
  72. root->ToElement()->SetAttribute("connectionId", this->value->getConnectionId().c_str());
  73. root->ToElement()->SetAttribute("id", this->value->getStateId().c_str());
  74. root->ToElement()->SetAttribute("condition", this->value->isPassable());
  75. }
  76. */