|
@@ -3,24 +3,25 @@
|
|
|
* Company: Lynar Studios
|
|
|
* E-Mail: webmaster@lynarstudios.com
|
|
|
* Created: 2023-02-11
|
|
|
-* Changed: 2023-02-12
|
|
|
+* Changed: 2023-02-13
|
|
|
*
|
|
|
* */
|
|
|
|
|
|
#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
|
|
|
#include <ls-std/io/NewLine.hpp>
|
|
|
+#include <ls-std/io/section-pair/model/SectionPairRow.hpp>
|
|
|
#include <ls-std/io/section-pair/model/SectionPairRowListValue.hpp>
|
|
|
#include <ls-std/io/section-pair/model/SectionPairRowSingleValue.hpp>
|
|
|
#include <ls-std/io/section-pair/serialization/SerializableSectionPairRow.hpp>
|
|
|
|
|
|
-ls::std::io::SerializableSectionPairRow::SerializableSectionPairRow(const ::std::shared_ptr<ls::std::io::SectionPairRow> &_value)
|
|
|
+ls::std::io::SerializableSectionPairRow::SerializableSectionPairRow(const ::std::shared_ptr<ls::std::core::Class> &_value)
|
|
|
{
|
|
|
this->_setValue(_value);
|
|
|
}
|
|
|
|
|
|
ls::std::io::SerializableSectionPairRow::~SerializableSectionPairRow() = default;
|
|
|
|
|
|
-::std::shared_ptr<ls::std::io::SectionPairRow> ls::std::io::SerializableSectionPairRow::getValue()
|
|
|
+::std::shared_ptr<ls::std::core::Class> ls::std::io::SerializableSectionPairRow::getValue()
|
|
|
{
|
|
|
return this->value;
|
|
|
}
|
|
@@ -28,17 +29,19 @@ ls::std::io::SerializableSectionPairRow::~SerializableSectionPairRow() = default
|
|
|
ls::std::core::type::byte_field ls::std::io::SerializableSectionPairRow::marshal()
|
|
|
{
|
|
|
ls::std::core::type::byte_field data = this->_marshalKey();
|
|
|
- return data + this->value->getValue()->marshal();
|
|
|
+ return data + ::std::dynamic_pointer_cast<ls::std::io::SectionPairRow>(this->value)->getValue()->marshal();
|
|
|
}
|
|
|
|
|
|
void ls::std::io::SerializableSectionPairRow::unmarshal(const ls::std::core::type::byte_field &_data)
|
|
|
{
|
|
|
- if (this->value->isSingleValue())
|
|
|
+ ::std::shared_ptr<ls::std::io::SectionPairRow> row = ::std::dynamic_pointer_cast<ls::std::io::SectionPairRow>(this->value);
|
|
|
+
|
|
|
+ if (row->isSingleValue())
|
|
|
{
|
|
|
this->_unmarshalSingleValue(_data);
|
|
|
}
|
|
|
|
|
|
- if (this->value->isList())
|
|
|
+ if (row->isList())
|
|
|
{
|
|
|
this->_unmarshalListValue(_data);
|
|
|
}
|
|
@@ -47,21 +50,22 @@ void ls::std::io::SerializableSectionPairRow::unmarshal(const ls::std::core::typ
|
|
|
::std::string ls::std::io::SerializableSectionPairRow::_marshalKey()
|
|
|
{
|
|
|
::std::string serializedKey{};
|
|
|
+ ::std::shared_ptr<ls::std::io::SectionPairRow> row = ::std::dynamic_pointer_cast<ls::std::io::SectionPairRow>(this->value);
|
|
|
|
|
|
- if (this->value->isSingleValue())
|
|
|
+ if (row->isSingleValue())
|
|
|
{
|
|
|
- serializedKey = this->value->getKey() + "=";
|
|
|
+ serializedKey = row->getKey() + "=";
|
|
|
}
|
|
|
|
|
|
- if (this->value->isList())
|
|
|
+ if (row->isList())
|
|
|
{
|
|
|
- serializedKey = this->value->getKey() + ":" + ls::std::io::NewLine::get();
|
|
|
+ serializedKey = row->getKey() + ":" + ls::std::io::NewLine::get();
|
|
|
}
|
|
|
|
|
|
return serializedKey;
|
|
|
}
|
|
|
|
|
|
-void ls::std::io::SerializableSectionPairRow::_setValue(const ::std::shared_ptr<ls::std::io::SectionPairRow> &_value)
|
|
|
+void ls::std::io::SerializableSectionPairRow::_setValue(const ::std::shared_ptr<ls::std::core::Class> &_value)
|
|
|
{
|
|
|
ls::std::core::NullPointerArgumentEvaluator{_value}.evaluate();
|
|
|
this->value = _value;
|
|
@@ -74,9 +78,10 @@ void ls::std::io::SerializableSectionPairRow::_unmarshalListValue(const ls::std:
|
|
|
|
|
|
if (separatorPosition != ::std::string::npos)
|
|
|
{
|
|
|
- this->value->setKey(_data.substr(0, separatorPosition));
|
|
|
+ ::std::shared_ptr<ls::std::io::SectionPairRow> row = ::std::dynamic_pointer_cast<ls::std::io::SectionPairRow>(this->value);
|
|
|
+ row->setKey(_data.substr(0, separatorPosition));
|
|
|
::std::string::size_type newLinePosition = _data.find(NewLine::get()) + (NewLine::get().size() - 1);
|
|
|
- ::std::dynamic_pointer_cast<ls::std::io::SectionPairRowListValue>(this->value->getValue())->unmarshal(_data.substr(newLinePosition + 1));
|
|
|
+ ::std::dynamic_pointer_cast<ls::std::io::SectionPairRowListValue>(row->getValue())->unmarshal(_data.substr(newLinePosition + 1));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -87,7 +92,8 @@ void ls::std::io::SerializableSectionPairRow::_unmarshalSingleValue(const ls::st
|
|
|
|
|
|
if (position != ::std::string::npos)
|
|
|
{
|
|
|
- this->value->setKey(_data.substr(0, position));
|
|
|
- ::std::dynamic_pointer_cast<ls::std::io::SectionPairRowSingleValue>(this->value->getValue())->unmarshal(_data.substr(position + 1));
|
|
|
+ ::std::shared_ptr<ls::std::io::SectionPairRow> row = ::std::dynamic_pointer_cast<ls::std::io::SectionPairRow>(this->value);
|
|
|
+ row->setKey(_data.substr(0, position));
|
|
|
+ ::std::dynamic_pointer_cast<ls::std::io::SectionPairRowSingleValue>(row->getValue())->unmarshal(_data.substr(position + 1));
|
|
|
}
|
|
|
}
|