ExternalEvent.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 <boost/serialization/serialization.hpp>
  30. #include <sstream>
  31. #include <string>
  32. #include <vector>
  33. namespace paradevs { namespace common {
  34. template < class Time >
  35. class Node;
  36. template < class Time >
  37. class Model;
  38. template < class Time >
  39. class ExternalEvent
  40. {
  41. public:
  42. ExternalEvent(const std::string& port_name, void* content) :
  43. _port_name(port_name), _model(0), _content(content)
  44. { }
  45. ExternalEvent(const Node < Time >& node, void* content) :
  46. _port_name(node.get_port_name()),
  47. _model(node.get_model()),
  48. _content(content)
  49. { }
  50. ExternalEvent()
  51. { }
  52. virtual ~ExternalEvent()
  53. { }
  54. void* get_content() const
  55. { return _content; }
  56. const std::string& get_port_name() const
  57. { return _port_name; }
  58. void set_content(void* content)
  59. { _content = content; }
  60. Model < Time >* get_model() const
  61. { return _model; }
  62. bool on_port(const std::string& port_name) const
  63. { return _port_name == port_name; }
  64. void set_model(Model < Time >* model)
  65. { _model = model; }
  66. std::string to_string() const
  67. {
  68. std::ostringstream ss;
  69. ss << "( " << _port_name << " , "
  70. << (_model ? _model->get_name() : "<>")
  71. << " , ";
  72. if (_content) {
  73. ss << *(double*)_content;
  74. } else {
  75. ss << "null";
  76. }
  77. ss << ")";
  78. return ss.str();
  79. }
  80. private:
  81. friend class boost::serialization::access;
  82. template<class Archive>
  83. void serialize(Archive & ar, const unsigned int version)
  84. {
  85. (void) version;
  86. ar & _port_name;
  87. // ar & _model->get_name();
  88. }
  89. std::string _port_name;
  90. Model < Time >* _model;
  91. void* _content;
  92. };
  93. } } // namespace paradevs common
  94. #endif