Browse Source

Add prototype implementation for SectionPairRow class

Patrick-Christopher Mattulat 2 years ago
parent
commit
5589c9e674

+ 2 - 0
CMakeLists.txt

@@ -166,6 +166,7 @@ set(SOURCE_FILES_IO
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/kv/KvParser.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/logging/Logger.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/logging/LogLevel.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairRow.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/xml/XmlAttribute.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/xml/XmlDeclaration.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/xml/XmlDocument.cpp
@@ -244,6 +245,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/kv/KvParserTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/logging/LoggerTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/logging/LogLevelTest.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairRowTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlAttributeTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlDeclarationTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlDocumentTest.cpp

+ 40 - 0
include/ls-std/io/section-pair/SectionPairRow.hpp

@@ -0,0 +1,40 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-08
+* Changed:         2023-02-08
+*
+* */
+
+#ifndef LS_STD_SECTION_PAIR_ROW_HPP
+#define LS_STD_SECTION_PAIR_ROW_HPP
+
+#include "SectionPairRowEnumType.hpp"
+#include <list>
+#include <ls-std/core/Class.hpp>
+#include <string>
+
+namespace ls::std::io
+{
+  class SectionPairRow : public ls::std::core::Class
+  {
+    public:
+
+      explicit SectionPairRow(const ::std::string &_key);
+      ~SectionPairRow() override;
+
+      [[nodiscard]] ::std::string getValue();
+      [[nodiscard]] bool isKeyValue();
+      [[nodiscard]] bool isList();
+      void setValue(const ::std::string &_value);
+
+    private:
+
+      ::std::string key{};
+      ls::std::io::SectionPairRowEnumType type{};
+      ::std::list<::std::string> values{};
+  };
+}
+
+#endif

+ 23 - 0
include/ls-std/io/section-pair/SectionPairRowEnumType.hpp

@@ -0,0 +1,23 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-08
+* Changed:         2023-02-08
+*
+* */
+
+#ifndef LS_STD_SECTION_PAIR_ROW_ENUM_TYPE_HPP
+#define LS_STD_SECTION_PAIR_ROW_ENUM_TYPE_HPP
+
+namespace ls::std::io
+{
+  enum SectionPairRowEnumType
+  {
+    SECTION_PAIR_ROW_NOT_IMPLEMENTED = 0,
+    SECTION_PAIR_ROW_LIST,
+    SECTION_PAIR_ROW_KEY_VALUE
+  };
+}
+
+#endif

+ 4 - 1
include/ls-std/ls-std-io.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2022-05-14
- * Changed:         2023-02-04
+ * Changed:         2023-02-08
  *
  * */
 
@@ -20,6 +20,9 @@
 #include <ls-std/io/logging/LogLevelValue.hpp>
 #include <ls-std/io/logging/Logger.hpp>
 
+#include <ls-std/io/section-pair/SectionPairRow.hpp>
+#include <ls-std/io/section-pair/SectionPairRowEnumType.hpp>
+
 #include <ls-std/io/xml/XmlAttribute.hpp>
 #include <ls-std/io/xml/XmlDeclaration.hpp>
 #include <ls-std/io/xml/XmlDocument.hpp>

+ 44 - 0
source/ls-std/io/section-pair/SectionPairRow.cpp

@@ -0,0 +1,44 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-08
+* Changed:         2023-02-08
+*
+* */
+
+#include <ls-std/io/section-pair/SectionPairRow.hpp>
+
+ls::std::io::SectionPairRow::SectionPairRow(const ::std::string &_key) : ls::std::core::Class("SectionPairRow")
+{
+  //ls::std::io::SectionPairRowKeyArgumentEvaluator{_key}.evaluate();
+  this->key = _key;
+}
+
+ls::std::io::SectionPairRow::~SectionPairRow() = default;
+
+::std::string ls::std::io::SectionPairRow::getValue()
+{
+  return this->values.empty() ? "" : this->values.front();
+}
+
+bool ls::std::io::SectionPairRow::isKeyValue()
+{
+  return this->type == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_KEY_VALUE;
+}
+
+bool ls::std::io::SectionPairRow::isList()
+{
+  return this->type == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_LIST;
+}
+
+void ls::std::io::SectionPairRow::setValue(const ::std::string &_value)
+{
+  //ls::std::core::EmptyStringArgumentEvaluator{_value}.evaluate();
+  if (!this->values.empty())
+  {
+    this->values.pop_front();
+  }
+
+  this->values.push_back(_value);
+}

+ 62 - 0
test/cases/io/section-pair/SectionPairRowTest.cpp

@@ -0,0 +1,62 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-08
+* Changed:         2023-02-08
+*
+* */
+
+#include <gtest/gtest.h>
+#include <ls-std/ls-std-core.hpp>
+#include <ls-std/ls-std-io.hpp>
+
+using namespace ls::std::core;
+using namespace ls::std::io;
+using namespace ::std;
+
+namespace
+{
+  class SectionPairRowTest : public ::testing::Test
+  {
+    protected:
+
+      SectionPairRowTest() = default;
+      ~SectionPairRowTest() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(SectionPairRowTest, getClassName)
+  {
+    ASSERT_STREQ("SectionPairRow", SectionPairRow{"TMP_KEY"}.getClassName().c_str());
+  }
+
+  TEST_F(SectionPairRowTest, getValue)
+  {
+    SectionPairRow row{"TMP_KEY"};
+    ASSERT_TRUE(row.getValue().empty());
+  }
+
+  TEST_F(SectionPairRowTest, isKeyValue)
+  {
+    ASSERT_FALSE(SectionPairRow{"TMP_KEY"}.isKeyValue());
+  }
+
+  TEST_F(SectionPairRowTest, isList)
+  {
+    ASSERT_FALSE(SectionPairRow{"TMP_KEY"}.isList());
+  }
+
+  TEST_F(SectionPairRowTest, setValue_key_value)
+  {
+    SectionPairRow row{"color"};
+    row.setValue("blue");
+
+    ASSERT_STREQ("blue", row.getValue().c_str());
+  }
+}