Coordinator.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * @file Coordinator.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_COORDINATOR
  26. #define COMMON_COORDINATOR
  27. #include <artis-star/common/Bag.hpp>
  28. #include <artis-star/common/ExternalEvent.hpp>
  29. #include <artis-star/common/Links.hpp>
  30. #include <artis-star/common/Model.hpp>
  31. #include <artis-star/common/Node.hpp>
  32. #include <sstream>
  33. namespace artis { namespace common {
  34. template < class Time >
  35. class Model;
  36. template < class Time >
  37. class GraphManager;
  38. template < class Time >
  39. class Coordinator : public virtual Model < Time >
  40. {
  41. public :
  42. Coordinator(const std::string& name) : Model < Time >(name)
  43. { }
  44. virtual ~Coordinator()
  45. { }
  46. virtual const GraphManager < Time >& get_graph_manager() const = 0;
  47. virtual const Model < Time >* get_submodel(unsigned int index) const
  48. {
  49. const GraphManager < Time >& graph_manager =
  50. get_graph_manager();
  51. typename common::ModelMap < Time >::const_iterator it =
  52. graph_manager.child_map().find(index);
  53. if (it != graph_manager.child_map().end()) {
  54. return it->second;
  55. } else {
  56. return nullptr;
  57. }
  58. }
  59. virtual const Model < Time >* get_submodel(unsigned int index,
  60. unsigned int rank) const
  61. {
  62. const GraphManager < Time >& graph_manager =
  63. get_graph_manager();
  64. typename common::ModelsMap < Time >::const_iterator it =
  65. graph_manager.children_map().find(index);
  66. if (it != graph_manager.children_map().end() and
  67. it->second.size() > rank) {
  68. return it->second.at(rank);
  69. } else {
  70. return nullptr;
  71. }
  72. }
  73. virtual unsigned int get_submodel_number(unsigned int index) const
  74. {
  75. const GraphManager < Time >& graph_manager =
  76. get_graph_manager();
  77. typename common::ModelsMap < Time >::const_iterator it =
  78. graph_manager.children_map().find(index);
  79. if (it != graph_manager.children_map().end()) {
  80. return it->second.size();
  81. } else {
  82. return 0;
  83. }
  84. }
  85. virtual bool is_atomic() const
  86. { return false; }
  87. virtual std::string to_string(int /* level */) const
  88. {
  89. std::ostringstream ss;
  90. ss << "Coordinator "
  91. << Coordinator < Time >::get_name();
  92. return ss.str();
  93. }
  94. // DEVS methods
  95. virtual common::Value observe(const typename Time::type& t,
  96. unsigned int index) const =0;
  97. virtual void output(const typename Time::type& t) =0;
  98. virtual void post_event(const typename Time::type& t,
  99. const common::ExternalEvent < Time >& event) =0;
  100. virtual typename Time::type dispatch_events(const common::Bag < Time >&
  101. bag,
  102. const typename Time::type& t) =0;
  103. virtual typename Time::type start(const typename Time::type& t) =0;
  104. virtual typename Time::type transition(const typename Time::type& t) =0;
  105. };
  106. } } // namespace artis common
  107. #endif