ソースを参照

Add SectionPairRowListValue member to SectionPairRow class

Patrick-Christopher Mattulat 2 年 前
コミット
59ac11b4e2

+ 2 - 0
CMakeLists.txt

@@ -177,6 +177,7 @@ set(SOURCE_FILES_IO
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairIdentifierArgumentEvaluator.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairIdentifierValidator.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairRow.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairRowListValue.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairRowSingleValue.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairRowValue.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.cpp
@@ -267,6 +268,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/logging/LogLevelTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairIdentifierArgumentEvaluatorTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairIdentifierValidatorTest.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairRowListValueTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairRowSingleValueTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairRowTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairRowValueArgumentEvaluatorTest.cpp

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

@@ -15,7 +15,7 @@ namespace ls::std::io
   enum SectionPairRowEnumType
   {
     SECTION_PAIR_ROW_NOT_IMPLEMENTED = 0,
-    SECTION_PAIR_ROW_LIST,
+    SECTION_PAIR_ROW_LIST_VALUE,
     SECTION_PAIR_ROW_SINGLE_VALUE
   };
 }

+ 38 - 0
include/ls-std/io/section-pair/SectionPairRowListValue.hpp

@@ -0,0 +1,38 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-10
+* Changed:         2023-02-10
+*
+* */
+
+#ifndef LS_STD_SECTION_PAIR_ROW_LIST_VALUE_HPP
+#define LS_STD_SECTION_PAIR_ROW_LIST_VALUE_HPP
+
+#include "SectionPairRowValue.hpp"
+#include "SectionPairTypes.hpp"
+#include <list>
+#include <ls-std/core/Class.hpp>
+
+namespace ls::std::io
+{
+  class SectionPairRowListValue : public ls::std::core::Class, public ls::std::io::SectionPairRowValue
+  {
+    public:
+
+      SectionPairRowListValue();
+      ~SectionPairRowListValue() override;
+
+      void add(const ls::std::io::section_pair_row_value &_value);
+      [[nodiscard]] ls::std::io::section_pair_row_value get(size_t _index);
+      [[nodiscard]] size_t getSize();
+      [[nodiscard]] ls::std::io::SectionPairRowEnumType getType() override;
+
+    private:
+
+      ::std::list<ls::std::io::section_pair_row_value> values{};
+  };
+}
+
+#endif

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

@@ -24,6 +24,7 @@
 #include <ls-std/io/section-pair/SectionPairIdentifierValidator.hpp>
 #include <ls-std/io/section-pair/SectionPairRow.hpp>
 #include <ls-std/io/section-pair/SectionPairRowEnumType.hpp>
+#include <ls-std/io/section-pair/SectionPairRowListValue.hpp>
 #include <ls-std/io/section-pair/SectionPairRowSingleValue.hpp>
 #include <ls-std/io/section-pair/SectionPairRowValue.hpp>
 #include <ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.hpp>

+ 4 - 2
source/ls-std/io/section-pair/SectionPairRow.cpp

@@ -11,6 +11,7 @@
 #include <ls-std/core/exception/IllegalArgumentException.hpp>
 #include <ls-std/io/section-pair/SectionPairIdentifierArgumentEvaluator.hpp>
 #include <ls-std/io/section-pair/SectionPairRow.hpp>
+#include <ls-std/io/section-pair/SectionPairRowListValue.hpp>
 #include <ls-std/io/section-pair/SectionPairRowSingleValue.hpp>
 
 ls::std::io::SectionPairRow::SectionPairRow(const ls::std::io::section_pair_identifier &_key, const ls::std::io::SectionPairRowEnumType &_type) : ls::std::core::Class("SectionPairRow")
@@ -28,7 +29,7 @@ ls::std::io::section_pair_row_value ls::std::io::SectionPairRow::getKey()
 
 bool ls::std::io::SectionPairRow::isList()
 {
-  return this->value->getType() == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_LIST;
+  return this->value->getType() == ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE;
 }
 
 bool ls::std::io::SectionPairRow::isSingleValue()
@@ -44,8 +45,9 @@ void ls::std::io::SectionPairRow::_initValue(const ls::std::io::SectionPairRowEn
     {
       throw ls::std::core::IllegalArgumentException{"default row enum type can not be set!"};
     }
-    case SECTION_PAIR_ROW_LIST:
+    case SECTION_PAIR_ROW_LIST_VALUE:
     {
+      this->value = ::std::make_shared<ls::std::io::SectionPairRowListValue>();
     }
     break;
     case SECTION_PAIR_ROW_SINGLE_VALUE:

+ 55 - 0
source/ls-std/io/section-pair/SectionPairRowListValue.cpp

@@ -0,0 +1,55 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-10
+* Changed:         2023-02-10
+*
+* */
+
+#include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
+#include <ls-std/core/evaluator/IndexOutOfBoundsEvaluator.hpp>
+#include <ls-std/io/section-pair/SectionPairRowListValue.hpp>
+#include <ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.hpp>
+
+ls::std::io::SectionPairRowListValue::SectionPairRowListValue() : ls::std::core::Class("SectionPairRowListValue"), ls::std::io::SectionPairRowValue(ls::std::io::SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE)
+{}
+
+ls::std::io::SectionPairRowListValue::~SectionPairRowListValue() = default;
+
+void ls::std::io::SectionPairRowListValue::add(const ls::std::io::section_pair_row_value &_value)
+{
+  ls::std::core::EmptyStringArgumentEvaluator{_value}.evaluate();
+  ls::std::io::SectionPairRowValueArgumentEvaluator{_value, "section pair row list value \"" + _value + "\" contains invalid characters!"}.evaluate();
+  this->values.push_back(_value);
+}
+
+ls::std::io::section_pair_row_value ls::std::io::SectionPairRowListValue::get(size_t _index)
+{
+  ls::std::core::IndexOutOfBoundsEvaluator(_index, this->values.size()).evaluate();
+  ls::std::io::section_pair_row_value value{};
+  size_t index{};
+
+  for (const auto &_value : this->values)
+  {
+    if (index == _index)
+    {
+      value = _value;
+      break;
+    }
+
+    ++index;
+  }
+
+  return value;
+}
+
+size_t ls::std::io::SectionPairRowListValue::getSize()
+{
+  return this->values.size();
+}
+
+ls::std::io::SectionPairRowEnumType ls::std::io::SectionPairRowListValue::getType()
+{
+  return this->type;
+}

+ 113 - 0
test/cases/io/section-pair/SectionPairRowListValueTest.cpp

@@ -0,0 +1,113 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-10
+* Changed:         2023-02-10
+*
+* */
+
+#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 SectionPairRowListValueTest : public ::testing::Test
+  {
+    protected:
+
+      SectionPairRowListValueTest() = default;
+      ~SectionPairRowListValueTest() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(SectionPairRowListValueTest, add)
+  {
+    SectionPairRowListValue list{};
+    list.add("Music");
+
+    ASSERT_TRUE(list.getSize() == 1);
+    ASSERT_STREQ("Music", list.get(0).c_str());
+  }
+
+  TEST_F(SectionPairRowListValueTest, add_empty_value)
+  {
+    SectionPairRowListValue list{};
+
+    EXPECT_THROW(
+        {
+          try
+          {
+            list.add("");
+          }
+          catch (const IllegalArgumentException &_exception)
+          {
+            throw;
+          }
+        },
+        IllegalArgumentException);
+  }
+
+  TEST_F(SectionPairRowListValueTest, add_invalid_value)
+  {
+    SectionPairRowListValue list{};
+
+    EXPECT_THROW(
+        {
+          try
+          {
+            list.add("=33");
+          }
+          catch (const IllegalArgumentException &_exception)
+          {
+            throw;
+          }
+        },
+        IllegalArgumentException);
+  }
+
+  TEST_F(SectionPairRowListValueTest, getClassName)
+  {
+    ASSERT_STREQ("SectionPairRowListValue", SectionPairRowListValue{}.getClassName().c_str());
+  }
+
+  TEST_F(SectionPairRowListValueTest, get_no_elements)
+  {
+    SectionPairRowListValue list{};
+
+    EXPECT_THROW(
+        {
+          try
+          {
+            ls::std::io::section_pair_row_value value = list.get(0);
+          }
+          catch (const IndexOutOfBoundsException &_exception)
+          {
+            throw;
+          }
+        },
+        IndexOutOfBoundsException);
+  }
+
+  TEST_F(SectionPairRowListValueTest, getSize)
+  {
+    SectionPairRowListValue list{};
+    ASSERT_EQ(0, list.getSize());
+  }
+
+  TEST_F(SectionPairRowListValueTest, getType)
+  {
+    SectionPairRowListValue list{};
+    ASSERT_EQ(ls::std::io::SECTION_PAIR_ROW_LIST_VALUE, list.getType());
+  }
+}

+ 1 - 1
test/cases/io/section-pair/SectionPairRowTest.cpp

@@ -33,7 +33,7 @@ namespace
 
   TEST_F(SectionPairRowTest, getClassName)
   {
-    ASSERT_STREQ("SectionPairRow", SectionPairRow("tmp-key", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE).getClassName().c_str());
+    ASSERT_STREQ("SectionPairRow", SectionPairRow("tmp-key", SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE).getClassName().c_str());
   }
 
   TEST_F(SectionPairRowTest, constructor_empty_key)