Model.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * @file kernel/sss/Model.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-2022 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 SSS_MODEL
  26. #define SSS_MODEL
  27. #include <artis-star/common/Model.hpp>
  28. namespace artis::sss {
  29. template<typename Time>
  30. class Model : public virtual common::Model<Time> {
  31. public:
  32. Model(const std::string &name)
  33. :
  34. common::Model<Time>(name) {
  35. assigned = 0;
  36. _mark = false;
  37. _send = false;
  38. }
  39. virtual ~Model() {}
  40. virtual void update_buffer(typename Time::type /* time */) = 0;
  41. void add_event(const common::event::ExternalEvent <Time> &message) {
  42. common::Model<Time>::add_event(message);
  43. std::map<std::string, bool>::iterator it =
  44. port_assigned.find(message.get_port_name());
  45. if (it != port_assigned.end() and not it->second) {
  46. port_assigned[message.get_port_name()] = true;
  47. ++assigned;
  48. }
  49. }
  50. void add_in_port(const std::string &port_name, bool sync) {
  51. common::Model<Time>::add_in_port(port_name);
  52. if (sync) {
  53. port_assigned[port_name] = false;
  54. }
  55. }
  56. bool all_ports_are_assigned() const { return assigned == port_assigned.size(); }
  57. void clear_bag() {
  58. common::Model<Time>::clear_bag();
  59. for (auto &p: port_assigned) {
  60. p.second = false;
  61. }
  62. assigned = 0;
  63. }
  64. bool is_marked() const { return _mark; }
  65. bool is_send() const { return _send; }
  66. void mark() { _mark = true; }
  67. void send() { _send = true; }
  68. void unmark() { _mark = false; }
  69. void unsend() { _send = false; }
  70. private:
  71. std::map<std::string, bool> port_assigned;
  72. unsigned int assigned;
  73. bool _mark;
  74. bool _send;
  75. };
  76. template<typename Time>
  77. class Models : public std::vector<sss::Model<Time> *> {
  78. public:
  79. Models() {}
  80. virtual ~Models() {}
  81. std::string to_string() const {
  82. std::ostringstream ss;
  83. ss << "{ ";
  84. for (typename Models<Time>::const_iterator it =
  85. Models<Time>::begin();
  86. it != Models<Time>::end(); ++it) {
  87. ss << (*it)->get_name() << " ";
  88. }
  89. ss << "}";
  90. return ss.str();
  91. }
  92. };
  93. } // namespace artis sss
  94. #endif