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.

message.cpp 1.3 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "dbcc/message.h"
  2. #include <iostream>
  3. #include <limits>
  4. #include <algorithm>
  5. namespace ad {
  6. namespace dbcc {
  7. std::istream &operator>>(std::istream &in, Message &msg)
  8. {
  9. std::string preamble;
  10. in >> preamble;
  11. // Check if we are actually reading a message otherwise fail the stream
  12. if (preamble != "BO_")
  13. {
  14. in.setstate(std::ios_base::failbit);
  15. return in;
  16. }
  17. // Parse the message ID.
  18. in >> msg.m_id;
  19. // Parse the name of the message
  20. std::string name;
  21. in >> name;
  22. msg.m_name = name.substr(0, name.length() - 1);
  23. // Parse the message length
  24. in >> msg.m_dlc;
  25. // Parse the sender
  26. in >> msg.m_from;
  27. in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  28. // As long as there is a signal, parse the signal
  29. while (in)
  30. {
  31. Signal sig;
  32. in >> sig;
  33. if (in)
  34. {
  35. msg.appendSignal(sig);
  36. }
  37. }
  38. in.clear();
  39. return in;
  40. }
  41. std::set<std::string> Message::to() const
  42. {
  43. std::set<std::string> collection;
  44. for (auto sig : m_signals)
  45. {
  46. auto toList = sig.to();
  47. collection.insert(toList.begin(), toList.end());
  48. }
  49. return collection;
  50. }
  51. } // namespace dbcc
  52. } // namespace ad