RootCoordinator.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * @file RootCoordinator.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-2018 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 COMMON_ROOT_COORDINATOR
  26. #define COMMON_ROOT_COORDINATOR
  27. #include <artis-star/common/observer/Observer.hpp>
  28. #include <artis-star/common/observer/View.hpp>
  29. #include <artis-star/common/Parameters.hpp>
  30. #include <sstream>
  31. #include <string>
  32. namespace artis { namespace common {
  33. template < class Time, class Coordinator >
  34. class RootCoordinator
  35. {
  36. public :
  37. RootCoordinator(
  38. const typename Time::type& t_start,
  39. const typename Time::type& t_max,
  40. const std::string& root_name,
  41. const typename Coordinator::parameters_type& parameters,
  42. const typename Coordinator::graph_parameters_type& graph_parameters) :
  43. _root(root_name, parameters, graph_parameters), _observer(&_root),
  44. _t_max(t_max), _tn(t_start)
  45. { }
  46. RootCoordinator(const typename Time::type& t_start,
  47. const typename Time::type& t_max,
  48. const std::string& root_name,
  49. const typename Coordinator::parameters_type& parameters) :
  50. _root(root_name, parameters, NoParameters()), _observer(&_root),
  51. _t_max(t_max), _tn(t_start)
  52. { }
  53. RootCoordinator(const typename Time::type& t_start,
  54. const typename Time::type& t_max,
  55. const std::string& root_name) :
  56. _root(root_name, NoParameters(), NoParameters()), _observer(&_root),
  57. _t_max(t_max), _tn(t_start)
  58. { }
  59. virtual ~RootCoordinator()
  60. { }
  61. void attachView(const std::string& name, observer::View < Time >* view)
  62. { _observer.attachView(name, view); }
  63. const observer::Observer < Time >& observer() const
  64. { return _observer; }
  65. void run()
  66. {
  67. _observer.init();
  68. _tn = _root.start(_tn);
  69. while (_tn <= _t_max) {
  70. _root.output(_tn);
  71. _tn = _root.transition(_tn);
  72. _observer.observe(_tn);
  73. }
  74. }
  75. std::string to_string() const
  76. {
  77. std::ostringstream ss;
  78. ss << _root.to_string(0);
  79. return ss.str();
  80. }
  81. private :
  82. Coordinator _root;
  83. observer::Observer < Time > _observer;
  84. typename Time::type _t_max;
  85. typename Time::type _tn;
  86. };
  87. } } // namespace artis common
  88. #endif