소스 검색

Extended State class

- added "clearConnections" method to remove all
connections
- extended tests for State class
Patrick-Laptop 3 년 전
부모
커밋
e4c1341ab4
3개의 변경된 파일27개의 추가작업 그리고 3개의 파일을 삭제
  1. 11 1
      source/logic/State.cpp
  2. 3 1
      source/logic/State.hpp
  3. 13 1
      test/cases/logic/StateTest.cpp

+ 11 - 1
source/logic/State.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-05
- * Changed:         2020-09-15
+ * Changed:         2020-09-20
  *
  * */
 
@@ -39,6 +39,11 @@ bool ls_std::State::addStateConnection(const std::shared_ptr<StateConnection>& _
   return added;
 }
 
+void ls_std::State::clearConnections()
+{
+  this->_clearConnections();
+}
+
 std::unordered_map<ls_std::StateConnectionId, std::shared_ptr<ls_std::StateConnection>> ls_std::State::getConnectedStates()
 {
   return this->connectedStates;
@@ -59,6 +64,11 @@ void ls_std::State::setId(StateId _id)
   this->id = std::move(_id);
 }
 
+void ls_std::State::_clearConnections()
+{
+  this->connectedStates.clear();
+}
+
 bool ls_std::State::_hasConnection(const StateConnectionId &_connectionId)
 {
   return this->connectedStates.find(_connectionId) != this->connectedStates.end();

+ 3 - 1
source/logic/State.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-05
- * Changed:         2020-09-15
+ * Changed:         2020-09-20
  *
  * */
 
@@ -25,6 +25,7 @@ namespace ls_std {
 
       bool addStateConnection(const StateConnectionId& _connectionId, const std::shared_ptr<State>& _connectedState);
       bool addStateConnection(const std::shared_ptr<StateConnection>& _connection);
+      void clearConnections();
       std::unordered_map<StateConnectionId, std::shared_ptr<StateConnection>> getConnectedStates();
       StateId getId();
       bool hasConnection(const StateConnectionId& _connectionId);
@@ -35,6 +36,7 @@ namespace ls_std {
       std::unordered_map<StateConnectionId, std::shared_ptr<StateConnection>> connectedStates {};
       StateId id {};
 
+      void _clearConnections();
       bool _hasConnection(const StateConnectionId& _connectionId);
   };
 }

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

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-05
- * Changed:         2020-09-15
+ * Changed:         2020-09-20
  *
  * */
 
@@ -54,6 +54,18 @@ namespace {
     ASSERT_FALSE(stateA.addStateConnection(nullptr));
   }
 
+  TEST_F(StateTest, clearConnections)
+  {
+    ls_std::State stateA {"A"};
+    stateA.addStateConnection(std::make_shared<ls_std::StateConnection>("AB", "B"));
+    stateA.addStateConnection(std::make_shared<ls_std::StateConnection>("AC", "C"));
+
+    ASSERT_EQ(2, stateA.getConnectedStates().size());
+    stateA.clearConnections();
+    ASSERT_EQ(0, stateA.getConnectedStates().size());
+    ASSERT_TRUE(stateA.getConnectedStates().empty());
+  }
+
   TEST_F(StateTest, getConnectedStates)
   {
     ls_std::State stateA {"A"};