RootCoordinator.hpp 2.6 KB

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