Browse Source

Reduce polymorphism of Long class

- remove ISerializable extension
- remove IStorable extension
- adjust tests for Long class
Patrick-Christopher Mattulat 3 years ago
parent
commit
0dc4d08e4b
3 changed files with 4 additions and 121 deletions
  1. 2 10
      include/ls_std/boxing/Long.hpp
  2. 1 59
      source/ls_std/boxing/Long.cpp
  3. 1 52
      test/cases/boxing/LongTest.cpp

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

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-17
- * Changed:         2021-05-01
+ * Changed:         2021-07-14
  *
  * */
 
@@ -19,7 +19,7 @@
 
 namespace ls_std
 {
-  class Long : public ls_std::Class, public ls_std::IBoxing, public ls_std::ISerializable, public ls_std::IStorable
+  class Long : public ls_std::Class, public ls_std::IBoxing
   {
     public:
 
@@ -96,23 +96,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
 
       ls_std::long_type 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{};
       ls_std::long_type value{};
   };
 }

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

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

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

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-17
- * Changed:         2021-05-02
+ * Changed:         2021-07-14
  *
  * */
 
@@ -340,44 +340,6 @@ namespace
 
   // implementation
 
-  TEST_F(LongTest, load)
-  {
-    // preparation
-
-    std::shared_ptr<ls_std::Long> x = std::make_shared<ls_std::Long>();
-    std::string path = TestHelper::getResourcesFolderLocation() + "tmp_storable_long.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::SerializableJsonLong>(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(LongTest, marshal)
-  {
-    std::shared_ptr<ls_std::Long> x = std::make_shared<ls_std::Long>(3);
-
-    auto serializable = std::make_shared<ls_std::SerializableJsonLong>(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(LongTest, parse)
   {
     ls_std::Long x{};
@@ -395,19 +357,6 @@ namespace
     ASSERT_STREQ("112", x.toString().c_str());
   }
 
-  TEST_F(LongTest, unmarshal)
-  {
-    std::shared_ptr<ls_std::Long> x = std::make_shared<ls_std::Long>(13);
-    ASSERT_EQ(13, *x);
-
-    auto serializable = std::make_shared<ls_std::SerializableJsonLong>(x);
-    x->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
-
-    x->unmarshal(R"({"value":1989})");
-
-    ASSERT_EQ(1989, *x);
-  }
-
   // additional functionality
 
   TEST_F(LongTest, getValue)