State.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-05
  6. * Changed: 2021-04-23
  7. *
  8. * */
  9. #include <ls_std/logic/State.hpp>
  10. ls_std::State::State(ls_std::StateId _id)
  11. : ls_std::Class("State"),
  12. id(std::move(_id))
  13. {}
  14. bool ls_std::State::addStateConnection(const ls_std::StateConnectionId &_connectionId, const std::shared_ptr<ls_std::State> &_connectedState)
  15. {
  16. bool added{};
  17. std::shared_ptr<ls_std::StateConnection> connection{};
  18. if (_connectedState != nullptr && !this->_hasConnection(_connectionId))
  19. {
  20. connection = std::make_shared<ls_std::StateConnection>(_connectionId, _connectedState->getId());
  21. this->connectedStates.insert({_connectionId, connection});
  22. added = true;
  23. }
  24. return added;
  25. }
  26. bool ls_std::State::addStateConnection(const std::shared_ptr<ls_std::StateConnection> &_connection)
  27. {
  28. bool added{};
  29. if (_connection != nullptr)
  30. {
  31. this->connectedStates.insert({_connection->getConnectionId(), _connection});
  32. added = this->_hasConnection(_connection->getConnectionId());
  33. }
  34. return added;
  35. }
  36. void ls_std::State::clearConnections()
  37. {
  38. this->_clearConnections();
  39. }
  40. std::unordered_map<ls_std::StateConnectionId, std::shared_ptr<ls_std::StateConnection>> ls_std::State::getConnectedStates()
  41. {
  42. return this->connectedStates;
  43. }
  44. ls_std::StateId ls_std::State::getId()
  45. {
  46. return this->id;
  47. }
  48. bool ls_std::State::hasConnection(const ls_std::StateConnectionId &_connectionId)
  49. {
  50. return this->_hasConnection(_connectionId);
  51. }
  52. void ls_std::State::setId(ls_std::StateId _id)
  53. {
  54. this->id = std::move(_id);
  55. }
  56. void ls_std::State::_clearConnections()
  57. {
  58. this->connectedStates.clear();
  59. }
  60. bool ls_std::State::_hasConnection(const ls_std::StateConnectionId &_connectionId)
  61. {
  62. return this->connectedStates.find(_connectionId) != this->connectedStates.end();
  63. }