You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dbc_iterator.cpp 1.9 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "dbcc/dbc_iterator.h"
  2. #include <limits>
  3. #include <fstream>
  4. namespace ad {
  5. namespace dbcc {
  6. DbcIterator::DbcIterator(const std::string &filePath)
  7. {
  8. std::ifstream file(filePath);
  9. if (file)
  10. {
  11. _parse(file);
  12. }
  13. file.close();
  14. }
  15. DbcIterator::DbcIterator(std::istream &stream)
  16. {
  17. _parse(stream);
  18. }
  19. std::ostream &operator<<(std::ostream &out, DbcIterator &dbc)
  20. {
  21. for (auto &msg : dbc)
  22. {
  23. out << msg.name() << " " << msg.id() << std::endl;
  24. for (auto &sig : msg)
  25. {
  26. out << "Signal: " << sig.name() << " [" << (sig.isFloat() ? "float" : "int") << "] ";
  27. out << "To: ";
  28. for (auto to : sig.to())
  29. {
  30. out << to << ", ";
  31. }
  32. out << sig.startBit() << "," << sig.length() << std::endl;
  33. out << "(" << sig.factor() << ", " << sig.offset() << ")" << std::endl;
  34. out << "[" << sig.minimum() << ", " << sig.maximum() << "]" << std::endl;
  35. if (sig.multiplexor() == Multiplexor::Multiplexed)
  36. {
  37. out << "#" << sig.multiplexedNumber() << "#" << std::endl;
  38. }
  39. else if (sig.multiplexor() == Multiplexor::Multiplexor)
  40. {
  41. out << "+Multiplexor+" << std::endl;
  42. }
  43. out << std::endl;
  44. }
  45. }
  46. return out;
  47. }
  48. void DbcIterator::_parse(std::istream &stream)
  49. {
  50. m_messages.clear();
  51. do {
  52. Message msg;
  53. stream >> msg;
  54. if (stream.fail())
  55. {
  56. stream.clear();
  57. stream.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  58. }
  59. else
  60. {
  61. m_messages.emplace_back(msg);
  62. m_messageIndex[msg.id()] = static_cast<uint32_t>(m_messages.size() - 1);
  63. }
  64. } while (!stream.eof());
  65. }
  66. } // namespace dbcc
  67. } // namespace ad