Jelajahi Sumber

Add SectionPairRowSingleValue class

This class is based on the abstract class SectionPairRowValue and represents a single value for a section pair row.
Patrick-Christopher Mattulat 2 tahun lalu
induk
melakukan
7ac6f4b08d

+ 3 - 0
CMakeLists.txt

@@ -177,6 +177,8 @@ 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/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
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/section-pair/SectionPairRowValueValidator.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/xml/XmlAttribute.cpp
@@ -265,6 +267,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/SectionPairRowSingleValueTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairRowTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairRowValueArgumentEvaluatorTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/section-pair/SectionPairRowValueValidatorTest.cpp

+ 36 - 0
include/ls-std/io/section-pair/SectionPairRowSingleValue.hpp

@@ -0,0 +1,36 @@
+/*
+* 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_SINGLE_VALUE_HPP
+#define LS_STD_SECTION_PAIR_ROW_SINGLE_VALUE_HPP
+
+#include "SectionPairRowValue.hpp"
+#include "SectionPairTypes.hpp"
+#include <ls-std/core/Class.hpp>
+#include <ls-std/os/dynamic-goal.hpp>
+
+namespace ls::std::io
+{
+  class LS_STD_DYNAMIC_GOAL SectionPairRowSingleValue : public ls::std::core::Class, public ls::std::io::SectionPairRowValue
+  {
+    public:
+
+      explicit SectionPairRowSingleValue(const ls::std::io::section_pair_row_value &_value);
+      ~SectionPairRowSingleValue() override;
+
+      [[nodiscard]] ls::std::io::section_pair_row_value get();
+      [[nodiscard]] ls::std::io::SectionPairRowEnumType getType() override;
+
+    private:
+
+      ls::std::io::section_pair_row_value value{};
+  };
+}
+
+#endif

+ 33 - 0
include/ls-std/io/section-pair/SectionPairRowValue.hpp

@@ -0,0 +1,33 @@
+/*
+* 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_VALUE_HPP
+#define LS_STD_SECTION_PAIR_ROW_VALUE_HPP
+
+#include "SectionPairRowEnumType.hpp"
+#include <ls-std/os/dynamic-goal.hpp>
+
+namespace ls::std::io
+{
+  class LS_STD_DYNAMIC_GOAL SectionPairRowValue
+  {
+    public:
+
+      explicit SectionPairRowValue(const ls::std::io::SectionPairRowEnumType &_type);
+      virtual ~SectionPairRowValue();
+
+      virtual ls::std::io::SectionPairRowEnumType getType() = 0;
+
+    protected:
+
+      ls::std::io::SectionPairRowEnumType type{};
+  };
+}
+
+#endif

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

@@ -24,6 +24,8 @@
 #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/SectionPairRowSingleValue.hpp>
+#include <ls-std/io/section-pair/SectionPairRowValue.hpp>
 #include <ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.hpp>
 #include <ls-std/io/section-pair/SectionPairRowValueValidator.hpp>
 #include <ls-std/io/section-pair/SectionPairTypes.hpp>

+ 31 - 0
source/ls-std/io/section-pair/SectionPairRowSingleValue.cpp

@@ -0,0 +1,31 @@
+/*
+* 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/io/section-pair/SectionPairRowSingleValue.hpp>
+#include <ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.hpp>
+
+ls::std::io::SectionPairRowSingleValue::SectionPairRowSingleValue(const ls::std::io::section_pair_row_value &_value) : ls::std::core::Class("SectionPairRowSingleValue"), ls::std::io::SectionPairRowValue(ls::std::io::SECTION_PAIR_ROW_SINGLE_VALUE)
+{
+  ls::std::core::EmptyStringArgumentEvaluator{_value}.evaluate();
+  ls::std::io::SectionPairRowValueArgumentEvaluator(_value, "section pair single value \"" + _value + "\" contains invalid characters!").evaluate();
+  this->value = _value;
+}
+
+ls::std::io::SectionPairRowSingleValue::~SectionPairRowSingleValue() = default;
+
+ls::std::io::section_pair_row_value ls::std::io::SectionPairRowSingleValue::get()
+{
+  return this->value;
+}
+
+ls::std::io::SectionPairRowEnumType ls::std::io::SectionPairRowSingleValue::getType()
+{
+  return this->type;
+}

+ 15 - 0
source/ls-std/io/section-pair/SectionPairRowValue.cpp

@@ -0,0 +1,15 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-10
+* Changed:         2023-02-10
+*
+* */
+
+#include <ls-std/io/section-pair/SectionPairRowValue.hpp>
+
+ls::std::io::SectionPairRowValue::SectionPairRowValue(const ls::std::io::SectionPairRowEnumType &_type) : type(_type)
+{}
+
+ls::std::io::SectionPairRowValue::~SectionPairRowValue() = default;

+ 82 - 0
test/cases/io/section-pair/SectionPairRowSingleValueTest.cpp

@@ -0,0 +1,82 @@
+/*
+* 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 SectionPairRowSingleValueTest : public ::testing::Test
+  {
+    protected:
+
+      SectionPairRowSingleValueTest() = default;
+      ~SectionPairRowSingleValueTest() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(SectionPairRowSingleValueTest, getClassName)
+  {
+    ASSERT_STREQ("SectionPairRowSingleValue", SectionPairRowSingleValue{"blue"}.getClassName().c_str());
+  }
+
+  TEST_F(SectionPairRowSingleValueTest, constructor_empty_value)
+  {
+    EXPECT_THROW(
+        {
+          try
+          {
+            SectionPairRowSingleValue value{""};
+          }
+          catch (const IllegalArgumentException &_exception)
+          {
+            throw;
+          }
+        },
+        IllegalArgumentException);
+  }
+
+  TEST_F(SectionPairRowSingleValueTest, constructor_invalid_value)
+  {
+    EXPECT_THROW(
+        {
+          try
+          {
+            SectionPairRowSingleValue value{"=33"};
+          }
+          catch (const IllegalArgumentException &_exception)
+          {
+            throw;
+          }
+        },
+        IllegalArgumentException);
+  }
+
+  TEST_F(SectionPairRowSingleValueTest, get)
+  {
+    SectionPairRowSingleValue value{"blue"};
+    ASSERT_STREQ("blue", value.get().c_str());
+  }
+
+  TEST_F(SectionPairRowSingleValueTest, getType)
+  {
+    SectionPairRowSingleValue value{"blue"};
+    ASSERT_EQ(ls::std::io::SECTION_PAIR_ROW_SINGLE_VALUE, value.getType());
+  }
+}