Model.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @file Model.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 <common/Model.hpp>
  26. #include <sstream>
  27. namespace paradevs { namespace common {
  28. Model::Model(const std::string& name) :
  29. _tl(0), _tn(0), _parent(0), _name(name), _inputs(0)
  30. { }
  31. Model::~Model()
  32. {
  33. if (_inputs) {
  34. delete _inputs;
  35. }
  36. }
  37. void Model::add_event(const common::ExternalEvent& message)
  38. {
  39. if (_inputs == 0) {
  40. _inputs = new Bag;
  41. }
  42. _inputs->push_back(message);
  43. }
  44. const common::Bag& Model::get_bag() const
  45. { return *_inputs; }
  46. void Model::clear_bag()
  47. {
  48. if (_inputs) {
  49. delete _inputs;
  50. _inputs = 0;
  51. }
  52. }
  53. unsigned int Model::event_number() const
  54. {
  55. if (_inputs) {
  56. return _inputs->size();
  57. } else {
  58. return 0;
  59. }
  60. }
  61. std::string Models::to_string() const
  62. {
  63. std::ostringstream ss;
  64. ss << "{ ";
  65. for (const_iterator it = begin(); it != end(); ++it) {
  66. ss << (*it)->get_name() << " ";
  67. }
  68. ss << "}";
  69. return ss.str();
  70. }
  71. } } // namespace paradevs common