InternalEvent.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @file InternalEvent.hpp
  3. * @author The PARADEVS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * PARADEVS - the multimodeling and simulation environment
  8. * This file is a part of the PARADEVS environment
  9. *
  10. * Copyright (C) 2013-2015 ULCO http://www.univ-litoral.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 COMMON_INTERNAL_EVENT
  26. #define COMMON_INTERNAL_EVENT 1
  27. #include <paradevs/common/Model.hpp>
  28. #include <functional>
  29. namespace paradevs { namespace common {
  30. template < class Time, class SchedulerHandle >
  31. class Model;
  32. template < class Time, class SchedulerHandle >
  33. class InternalEvent
  34. {
  35. public:
  36. InternalEvent(const typename Time::type& time,
  37. Model < Time, SchedulerHandle >* model)
  38. : _time(time), _model(model)
  39. { }
  40. virtual ~InternalEvent()
  41. { }
  42. Model < Time, SchedulerHandle >* get_model() const
  43. { return _model; }
  44. typename Time::type get_time() const
  45. { return _time; }
  46. bool operator<(InternalEvent const &e) const
  47. {
  48. return _time < e._time;
  49. }
  50. bool operator>(InternalEvent const &e) const
  51. {
  52. return _time > e._time;
  53. }
  54. bool operator>=(InternalEvent const &e) const
  55. {
  56. return _time >= e._time;
  57. }
  58. bool operator==(InternalEvent const &e) const
  59. {
  60. return _time == e._time;
  61. }
  62. void set_time(typename Time::type time)
  63. { _time = time; }
  64. private:
  65. typename Time::type _time;
  66. Model < Time, SchedulerHandle >* _model;
  67. };
  68. template < typename Event >
  69. struct EventCompare
  70. : std::binary_function < Event, Event, bool >
  71. {
  72. bool operator()(const Event &left, const Event &right) const
  73. { return left >= right; }
  74. };
  75. } } // namespace paradevs common
  76. #endif