State.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-05
  6. * Changed: 2020-09-10
  7. *
  8. * */
  9. #include "State.hpp"
  10. ls_std::State::State(ls_std::StateId _id) : Class("State"),
  11. id(std::move(_id))
  12. {}
  13. bool ls_std::State::addStateConnection(const StateConnectionId& _connectionId, const std::shared_ptr<State>& _connectedState)
  14. {
  15. bool added {};
  16. std::shared_ptr<ls_std::StateConnection> connection {};
  17. if(_connectedState != nullptr && !this->_stateIsConnected(_connectionId)) {
  18. connection = std::make_shared<ls_std::StateConnection>(_connectionId, _connectedState->getId());
  19. this->connectedStates.insert({_connectionId, connection});
  20. added = true;
  21. }
  22. return added;
  23. }
  24. std::unordered_map<ls_std::StateConnectionId, std::shared_ptr<ls_std::StateConnection>> ls_std::State::getConnectedStates()
  25. {
  26. return this->connectedStates;
  27. }
  28. ls_std::StateId ls_std::State::getId()
  29. {
  30. return this->id;
  31. }
  32. bool ls_std::State::_stateIsConnected(const std::string &_id)
  33. {
  34. return this->connectedStates.find(_id) != this->connectedStates.end();
  35. }