Browse Source

Reduce polymorphism of Float class

- remove ISerializable extension
- remove IStorable extension
- adjust tests for Float class
Patrick-Christopher Mattulat 3 years ago
parent
commit
62fb7165f9

+ 0 - 2
CMakeLists.txt

@@ -97,7 +97,6 @@ set(SOURCE_FILES
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/kv/KvParser.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/kv/KvReader.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/factory/serialization/json/SerializableJsonFactory.cpp
-        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/factory/serialization/json/boxing/SerializableJsonFloatFactory.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/factory/serialization/json/boxing/SerializableJsonIntegerFactory.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/factory/serialization/json/boxing/SerializableJsonLongFactory.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/factory/serialization/json/boxing/SerializableJsonStringFactory.cpp
@@ -162,7 +161,6 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/kv/KvParserTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/kv/KvReaderTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/factory/serialization/json/SerializableFactoryTest.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/factory/serialization/json/boxing/SerializableJsonFloatFactoryTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/factory/serialization/json/boxing/SerializableJsonIntegerFactoryTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/factory/serialization/json/boxing/SerializableJsonLongFactoryTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/factory/serialization/json/boxing/SerializableJsonStringFactoryTest.cpp

+ 2 - 14
include/ls_std/boxing/Float.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2021-07-08
+ * Changed:         2021-07-12
  *
  * */
 
@@ -13,12 +13,10 @@
 #include <memory>
 #include <ls_std/base/Class.hpp>
 #include "IBoxing.hpp"
-#include <ls_std/serialization/ISerializable.hpp>
-#include <ls_std/io/IStorable.hpp>
 
 namespace ls_std
 {
-  class Float : public ls_std::Class, public ls_std::IBoxing, public ls_std::ISerializable, public ls_std::IStorable
+  class Float : public ls_std::Class, public ls_std::IBoxing
   {
     public:
 
@@ -79,31 +77,21 @@ 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
 
       float getEpsilon();
       float getValue();
       void setEpsilon(float _epsilon);
-      void setSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable);
-      void setStorable(const std::shared_ptr<ls_std::IStorable>& _storable);
 
     private:
 
       float epsilon{};
-      std::shared_ptr<ls_std::ISerializable> serializable{};
-      std::shared_ptr<ls_std::IStorable> storable{};
       float value{};
 
       void _assignEpsilon(float _epsilon);
-      void _assignSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable);
-      void _assignStorable(const std::shared_ptr<ls_std::IStorable>& _storable);
   };
 }
 

+ 0 - 29
include/ls_std/factory/serialization/json/boxing/SerializableJsonFloatFactory.hpp

@@ -1,29 +0,0 @@
-/*
- * Author:          Patrick-Christopher Mattulat
- * Company:         Lynar Studios
- * E-Mail:          webmaster@lynarstudios.com
- * Created:         2021-04-24
- * Changed:         2021-05-02
- *
- * */
-
-#ifndef LS_STD_SERIALIZABLE_JSON_FLOAT_FACTORY_HPP
-#define LS_STD_SERIALIZABLE_JSON_FLOAT_FACTORY_HPP
-
-#include <ls_std/factory/IFactory.hpp>
-#include <memory>
-
-namespace ls_std
-{
-  class SerializableJsonFloatFactory : public ls_std::Class, public ls_std::IFactory
-  {
-    public:
-
-      SerializableJsonFloatFactory();
-      ~SerializableJsonFloatFactory() override = default;
-
-      std::shared_ptr<ls_std::Class> build() override;
-  };
-}
-
-#endif

+ 0 - 1
include/ls_std/ls_std.hpp

@@ -97,7 +97,6 @@
 
 #include "factory/IFactory.hpp"
 #include "ls_std/factory/serialization/json/SerializableJsonFactory.hpp"
-#include "factory/serialization/json/boxing/SerializableJsonFloatFactory.hpp"
 #include "factory/serialization/json/boxing/SerializableJsonIntegerFactory.hpp"
 #include "factory/serialization/json/boxing/SerializableJsonLongFactory.hpp"
 #include "factory/serialization/json/boxing/SerializableJsonStringFactory.hpp"

+ 1 - 79
source/ls_std/boxing/Float.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2021-07-08
+ * Changed:         2021-07-12
  *
  * */
 
@@ -196,64 +196,16 @@ void ls_std::Float::operator--()
   this->value -= 1.0f;
 }
 
-ls_std::byte_field ls_std::Float::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::Float::marshal()
-{
-  ls_std::byte_field data{};
-
-  if (this->serializable != nullptr)
-  {
-    data = this->serializable->marshal();
-  }
-
-  return data;
-}
-
 void ls_std::Float::parse(std::string _parseText)
 {
   this->value = std::stof(_parseText);
 }
 
-void ls_std::Float::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::Float::toString()
 {
   return std::to_string(this->value);
 }
 
-void ls_std::Float::unmarshal(const ls_std::byte_field &_data)
-{
-  if (this->serializable != nullptr)
-  {
-    this->serializable->unmarshal(_data);
-  }
-}
-
 float ls_std::Float::getEpsilon()
 {
   return this->epsilon;
@@ -269,16 +221,6 @@ void ls_std::Float::setEpsilon(float _epsilon)
   this->_assignEpsilon(_epsilon);
 }
 
-void ls_std::Float::setSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable)
-{
-  this->_assignSerializable(_serializable);
-}
-
-void ls_std::Float::setStorable(const std::shared_ptr<ls_std::IStorable>& _storable)
-{
-  this->_assignStorable(_storable);
-}
-
 void ls_std::Float::_assignEpsilon(float _epsilon)
 {
   if (_epsilon <= 0.0)
@@ -288,23 +230,3 @@ void ls_std::Float::_assignEpsilon(float _epsilon)
 
   this->epsilon = _epsilon;
 }
-
-void ls_std::Float::_assignSerializable(const std::shared_ptr<ls_std::ISerializable> &_serializable)
-{
-  if (_serializable == nullptr)
-  {
-    throw ls_std::IllegalArgumentException{};
-  }
-
-  this->serializable = _serializable;
-}
-
-void ls_std::Float::_assignStorable(const std::shared_ptr<ls_std::IStorable> &_storable)
-{
-  if (_storable == nullptr)
-  {
-    throw ls_std::IllegalArgumentException{};
-  }
-
-  this->storable = _storable;
-}

+ 0 - 2
source/ls_std/factory/serialization/json/SerializableJsonFactory.cpp

@@ -12,7 +12,6 @@
 #include <ls_std/boxing/Integer.hpp>
 #include <ls_std/boxing/Long.hpp>
 #include <ls_std/boxing/String.hpp>
-#include <ls_std/factory/serialization/json/boxing/SerializableJsonFloatFactory.hpp>
 #include <ls_std/factory/serialization/json/boxing/SerializableJsonIntegerFactory.hpp>
 #include <ls_std/factory/serialization/json/boxing/SerializableJsonLongFactory.hpp>
 #include <ls_std/factory/serialization/json/boxing/SerializableJsonStringFactory.hpp>
@@ -89,7 +88,6 @@ bool ls_std::SerializableJsonFactory::_hasFactory(const std::string &_relatedObj
 
 void ls_std::SerializableJsonFactory::_init()
 {
-  this->factories.insert({ls_std::Float{}.getClassName(), std::make_shared<ls_std::SerializableJsonFloatFactory>()});
   this->factories.insert({ls_std::Integer{}.getClassName(), std::make_shared<ls_std::SerializableJsonIntegerFactory>()});
   this->factories.insert({ls_std::Long{}.getClassName(), std::make_shared<ls_std::SerializableJsonLongFactory>()});
   this->factories.insert({ls_std::String{}.getClassName(), std::make_shared<ls_std::SerializableJsonStringFactory>()});

+ 0 - 24
source/ls_std/factory/serialization/json/boxing/SerializableJsonFloatFactory.cpp

@@ -1,24 +0,0 @@
-/*
- * Author:          Patrick-Christopher Mattulat
- * Company:         Lynar Studios
- * E-Mail:          webmaster@lynarstudios.com
- * Created:         2021-04-25
- * Changed:         2021-05-02
- *
- * */
-
-#include <ls_std/factory/serialization/json/boxing/SerializableJsonFloatFactory.hpp>
-#include <ls_std/boxing/Float.hpp>
-#include <ls_std/serialization/json/boxing/SerializableJsonFloat.hpp>
-
-ls_std::SerializableJsonFloatFactory::SerializableJsonFloatFactory() : ls_std::Class("SerializableJsonFloatFactory")
-{}
-
-std::shared_ptr<ls_std::Class> ls_std::SerializableJsonFloatFactory::build()
-{
-  std::shared_ptr<ls_std::Float> requestedObject = std::make_shared<ls_std::Float>();
-  std::shared_ptr<ls_std::ISerializable> serializable = std::make_shared<ls_std::SerializableJsonFloat>(requestedObject);
-  requestedObject->setSerializable(serializable);
-
-  return std::dynamic_pointer_cast<ls_std::Class>(requestedObject);
-}

+ 1 - 87
test/cases/boxing/FloatTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2021-07-08
+ * Changed:         2021-07-12
  *
  * */
 
@@ -25,24 +25,6 @@ namespace
 
       void TearDown() override
       {}
-
-      static std::pair<std::shared_ptr<ls_std::File>, std::shared_ptr<ls_std::Float>> createPersistentTestFloat()
-      {
-        std::shared_ptr<ls_std::Float> number = std::make_shared<ls_std::Float>();
-        std::string path = TestHelper::getResourcesFolderLocation() + "tmp_storable_float.json";
-        std::shared_ptr<ls_std::File> file = std::make_shared<ls_std::File>(path);
-        file->createNewFile();
-        ls_std::FileWriter writer{*file};
-        writer.write(R"({"value":3.14159})");
-
-        auto serializable = std::make_shared<ls_std::SerializableJsonFloat>(number);
-        number->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
-
-        auto storable = std::make_shared<ls_std::StorableFile>(path);
-        number->setStorable(std::dynamic_pointer_cast<ls_std::IStorable>(storable));
-
-        return std::pair<std::shared_ptr<ls_std::File>, std::shared_ptr<ls_std::Float>>(file, number);
-      }
   };
 
   // assignment operators
@@ -311,31 +293,6 @@ namespace
 
   // implementation
 
-  TEST_F(FloatTest, load)
-  {
-    // preparation
-
-    auto storableFloat = createPersistentTestFloat();
-
-    // check
-
-    storableFloat.second->load();
-    ASSERT_FLOAT_EQ(3.14159f, *storableFloat.second);
-
-    storableFloat.first->remove();
-  }
-
-  TEST_F(FloatTest, marshal)
-  {
-    std::shared_ptr<ls_std::Float> number = std::make_shared<ls_std::Float>(3.14159f);
-
-    auto serializable = std::make_shared<ls_std::SerializableJsonFloat>(number);
-    number->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
-    ls_std::String jsonString{number->marshal()};
-
-    ASSERT_TRUE(jsonString.contains(R"({"value":3.14159)"));
-  }
-
   TEST_F(FloatTest, parse)
   {
     ls_std::Float number{};
@@ -350,17 +307,6 @@ namespace
     ASSERT_TRUE(x.toString().find("13.1543") != std::string::npos);
   }
 
-  TEST_F(FloatTest, unmarshal)
-  {
-    std::shared_ptr<ls_std::Float> number = std::make_shared<ls_std::Float>(3.14159f);
-
-    auto serializable = std::make_shared<ls_std::SerializableJsonFloat>(number);
-    number->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
-    number->unmarshal(R"({"value":17.4132})");
-
-    ASSERT_FLOAT_EQ(17.4132, *number);
-  }
-
   // additional functionality
 
   TEST_F(FloatTest, getEpsilon)
@@ -398,36 +344,4 @@ namespace
                    }
                  }, ls_std::IllegalArgumentException);
   }
-
-  TEST_F(FloatTest, setSerializable_no_reference)
-  {
-    ls_std::Float x{};
-
-    EXPECT_THROW({
-                   try
-                   {
-                     x.setSerializable(nullptr);
-                   }
-                   catch (const ls_std::IllegalArgumentException &_exception)
-                   {
-                     throw;
-                   }
-                 }, ls_std::IllegalArgumentException);
-  }
-
-  TEST_F(FloatTest, setStorable_no_reference)
-  {
-    ls_std::Float x{};
-
-    EXPECT_THROW({
-                   try
-                   {
-                     x.setStorable(nullptr);
-                   }
-                   catch (const ls_std::IllegalArgumentException &_exception)
-                   {
-                     throw;
-                   }
-                 }, ls_std::IllegalArgumentException);
-  }
 }

+ 0 - 1
test/cases/factory/serialization/json/SerializableFactoryTest.cpp

@@ -104,7 +104,6 @@ namespace
   TEST_F(SerializableFactoryTest, hasFactory_ofBoxingPackage)
   {
     ls_std::SerializableJsonFactory serializableFactory{};
-    ASSERT_TRUE(serializableFactory.hasFactory(ls_std::Float{}.getClassName()));
     ASSERT_TRUE(serializableFactory.hasFactory(ls_std::Integer{}.getClassName()));
     ASSERT_TRUE(serializableFactory.hasFactory(ls_std::Long{}.getClassName()));
     ASSERT_TRUE(serializableFactory.hasFactory(ls_std::String{}.getClassName()));

+ 0 - 35
test/cases/factory/serialization/json/boxing/SerializableJsonDoubleFactoryTest.cpp

@@ -1,35 +0,0 @@
-/*
- * Author:          Patrick-Christopher Mattulat
- * Company:         Lynar Studios
- * E-Mail:          webmaster@lynarstudios.com
- * Created:         2021-04-24
- * Changed:         2021-05-02
- *
- * */
-
-#include <gtest/gtest.h>
-#include <ls_std/ls_std.hpp>
-
-namespace
-{
-  class SerializableJsonDoubleFactoryTest : public ::testing::Test
-  {
-    protected:
-
-      SerializableJsonDoubleFactoryTest() = default;
-      ~SerializableJsonDoubleFactoryTest() override = default;
-
-      void SetUp() override
-      {}
-
-      void TearDown() override
-      {}
-  };
-
-  TEST_F(SerializableJsonDoubleFactoryTest, build)
-  {
-    std::shared_ptr<ls_std::Double> value = std::dynamic_pointer_cast<ls_std::Double>(ls_std::SerializableJsonDoubleFactory{}.build());
-    ASSERT_TRUE(value != nullptr);
-    ASSERT_STREQ("Double", value->getClassName().c_str());
-  }
-}

+ 0 - 35
test/cases/factory/serialization/json/boxing/SerializableJsonFloatFactoryTest.cpp

@@ -1,35 +0,0 @@
-/*
- * Author:          Patrick-Christopher Mattulat
- * Company:         Lynar Studios
- * E-Mail:          webmaster@lynarstudios.com
- * Created:         2021-04-25
- * Changed:         2021-05-02
- *
- * */
-
-#include <gtest/gtest.h>
-#include <ls_std/ls_std.hpp>
-
-namespace
-{
-  class SerializableJsonFloatFactoryTest : public ::testing::Test
-  {
-    protected:
-
-      SerializableJsonFloatFactoryTest() = default;
-      ~SerializableJsonFloatFactoryTest() override = default;
-
-      void SetUp() override
-      {}
-
-      void TearDown() override
-      {}
-  };
-
-  TEST_F(SerializableJsonFloatFactoryTest, build)
-  {
-    std::shared_ptr<ls_std::Float> value = std::dynamic_pointer_cast<ls_std::Float>(ls_std::SerializableJsonFloatFactory{}.build());
-    ASSERT_TRUE(value != nullptr);
-    ASSERT_STREQ("Float", value->getClassName().c_str());
-  }
-}