ExternalEvent.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @file ExternalEvent.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_EXTERNAL_EVENT
  26. #define COMMON_EXTERNAL_EVENT 1
  27. #include <paradevs/common/Model.hpp>
  28. #include <paradevs/common/Node.hpp>
  29. #include <sstream>
  30. #include <string>
  31. #include <vector>
  32. namespace paradevs { namespace common {
  33. template < class Time, class SchedulerHandle >
  34. class Node;
  35. template < class Time, class SchedulerHandle >
  36. class Model;
  37. template < class Time, class SchedulerHandle >
  38. class ExternalEvent
  39. {
  40. public:
  41. ExternalEvent(const std::string& port_name, void* content) :
  42. _port_name(port_name), _model(0), _content(content)
  43. { }
  44. ExternalEvent(const Node < Time, SchedulerHandle >& node, void* content) :
  45. _port_name(node.get_port_name()),
  46. _model(node.get_model()),
  47. _content(content)
  48. { }
  49. ExternalEvent()
  50. { }
  51. virtual ~ExternalEvent()
  52. { }
  53. void* get_content() const
  54. { return _content; }
  55. const std::string& get_port_name() const
  56. { return _port_name; }
  57. void set_content(void* content)
  58. { _content = content; }
  59. Model < Time, SchedulerHandle >* get_model() const
  60. { return _model; }
  61. bool on_port(const std::string& port_name) const
  62. { return _port_name == port_name; }
  63. void set_model(Model < Time, SchedulerHandle >* model)
  64. { _model = model; }
  65. std::string to_string() const
  66. {
  67. std::ostringstream ss;
  68. ss << "( " << _port_name << " , " << (_model?_model->get_name():"<>")
  69. << " , " << *(double*)_content << ")";
  70. return ss.str();
  71. }
  72. private :
  73. std::string _port_name;
  74. Model < Time, SchedulerHandle >* _model;
  75. void* _content;
  76. };
  77. } } // namespace paradevs common
  78. #endif