Policy.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * @file kernel/dtss/Coordinator.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-2022 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 DTSS_POLICY
  26. #define DTSS_POLICY
  27. #include "artis-star/common/event/Bag.hpp"
  28. #include <cassert>
  29. namespace artis::dtss {
  30. class Policy {
  31. public:
  32. Policy() = default;
  33. virtual ~Policy() = default;
  34. const common::event::Bag <common::DoubleTime> &bag() const { return _bag; }
  35. void clear() { _bag.clear(); }
  36. void push(const common::event::ExternalEvent <common::DoubleTime> &event) { _bag.push_back(event); }
  37. private:
  38. common::event::Bag <common::DoubleTime> _bag;
  39. };
  40. class AllEventsPolicy : public Policy {
  41. public:
  42. AllEventsPolicy() = default;
  43. virtual ~AllEventsPolicy() = default;
  44. virtual void operator()(
  45. typename common::DoubleTime::type /* t */,
  46. const common::event::ExternalEvent <common::DoubleTime> &event,
  47. typename common::DoubleTime::type /* tl */,
  48. typename common::DoubleTime::type /* tn */) {
  49. push(event);
  50. }
  51. };
  52. class LastBagPolicy : public Policy {
  53. public:
  54. LastBagPolicy() = default;
  55. virtual ~LastBagPolicy() = default;
  56. virtual void operator()(
  57. typename common::DoubleTime::type /* t */,
  58. const common::event::ExternalEvent <common::DoubleTime> &event,
  59. typename common::DoubleTime::type /* tl */,
  60. typename common::DoubleTime::type /* tn */) {
  61. clear();
  62. push(event);
  63. }
  64. };
  65. class IgnorePolicy : public Policy {
  66. public:
  67. IgnorePolicy() = default;
  68. virtual ~IgnorePolicy() = default;
  69. virtual void operator()(
  70. typename common::DoubleTime::type /* t */,
  71. const common::event::ExternalEvent <common::DoubleTime> & /* event */,
  72. typename common::DoubleTime::type /* tl */,
  73. typename common::DoubleTime::type /* tn */) {}
  74. };
  75. }
  76. #endif