Message.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @file Message.cpp
  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. #include <devs/Message.hpp>
  26. #include <devs/Node.hpp>
  27. #include <cassert>
  28. #include <sstream>
  29. namespace paradevs {
  30. Message::Message(const std::string& port_name, double content) :
  31. _port_name(port_name), _model(0), _content(content)
  32. { }
  33. Message::Message(const std::string& port_name, Model* model, double content) :
  34. _port_name(port_name), _model(model), _content(content)
  35. { }
  36. Message::Message()
  37. { }
  38. Message::~Message()
  39. { }
  40. const std::string& Message::get_port_name() const
  41. { return _port_name; }
  42. double Message::get_content() const
  43. { return _content; }
  44. void Message::set_content(double content)
  45. { _content = content; }
  46. Model* Message::get_model() const
  47. { return _model; }
  48. void Message::set_model(Model* model)
  49. { _model = model; }
  50. std::string Message::to_string() const
  51. {
  52. std::ostringstream ss;
  53. ss << "( " << _port_name << " , " << _model->get_name() << ")";
  54. return ss.str();
  55. }
  56. std::string Messages::to_string() const
  57. {
  58. std::ostringstream ss;
  59. ss << "{ ";
  60. for (const_iterator it = begin(); it != end(); ++it) {
  61. ss << it->to_string() << " ";
  62. }
  63. ss << "}";
  64. return ss.str();
  65. }
  66. } // namespace paradevs