Browse Source

Introduce section pair types

STL types have been replaced by dedicated section pair types.
Patrick-Christopher Mattulat 2 years ago
parent
commit
dbdd052310

+ 4 - 3
include/ls-std/io/section-pair/SectionPairIdentifierArgumentEvaluator.hpp

@@ -3,13 +3,14 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-09
-* Changed:         2023-02-09
+* Changed:         2023-02-10
 *
 * */
 
 #ifndef LS_STD_SECTION_PAIR_IDENTIFIER_ARGUMENT_EVALUATOR_HPP
 #define LS_STD_SECTION_PAIR_IDENTIFIER_ARGUMENT_EVALUATOR_HPP
 
+#include "SectionPairTypes.hpp"
 #include <ls-std/core/interface/IEvaluator.hpp>
 #include <string>
 
@@ -19,14 +20,14 @@ namespace ls::std::io
   {
     public:
 
-      SectionPairIdentifierArgumentEvaluator(::std::string _identifier, ::std::string _message);
+      explicit SectionPairIdentifierArgumentEvaluator(ls::std::io::section_pair_identifier _identifier, ::std::string _message);
       ~SectionPairIdentifierArgumentEvaluator() override;
 
       void evaluate() override;
 
     private:
 
-      ::std::string identifier{};
+      ls::std::io::section_pair_identifier identifier{};
       ::std::string message{};
   };
 }

+ 4 - 3
include/ls-std/io/section-pair/SectionPairIdentifierValidator.hpp

@@ -3,13 +3,14 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-09
-* Changed:         2023-02-09
+* Changed:         2023-02-10
 *
 * */
 
 #ifndef LS_STD_SECTION_PAIR_IDENTIFIER_VALIDATOR_HPP
 #define LS_STD_SECTION_PAIR_IDENTIFIER_VALIDATOR_HPP
 
+#include "SectionPairTypes.hpp"
 #include <ls-std/core/Class.hpp>
 #include <ls-std/core/interface/IValidator.hpp>
 #include <string>
@@ -20,14 +21,14 @@ namespace ls::std::io
   {
     public:
 
-      explicit SectionPairIdentifierValidator(::std::string _identifier);
+      explicit SectionPairIdentifierValidator(ls::std::io::section_pair_identifier _identifier);
       ~SectionPairIdentifierValidator() override;
 
       bool isValid() override;
 
     private:
 
-      ::std::string identifier{};
+      ls::std::io::section_pair_identifier identifier{};
   };
 }
 

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

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-08
-* Changed:         2023-02-09
+* Changed:         2023-02-10
 *
 * */
 
@@ -11,9 +11,9 @@
 #define LS_STD_SECTION_PAIR_ROW_HPP
 
 #include "SectionPairRowEnumType.hpp"
+#include "SectionPairTypes.hpp"
 #include <list>
 #include <ls-std/core/Class.hpp>
-#include <string>
 
 namespace ls::std::io
 {
@@ -21,23 +21,23 @@ namespace ls::std::io
   {
     public:
 
-      explicit SectionPairRow(const ::std::string &_key);
+      explicit SectionPairRow(const ls::std::io::section_pair_identifier &_key);
       ~SectionPairRow() override;
 
-      [[nodiscard]] ::std::string getKey();
-      [[nodiscard]] ::std::string getValue();
+      [[nodiscard]] ls::std::io::section_pair_identifier getKey();
+      [[nodiscard]] ls::std::io::section_pair_row_value getValue();
       [[nodiscard]] bool isKeyValue();
       [[nodiscard]] bool isList();
-      void setValue(const ::std::string &_value);
+      void setValue(const ls::std::io::section_pair_row_value &_value);
 
     private:
 
-      ::std::string key{};
+      ls::std::io::section_pair_identifier key{};
       ls::std::io::SectionPairRowEnumType type{};
-      ::std::list<::std::string> values{};
+      ::std::list<ls::std::io::section_pair_row_value> values{};
 
-      void _setType(const ls::std::io::SectionPairRowEnumType& _type);
-      void _setValue(const ::std::string &_value);
+      void _setType(const ls::std::io::SectionPairRowEnumType &_type);
+      void _setValue(const ls::std::io::section_pair_row_value &_value);
   };
 }
 

+ 3 - 2
include/ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.hpp

@@ -10,6 +10,7 @@
 #ifndef LS_STD_SECTION_PAIR_ROW_VALUE_ARGUMENT_EVALUATOR_HPP
 #define LS_STD_SECTION_PAIR_ROW_VALUE_ARGUMENT_EVALUATOR_HPP
 
+#include "SectionPairTypes.hpp"
 #include <ls-std/core/interface/IEvaluator.hpp>
 #include <string>
 
@@ -19,7 +20,7 @@ namespace ls::std::io
   {
     public:
 
-      explicit SectionPairRowValueArgumentEvaluator(::std::string _value, ::std::string _message);
+      explicit SectionPairRowValueArgumentEvaluator(ls::std::io::section_pair_row_value _value, ::std::string _message);
       ~SectionPairRowValueArgumentEvaluator() override;
 
       void evaluate() override;
@@ -27,7 +28,7 @@ namespace ls::std::io
     private:
 
       ::std::string message{};
-      ::std::string value{};
+      ls::std::io::section_pair_row_value value{};
   };
 }
 

+ 4 - 3
include/ls-std/io/section-pair/SectionPairRowValueValidator.hpp

@@ -3,13 +3,14 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-09
-* Changed:         2023-02-09
+* Changed:         2023-02-10
 *
 * */
 
 #ifndef LS_STD_SECTION_PAIR_ROW_VALUE_VALIDATOR_HPP
 #define LS_STD_SECTION_PAIR_ROW_VALUE_VALIDATOR_HPP
 
+#include "SectionPairTypes.hpp"
 #include <ls-std/core/Class.hpp>
 #include <ls-std/core/interface/IValidator.hpp>
 #include <string>
@@ -20,14 +21,14 @@ namespace ls::std::io
   {
     public:
 
-      explicit SectionPairRowValueValidator(::std::string _value);
+      explicit SectionPairRowValueValidator(ls::std::io::section_pair_row_value _value);
       ~SectionPairRowValueValidator() override;
 
       bool isValid() override;
 
     private:
 
-      ::std::string value{};
+      ls::std::io::section_pair_row_value value{};
   };
 }
 

+ 21 - 0
include/ls-std/io/section-pair/SectionPairTypes.hpp

@@ -0,0 +1,21 @@
+/*
+* 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_TYPES_HPP
+#define LS_STD_SECTION_PAIR_TYPES_HPP
+
+#include <string>
+
+namespace ls::std::io
+{
+  using section_pair_identifier = ::std::string;
+  using section_pair_row_value = ::std::string;
+}
+
+#endif

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

@@ -26,6 +26,7 @@
 #include <ls-std/io/section-pair/SectionPairRowEnumType.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>
 
 #include <ls-std/io/xml/XmlAttribute.hpp>
 #include <ls-std/io/xml/XmlDeclaration.hpp>

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

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-09
-* Changed:         2023-02-09
+* Changed:         2023-02-10
 *
 * */
 
@@ -11,7 +11,7 @@
 #include <ls-std/io/section-pair/SectionPairIdentifierArgumentEvaluator.hpp>
 #include <ls-std/io/section-pair/SectionPairIdentifierValidator.hpp>
 
-ls::std::io::SectionPairIdentifierArgumentEvaluator::SectionPairIdentifierArgumentEvaluator(::std::string _identifier, ::std::string _message) : identifier(::std::move(_identifier)), message(::std::move(_message))
+ls::std::io::SectionPairIdentifierArgumentEvaluator::SectionPairIdentifierArgumentEvaluator(ls::std::io::section_pair_identifier _identifier, ::std::string _message) : identifier(::std::move(_identifier)), message(::std::move(_message))
 {}
 
 ls::std::io::SectionPairIdentifierArgumentEvaluator::~SectionPairIdentifierArgumentEvaluator() = default;

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

@@ -3,13 +3,13 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-09
-* Changed:         2023-02-09
+* Changed:         2023-02-10
 *
 * */
 
 #include <ls-std/io/section-pair/SectionPairIdentifierValidator.hpp>
 
-ls::std::io::SectionPairIdentifierValidator::SectionPairIdentifierValidator(::std::string _identifier) : ls::std::core::Class("SectionPairIdentifierValidator"), identifier(::std::move(_identifier))
+ls::std::io::SectionPairIdentifierValidator::SectionPairIdentifierValidator(ls::std::io::section_pair_identifier _identifier) : ls::std::core::Class("SectionPairIdentifierValidator"), identifier(::std::move(_identifier))
 {}
 
 ls::std::io::SectionPairIdentifierValidator::~SectionPairIdentifierValidator() = default;
@@ -21,8 +21,8 @@ bool ls::std::io::SectionPairIdentifierValidator::isValid()
   if (!this->identifier.empty())
   {
     size_t foundPosition = this->identifier.find_first_not_of("abcdefghijklmnopqrstuvwxyz-0123456789");
-    startsWithValidCharacter = ::std::string{this->identifier[0]}.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == ::std::string::npos;
-    containsValidCharacters = foundPosition == ::std::string::npos;
+    startsWithValidCharacter = ls::std::io::section_pair_identifier{this->identifier[0]}.find_first_not_of("abcdefghijklmnopqrstuvwxyz") == ::std::string::npos;
+    containsValidCharacters = foundPosition == ls::std::io::section_pair_identifier::npos;
     doesNotExceedMaxSize = this->identifier.size() <= 16;
   }
 

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

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-08
-* Changed:         2023-02-09
+* Changed:         2023-02-10
 *
 * */
 
@@ -11,7 +11,7 @@
 #include <ls-std/io/section-pair/SectionPairIdentifierArgumentEvaluator.hpp>
 #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::SectionPairRow::SectionPairRow(const ls::std::io::section_pair_identifier &_key) : ls::std::core::Class("SectionPairRow")
 {
   ls::std::core::EmptyStringArgumentEvaluator{_key, "passed key identifier for section pair row is empty!"}.evaluate();
   ls::std::io::SectionPairIdentifierArgumentEvaluator(_key, "section pair key identifier \"" + _key + "\" contains invalid characters!").evaluate();
@@ -20,7 +20,7 @@ ls::std::io::SectionPairRow::SectionPairRow(const ::std::string &_key) : ls::std
 
 ls::std::io::SectionPairRow::~SectionPairRow() = default;
 
-::std::string ls::std::io::SectionPairRow::getKey()
+ls::std::io::section_pair_row_value ls::std::io::SectionPairRow::getKey()
 {
   return this->key;
 }
@@ -40,7 +40,7 @@ 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)
+void ls::std::io::SectionPairRow::setValue(const ls::std::io::section_pair_row_value &_value)
 {
   ls::std::core::EmptyStringArgumentEvaluator{_value, "passed value for section pair row is empty!"}.evaluate();
   //TODO: add SectionPairRowValueArgumentEvaluator
@@ -56,7 +56,7 @@ void ls::std::io::SectionPairRow::_setType(const ls::std::io::SectionPairRowEnum
   }
 }
 
-void ls::std::io::SectionPairRow::_setValue(const ::std::string &_value)
+void ls::std::io::SectionPairRow::_setValue(const ls::std::io::section_pair_row_value &_value)
 {
   if (!this->values.empty())
   {

+ 1 - 1
source/ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.cpp

@@ -11,7 +11,7 @@
 #include <ls-std/io/section-pair/SectionPairRowValueArgumentEvaluator.hpp>
 #include <ls-std/io/section-pair/SectionPairRowValueValidator.hpp>
 
-ls::std::io::SectionPairRowValueArgumentEvaluator::SectionPairRowValueArgumentEvaluator(::std::string _value, ::std::string _message) : value(::std::move(_value)) , message(::std::move(_message))
+ls::std::io::SectionPairRowValueArgumentEvaluator::SectionPairRowValueArgumentEvaluator(ls::std::io::section_pair_row_value _value, ::std::string _message) : value(::std::move(_value)) , message(::std::move(_message))
 {}
 
 ls::std::io::SectionPairRowValueArgumentEvaluator::~SectionPairRowValueArgumentEvaluator() = default;

+ 3 - 3
source/ls-std/io/section-pair/SectionPairRowValueValidator.cpp

@@ -3,13 +3,13 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-09
-* Changed:         2023-02-09
+* Changed:         2023-02-10
 *
 * */
 
 #include <ls-std/io/section-pair/SectionPairRowValueValidator.hpp>
 
-ls::std::io::SectionPairRowValueValidator::SectionPairRowValueValidator(::std::string _value) : ls::std::core::Class("SectionPairRowValueValidator"), value(::std::move(_value))
+ls::std::io::SectionPairRowValueValidator::SectionPairRowValueValidator(ls::std::io::section_pair_row_value _value) : ls::std::core::Class("SectionPairRowValueValidator"), value(::std::move(_value))
 {}
 
 ls::std::io::SectionPairRowValueValidator::~SectionPairRowValueValidator() = default;
@@ -17,5 +17,5 @@ ls::std::io::SectionPairRowValueValidator::~SectionPairRowValueValidator() = def
 bool ls::std::io::SectionPairRowValueValidator::isValid()
 {
   size_t foundPosition = this->value.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789_#![]{}()/$ۤ%?<>+:;., *\"");
-  return foundPosition == ::std::string::npos;
+  return foundPosition == ls::std::io::section_pair_row_value::npos;
 }

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

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-08
-* Changed:         2023-02-09
+* Changed:         2023-02-10
 *
 * */
 
@@ -70,7 +70,7 @@ namespace
 
   TEST_F(SectionPairRowTest, getKey)
   {
-    ::std::string key = "tmp-key";
+    ls::std::io::section_pair_identifier key = "tmp-key";
 
     SectionPairRow row{key};
     ASSERT_STREQ(key.c_str(), row.getKey().c_str());