State.cpp 1.8 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-09-20
  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->_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<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 StateConnectionId &_connectionId)
  46. {
  47. return this->_hasConnection(_connectionId);
  48. }
  49. void ls_std::State::setId(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 StateConnectionId &_connectionId)
  58. {
  59. return this->connectedStates.find(_connectionId) != this->connectedStates.end();
  60. }