State.cpp 1.9 KB

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