ExternalEvent.hpp 2.4 KB

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