StateMachineDynamics.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @file pdevs/StateMachineDynamics.hpp
  3. * @author The ARTIS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * ARTIS - the multimodeling and simulation environment
  8. * This file is a part of the ARTIS environment
  9. *
  10. * Copyright (C) 2013-2023 ULCO http://www.univ-littoral.fr
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. #ifndef ARTIS_STAR_ADDONS_STATE_MACHINE_DYNAMICS_HPP
  26. #define ARTIS_STAR_ADDONS_STATE_MACHINE_DYNAMICS_HPP
  27. #include <artis-star/kernel/pdevs/Dynamics.hpp>
  28. namespace artis::addons::pdevs {
  29. template<class Time, class Model, class Parameters, class RootStateMachine>
  30. class StateMachineDynamics : public artis::pdevs::Dynamics<Time, Model, Parameters> {
  31. public:
  32. StateMachineDynamics(const std::string &name, const artis::pdevs::Context<Time, Model, Parameters> &context) :
  33. artis::pdevs::Dynamics<Time, Model, Parameters>(name, context), _root() {
  34. _root.build(context.parameters());
  35. }
  36. virtual ~StateMachineDynamics() = default;
  37. void
  38. dconf(const typename Time::type &t, const typename Time::type &e, const common::event::Bag <Time> &bag) override {
  39. dint(t);
  40. dext(t, e, bag);
  41. }
  42. void dint(const typename Time::type &t) override {
  43. _root.transition(t);
  44. }
  45. void dext(const typename Time::type & /* t */, const typename Time::type & /* e */,
  46. const common::event::Bag <Time> & /* bag*/) override {}
  47. void start(const typename Time::type &t) override {
  48. _root.start(t);
  49. }
  50. typename Time::type ta(const typename Time::type &t) const override {
  51. return _root.ta(t);
  52. }
  53. common::event::Bag <Time> lambda(const typename Time::type & /* t */) const override { return {}; }
  54. artis::common::event::Value
  55. observe(const typename Time::type & /* t */, unsigned int /* index */) const override { return {}; }
  56. protected:
  57. const RootStateMachine &root() const { return _root; }
  58. RootStateMachine &root() { return _root; }
  59. private:
  60. RootStateMachine _root;
  61. };
  62. }
  63. #endif //ARTIS_STAR_ADDONS_STATE_MACHINE_DYNAMICS_HPP