Quellcode durchsuchen

Reduce polymorphism of Integer class

- remove ISerializable extension
- remove IStorable extension
- adjust tests for Integer class
Patrick-Christopher Mattulat vor 3 Jahren
Ursprung
Commit
ab38080dc8

+ 2 - 10
include/ls_std/boxing/Integer.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-07
- * Changed:         2021-05-01
+ * Changed:         2021-07-14
  *
  * */
 
@@ -18,7 +18,7 @@
 
 namespace ls_std
 {
-  class Integer : public ls_std::Class, public ls_std::IBoxing, public ls_std::ISerializable, public ls_std::IStorable
+  class Integer : public ls_std::Class, public ls_std::IBoxing
   {
     public:
 
@@ -95,23 +95,15 @@ namespace ls_std
 
       // implementation
 
-      ls_std::byte_field load() override;
-      ls_std::byte_field marshal() override;
       void parse(std::string _parseText) override;
-      void save(const ls_std::byte_field &_data) override;
       std::string toString() override;
-      void unmarshal(const ls_std::byte_field &_data) override;
 
       // additional functionality
 
       int getValue() const;
-      void setSerializable(std::shared_ptr<ls_std::ISerializable> _serializable);
-      void setStorable(std::shared_ptr<ls_std::IStorable> _storable);
 
     private:
 
-      std::shared_ptr<ls_std::ISerializable> serializable{};
-      std::shared_ptr<ls_std::IStorable> storable{};
       int value{};
   };
 }

+ 1 - 59
source/ls_std/boxing/Integer.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-07
- * Changed:         2021-05-01
+ * Changed:         2021-07-14
  *
  * */
 
@@ -252,75 +252,17 @@ void ls_std::Integer::operator--()
   this->value -= 1;
 }
 
-ls_std::byte_field ls_std::Integer::load()
-{
-  ls_std::byte_field data{};
-
-  if (this->storable != nullptr && this->serializable != nullptr)
-  {
-    data = this->storable->load();
-    this->serializable->unmarshal(data);
-  }
-
-  return data;
-}
-
-ls_std::byte_field ls_std::Integer::marshal()
-{
-  ls_std::byte_field data{};
-
-  if (this->serializable != nullptr)
-  {
-    data = this->serializable->marshal();
-  }
-
-  return data;
-}
-
 void ls_std::Integer::parse(std::string _parseText)
 {
   this->value = std::stoi(_parseText);
 }
 
-void ls_std::Integer::save(const ls_std::byte_field &_data)
-{
-  if (this->serializable != nullptr)
-  {
-    if (_data.empty())
-    {
-      this->storable->save(this->serializable->marshal());
-    }
-    else
-    {
-      this->storable->save(_data);
-    }
-  }
-}
-
 std::string ls_std::Integer::toString()
 {
   return std::to_string(this->value);
 }
 
-void ls_std::Integer::unmarshal(const ls_std::byte_field &_data)
-{
-  if (this->serializable != nullptr)
-  {
-    this->serializable->unmarshal(_data);
-  }
-}
-
 int ls_std::Integer::getValue() const
 {
   return this->value;
 }
-
-void ls_std::Integer::setSerializable(std::shared_ptr<ls_std::ISerializable> _serializable)
-{
-  this->serializable = std::move(_serializable);
-}
-
-void ls_std::Integer::setStorable(std::shared_ptr<ls_std::IStorable> _storable)
-{
-  this->storable = std::move(_storable);
-}

+ 1 - 52
test/cases/boxing/IntegerTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-09
- * Changed:         2021-05-02
+ * Changed:         2021-07-14
  *
  * */
 
@@ -340,44 +340,6 @@ namespace
 
   // implementation
 
-  TEST_F(IntegerTest, load)
-  {
-    // preparation
-
-    std::shared_ptr<ls_std::Integer> x = std::make_shared<ls_std::Integer>();
-    std::string path = TestHelper::getResourcesFolderLocation() + "tmp_storable_integer.json";
-    ls_std::File file{path};
-    file.createNewFile();
-    ls_std::FileWriter writer{file};
-    writer.write(R"({"value":1990})");
-
-    auto serializable = std::make_shared<ls_std::SerializableJsonInteger>(x);
-    x->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
-
-    auto storable = std::make_shared<ls_std::StorableFile>(path);
-    x->setStorable(std::dynamic_pointer_cast<ls_std::IStorable>(storable));
-
-    // check
-
-    x->load();
-    ASSERT_EQ(1990, *x);
-
-    file.remove();
-  }
-
-  TEST_F(IntegerTest, marshal)
-  {
-    std::shared_ptr<ls_std::Integer> x = std::make_shared<ls_std::Integer>(3);
-
-    auto serializable = std::make_shared<ls_std::SerializableJsonInteger>(x);
-    x->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
-
-    ASSERT_STREQ(R"({"value":3})", x->marshal().c_str());
-
-    *x = 17;
-    ASSERT_STREQ(R"({"value":17})", x->marshal().c_str());
-  }
-
   TEST_F(IntegerTest, parse)
   {
     ls_std::Integer x{};
@@ -395,19 +357,6 @@ namespace
     ASSERT_STREQ("112", x.toString().c_str());
   }
 
-  TEST_F(IntegerTest, unmarshal)
-  {
-    std::shared_ptr<ls_std::Integer> x = std::make_shared<ls_std::Integer>(13);
-    ASSERT_EQ(13, *x);
-
-    auto serializable = std::make_shared<ls_std::SerializableJsonInteger>(x);
-    x->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
-
-    x->unmarshal(R"({"value":1989})");
-
-    ASSERT_EQ(1989, *x);
-  }
-
   // additional functionality
 
   TEST_F(IntegerTest, getValue)