Преглед на файлове

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);