State.cpp 1.5 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-05
  7. *
  8. * */
  9. #include "State.hpp"
  10. ls_std::State::State(std::string _id) : Class("State"),
  11. id(std::move(_id))
  12. {}
  13. bool ls_std::State::addStateConnection(const std::shared_ptr<State>& _connectedState)
  14. {
  15. bool added {};
  16. if(_connectedState != nullptr && !this->_stateIsConnected(_connectedState->getId())) {
  17. this->connectedStates.emplace_back(_connectedState);
  18. added = true;
  19. }
  20. return added;
  21. }
  22. std::list<std::shared_ptr<ls_std::State>> ls_std::State::getConnectedStates()
  23. {
  24. return this->connectedStates;
  25. }
  26. std::string ls_std::State::getId()
  27. {
  28. return this->id;
  29. }
  30. bool ls_std::State::isAccessible() const
  31. {
  32. return this->accessCondition;
  33. }
  34. void ls_std::State::removeStateConnection(const std::string &_id)
  35. {
  36. auto iterator = this->connectedStates.begin();
  37. while(iterator != this->connectedStates.end()) {
  38. if(iterator->get()->getId() == _id) {
  39. this->connectedStates.erase(iterator);
  40. break;
  41. }
  42. iterator++;
  43. }
  44. }
  45. void ls_std::State::updateAccessCondition(bool _enteredCondition)
  46. {
  47. this->accessCondition = _enteredCondition;
  48. }
  49. bool ls_std::State::_stateIsConnected(const std::string &_id)
  50. {
  51. bool connected {};
  52. for(const std::shared_ptr<State>& state : this->connectedStates) {
  53. connected = state->getId() == _id;
  54. if(connected) {
  55. break;
  56. }
  57. }
  58. return connected;
  59. }