Trace.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @file Trace.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/Trace.hpp>
  26. namespace paradevs { namespace common {
  27. Trace* Trace::_instance = 0;
  28. std::string TraceElements::to_string() const
  29. {
  30. std::ostringstream ss;
  31. for (const_iterator it = begin(); it != end(); ++it) {
  32. ss << "TRACE: " << it->get_model_name() << " at "
  33. << it->get_time() << " <";
  34. switch (it->get_type())
  35. {
  36. case NONE: ss << "none"; break;
  37. case I_MESSAGE: ss << "i_message"; break;
  38. case POST_MESSAGE: ss << "post_message"; break;
  39. case S_MESSAGE: ss << "s_message"; break;
  40. case Y_MESSAGE: ss << "y_message"; break;
  41. case DELTA_INT: ss << "delta_int"; break;
  42. case DELTA_EXT: ss << "delta_ext"; break;
  43. case DELTA_CONF: ss << "delta_conf"; break;
  44. case TA: ss << "ta"; break;
  45. case LAMBDA: ss << "lambda"; break;
  46. case START: ss << "start"; break;
  47. };
  48. ss << ">";
  49. if (not it->get_comment().empty()) {
  50. ss << " => " << it->get_comment();
  51. }
  52. ss << std::endl;
  53. }
  54. return ss.str();
  55. }
  56. void Trace::flush()
  57. {
  58. if (_sstream) {
  59. _element.set_comment(_sstream->str());
  60. delete _sstream;
  61. _sstream = 0;
  62. }
  63. _trace.push_back(_element);
  64. }
  65. std::ostringstream& Trace::sstream()
  66. {
  67. if (_sstream == 0) {
  68. _sstream = new std::ostringstream();
  69. }
  70. return *_sstream;
  71. }
  72. Trace& Trace::trace()
  73. {
  74. if (_instance == 0) {
  75. _instance = new Trace();
  76. }
  77. return *_instance;
  78. }
  79. } } // namespace paradevs common
  80. paradevs::common::Trace& operator<<(paradevs::common::Trace& trace,
  81. const paradevs::common::TraceElement& e)
  82. {
  83. trace.set_element(e);
  84. return trace;
  85. }
  86. paradevs::common::Trace& operator<<(paradevs::common::Trace& trace,
  87. const std::string& str)
  88. {
  89. trace.sstream() << str;
  90. return trace;
  91. }
  92. paradevs::common::Trace& operator<<(paradevs::common::Trace& trace,
  93. paradevs::common::Time t)
  94. {
  95. trace.sstream() << t;
  96. return trace;
  97. }