Policy.hpp 2.5 KB

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