EventIterator.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @file common/observer/EventIterator.hpp
  3. * @author See the AUTHORS file
  4. */
  5. /*
  6. * Copyright (C) 2013-2022 ULCO http://www.univ-littoral.fr
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef ARTIS_COMMON_OBSERVER_EVENT_ITERATOR_HPP
  22. #define ARTIS_COMMON_OBSERVER_EVENT_ITERATOR_HPP
  23. #include <artis-star/common/observer/Iterator.hpp>
  24. namespace artis::common::observer {
  25. template<typename Time>
  26. struct EventIterator {
  27. typedef artis::common::observer::Iterator<Time> iterator_type;
  28. double begin(const std::vector <Iterator<Time>> &its) const { return next_time(0, its); }
  29. iterator_type build(const typename View<Time>::Values &view) const { return iterator_type(view); }
  30. bool is_valid(double time, const iterator_type &it) const { return (*it).first == time; }
  31. double next_time(double /* time */, const std::vector <Iterator<Time>> &its) const {
  32. double min = std::numeric_limits<double>::max();
  33. for (const auto &it: its) {
  34. if (min > (*it).first) {
  35. min = (*it).first;
  36. }
  37. }
  38. return min;
  39. }
  40. };
  41. }
  42. #endif