ExternalEvent.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * @file ExternalEvent.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_EXTERNAL_EVENT
  26. #define COMMON_EXTERNAL_EVENT 1
  27. #include <artis-star/common/Model.hpp>
  28. #include <artis-star/common/Node.hpp>
  29. #include <artis-star/common/Value.hpp>
  30. #include <boost/serialization/serialization.hpp>
  31. #include <boost/serialization/nvp.hpp>
  32. #include <sstream>
  33. #include <string>
  34. #include <vector>
  35. namespace artis { namespace common {
  36. template < class Time >
  37. class Node;
  38. template < class Time >
  39. class Model;
  40. template < class Time >
  41. class ExternalEvent
  42. {
  43. public:
  44. ExternalEvent(const std::string& port_name, const Value& data) :
  45. _port_name(port_name), _model(nullptr), _data(data)
  46. { }
  47. ExternalEvent(const Node < Time >& node, const Value& data) :
  48. _port_name(node.get_port_name()),
  49. _model(node.get_model()),
  50. _data(data)
  51. { }
  52. ExternalEvent(const ExternalEvent& event) :
  53. _port_name(event._port_name), _model(event._model),
  54. _data(event._data)
  55. { }
  56. ExternalEvent() : _model(nullptr)
  57. { }
  58. virtual ~ExternalEvent()
  59. { }
  60. const Value& data() const
  61. { return _data; }
  62. const std::string& get_port_name() const
  63. { return _port_name; }
  64. void data(const Value& data)
  65. { _data = data; }
  66. Model < Time >* get_model() const
  67. { return _model; }
  68. bool on_port(const std::string& port_name) const
  69. { return _port_name == port_name; }
  70. void set_model(Model < Time >* model)
  71. { _model = model; }
  72. std::string to_string() const
  73. {
  74. std::ostringstream ss;
  75. ss << "( " << _port_name << " , "
  76. << (_model ? _model->get_name() : "<>")
  77. << " , ";
  78. if (not _data.empty()) {
  79. ss << _data.to_string();
  80. } else {
  81. ss << "null";
  82. }
  83. ss << ")";
  84. return ss.str();
  85. }
  86. private:
  87. friend class boost::serialization::access;
  88. template<class Archive>
  89. void serialize(Archive & ar, const unsigned int version)
  90. {
  91. (void) version;
  92. ar & _port_name;
  93. _model = 0;
  94. // ar & _model;
  95. ar & _data;
  96. // ar & _model->get_name();
  97. }
  98. std::string _port_name;
  99. Model < Time >* _model;
  100. Value _data;
  101. };
  102. } } // namespace artis common
  103. #endif