소스 검색

Improved State class

- connectedStates field now holds reference of StateConnection instead of value
pcmattulat 3 년 전
부모
커밋
7699cf8996
2개의 변경된 파일6개의 추가작업 그리고 4개의 파일을 삭제
  1. 4 2
      source/logic/State.cpp
  2. 2 2
      source/logic/State.hpp

+ 4 - 2
source/logic/State.cpp

@@ -16,16 +16,18 @@ id(std::move(_id))
 bool ls_std::State::addStateConnection(const StateConnectionId& _connectionId, const std::shared_ptr<State>& _connectedState)
 {
   bool added {};
+  std::shared_ptr<ls_std::StateConnection> connection {};
 
   if(_connectedState != nullptr && !this->_stateIsConnected(_connectionId)) {
-    this->connectedStates.insert({_connectionId, ls_std::StateConnection {_connectionId, _connectedState->getId()}});
+    connection = std::make_shared<ls_std::StateConnection>(_connectionId, _connectedState->getId());
+    this->connectedStates.insert({_connectionId, connection});
     added = true;
   }
 
   return added;
 }
 
-std::unordered_map<ls_std::StateConnectionId, ls_std::StateConnection> ls_std::State::getConnectedStates()
+std::unordered_map<ls_std::StateConnectionId, std::shared_ptr<ls_std::StateConnection>> ls_std::State::getConnectedStates()
 {
   return this->connectedStates;
 }

+ 2 - 2
source/logic/State.hpp

@@ -24,12 +24,12 @@ namespace ls_std {
       ~State() = default;
 
       bool addStateConnection(const StateConnectionId& _connectionId, const std::shared_ptr<State>& _connectedState);
-      std::unordered_map<StateConnectionId, StateConnection> getConnectedStates();
+      std::unordered_map<StateConnectionId, std::shared_ptr<StateConnection>> getConnectedStates();
       StateId getId();
 
     private:
 
-      std::unordered_map<StateConnectionId, StateConnection> connectedStates {};
+      std::unordered_map<StateConnectionId, std::shared_ptr<StateConnection>> connectedStates {};
       StateId id {};
 
       bool _stateIsConnected(const StateId& _id);