Model.hpp 3.1 KB

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