Просмотр исходного кода

Reduce polymorphism of State class

- remove ISerializable extension
- adjust tests for State class
Patrick-Christopher Mattulat 3 лет назад
Родитель
Сommit
b1ceb4993e
3 измененных файлов с 4 добавлено и 126 удалено
  1. 2 10
      include/ls_std/logic/State.hpp
  2. 1 44
      source/ls_std/logic/State.cpp
  3. 1 72
      test/cases/logic/StateTest.cpp

+ 2 - 10
include/ls_std/logic/State.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-05
- * Changed:         2021-05-28
+ * Changed:         2021-07-14
  *
  * */
 
@@ -19,18 +19,13 @@
 
 namespace ls_std
 {
-  class State : public ls_std::Class, public ls_std::ISerializable
+  class State : public ls_std::Class
   {
     public:
 
       explicit State(const ls_std::StateId& _id);
       ~State() override = default;
 
-      // implementation
-
-      ls_std::byte_field marshal() override;
-      void unmarshal(const ls_std::byte_field &_data) override;
-
       // additional functionality
 
       bool addStateConnection(const ls_std::StateConnectionId &_connectionId, const std::shared_ptr<ls_std::State> &_connectedState);
@@ -40,15 +35,12 @@ namespace ls_std
       ls_std::StateId getId();
       bool hasConnection(const ls_std::StateConnectionId &_connectionId);
       void setId(const ls_std::StateId& _id);
-      void setSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable);
 
     private:
 
       std::unordered_map<ls_std::StateConnectionId, std::shared_ptr<ls_std::StateConnection>> connectedStates{};
       ls_std::StateId id{};
-      std::shared_ptr<ISerializable> serializable{};
 
-      void _assignSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable);
       void _assignStateId(const ls_std::StateId& _id);
       void _clearConnections();
       bool _hasConnection(const ls_std::StateConnectionId &_connectionId);

+ 1 - 44
source/ls_std/logic/State.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-05
- * Changed:         2021-05-28
+ * Changed:         2021-07-14
  *
  * */
 
@@ -16,34 +16,6 @@ ls_std::State::State(const ls_std::StateId& _id) : ls_std::Class("State")
   this->_assignStateId(_id);
 }
 
-ls_std::byte_field ls_std::State::marshal()
-{
-  ls_std::byte_field data{};
-
-  if (this->serializable != nullptr)
-  {
-    data = this->serializable->marshal();
-  }
-  else
-  {
-    throw ls_std::NullPointerException{};
-  }
-
-  return data;
-}
-
-void ls_std::State::unmarshal(const ls_std::byte_field &_data)
-{
-  if (this->serializable != nullptr)
-  {
-    this->serializable->unmarshal(_data);
-  }
-  else
-  {
-    throw ls_std::NullPointerException{};
-  }
-}
-
 bool ls_std::State::addStateConnection(const ls_std::StateConnectionId &_connectionId, const std::shared_ptr<ls_std::State> &_connectedState)
 {
   bool added{};
@@ -106,21 +78,6 @@ void ls_std::State::setId(const ls_std::StateId& _id)
   this->_assignStateId(_id);
 }
 
-void ls_std::State::setSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable)
-{
-  this->_assignSerializable(_serializable);
-}
-
-void ls_std::State::_assignSerializable(const std::shared_ptr<ls_std::ISerializable> &_serializable)
-{
-  if (_serializable == nullptr)
-  {
-    throw ls_std::IllegalArgumentException{};
-  }
-
-  this->serializable = _serializable;
-}
-
 void ls_std::State::_assignStateId(const ls_std::StateId &_id)
 {
   if (_id.empty())

+ 1 - 72
test/cases/logic/StateTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-05
- * Changed:         2021-05-28
+ * Changed:         2021-07-14
  *
  * */
 
@@ -47,61 +47,6 @@ namespace
                  }, ls_std::IllegalArgumentException);
   }
 
-  // implementation
-
-  TEST_F(StateTest, marshal)
-  {
-    std::shared_ptr<ls_std::State> state = std::make_shared<ls_std::State>("A");
-    std::shared_ptr<ls_std::ISerializable> serializable = std::make_shared<ls_std::SerializableJsonState>(state);
-    state->setSerializable(serializable);
-
-    ASSERT_FALSE(state->marshal().empty());
-  }
-
-  TEST_F(StateTest, marshal_no_serializable_reference)
-  {
-    ls_std::State state{"A"};
-
-    EXPECT_THROW({
-                   try
-                   {
-                     state.marshal();
-                   }
-                   catch (const ls_std::NullPointerException &_exception)
-                   {
-                     throw;
-                   }
-                 }, ls_std::NullPointerException);
-  }
-
-  TEST_F(StateTest, unmarshal)
-  {
-    std::shared_ptr<ls_std::State> state = std::make_shared<ls_std::State>("TMP_ID");
-    std::shared_ptr<ls_std::ISerializable> serializable = std::make_shared<ls_std::SerializableJsonState>(state);
-    state->setSerializable(serializable);
-    std::string jsonString = R"({"id":"A","connectedStates":{"AB":{"condition":false,"connectionId":"AB","stateId":"B"}}})";
-    state->unmarshal(jsonString);
-
-    ASSERT_STREQ("A", state->getId().c_str());
-  }
-
-  TEST_F(StateTest, unmarshal_no_serializable_reference)
-  {
-    std::shared_ptr<ls_std::State> state = std::make_shared<ls_std::State>("TMP_ID");
-    std::string jsonString = R"({"id":"A","connectedStates":{"AB":{"condition":false,"connectionId":"AB","stateId":"B"}}})";
-
-    EXPECT_THROW({
-                   try
-                   {
-                     state->unmarshal(jsonString);
-                   }
-                   catch (const ls_std::NullPointerException &_exception)
-                   {
-                     throw;
-                   }
-                 }, ls_std::NullPointerException);
-  }
-
   // additional functionality
 
   TEST_F(StateTest, addStateConnection_v1)
@@ -242,20 +187,4 @@ namespace
     ls_std::State stateA{"A"};
     ASSERT_FALSE(stateA.hasConnection("AB"));
   }
-
-  TEST_F(StateTest, setSerializable_no_reference)
-  {
-    ls_std::State state{"A"};
-
-    EXPECT_THROW({
-                   try
-                   {
-                     state.setSerializable(nullptr);
-                   }
-                   catch (const ls_std::IllegalArgumentException &_exception)
-                   {
-                     throw;
-                   }
-                 }, ls_std::IllegalArgumentException);
-  }
 }