RootCoordinator.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 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 <common/Parameters.hpp>
  28. #include <string>
  29. namespace paradevs { namespace common {
  30. template < class Time, class Coordinator >
  31. class RootCoordinator
  32. {
  33. public :
  34. RootCoordinator(const typename Time::type& t_start,
  35. const typename Time::type& t_max,
  36. const std::string& root_name,
  37. const typename Coordinator::parameters_type& parameters,
  38. const typename Coordinator::graph_parameters_type&
  39. graph_parameters) :
  40. _root(root_name, parameters, graph_parameters),
  41. _t_max(t_max), _tn(t_start)
  42. { }
  43. RootCoordinator(const typename Time::type& t_start,
  44. const typename Time::type& t_max,
  45. const std::string& root_name,
  46. const typename Coordinator::parameters_type& parameters) :
  47. _root(root_name, parameters, NoParameters()),
  48. _t_max(t_max), _tn(t_start)
  49. { }
  50. RootCoordinator(const typename Time::type& t_start,
  51. const typename Time::type& t_max,
  52. const std::string& root_name) :
  53. _root(root_name, NoParameters(), NoParameters()),
  54. _t_max(t_max), _tn(t_start)
  55. { }
  56. virtual ~RootCoordinator()
  57. { }
  58. void run()
  59. {
  60. _tn = _root.start(_tn);
  61. while (_tn <= _t_max) {
  62. _root.output(_tn);
  63. _tn = _root.transition(_tn);
  64. }
  65. }
  66. private :
  67. Coordinator _root;
  68. typename Time::type _t_max;
  69. typename Time::type _tn;
  70. };
  71. } } // namespace paradevs common
  72. #endif