Просмотр исходного кода

Add new line reserve functionality to SectionPairDocument class

Patrick-Christopher Mattulat 1 год назад
Родитель
Сommit
ff420604dc

+ 3 - 1
include/ls-std/io/section-pair/model/SectionPairDocument.hpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-15
-* Changed:         2023-02-16
+* Changed:         2023-02-21
 *
 * */
 
@@ -33,11 +33,13 @@ namespace ls::std::io
       [[nodiscard]] ::std::string getHeader();
       [[nodiscard]] section_pair_document_section_list getSectionList();
       [[nodiscard]] ls::std::core::type::byte_field marshal() override;
+      void reserveNewLine(const ::std::string &_reservedNewLine);
       void unmarshal(const ls::std::core::type::byte_field &_data) override;
 
     private:
 
       const ::std::string header = "# section-pair document";
+      ::std::string reservedNewLine{};
       ls::std::io::section_pair_document_section_list sections{};
       ::std::shared_ptr<ls::std::core::interface_type::ISerializable> serializable{};
 

+ 12 - 1
source/ls-std/io/section-pair/model/SectionPairDocument.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-15
-* Changed:         2023-02-18
+* Changed:         2023-02-21
 *
 * */
 
@@ -73,6 +73,11 @@ ls::std::core::type::byte_field ls::std::io::SectionPairDocument::marshal()
   return this->serializable->marshal();
 }
 
+void ls::std::io::SectionPairDocument::reserveNewLine(const ::std::string &_reservedNewLine)
+{
+  this->reservedNewLine = _reservedNewLine;
+}
+
 void ls::std::io::SectionPairDocument::unmarshal(const ls::std::core::type::byte_field &_data)
 {
   ls::std::core::ConditionalFunctionExecutor{this->serializable == nullptr}.execute([this] { _createSerializable(); });
@@ -91,6 +96,12 @@ void ls::std::io::SectionPairDocument::_createSerializable()
 {
   ls::std::io::SerializableSectionPairParameter parameter{};
   parameter.setValue(shared_from_this());
+
+  if (!this->reservedNewLine.empty())
+  {
+    parameter.setNewLine(this->reservedNewLine);
+  }
+
   this->serializable = ::std::make_shared<ls::std::io::SerializableSectionPairDocument>(parameter);
 }