|
- #include "dbcc/message.h"
-
- #include <iostream>
- #include <limits>
- #include <algorithm>
-
- namespace ad {
- namespace dbcc {
-
- std::istream &operator>>(std::istream &in, Message &msg)
- {
- std::string preamble;
- in >> preamble;
-
- // Check if we are actually reading a message otherwise fail the stream
- if (preamble != "BO_")
- {
- in.setstate(std::ios_base::failbit);
- return in;
- }
-
- // Parse the message ID.
- in >> msg.m_id;
-
- // Parse the name of the message
- std::string name;
- in >> name;
- msg.m_name = name.substr(0, name.length() - 1);
-
- // Parse the message length
- in >> msg.m_dlc;
-
- // Parse the sender
- in >> msg.m_from;
-
- in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
-
- // As long as there is a signal, parse the signal
- while (in)
- {
- Signal sig;
- in >> sig;
- if (in)
- {
- msg.appendSignal(sig);
- }
- }
-
- in.clear();
- return in;
- }
-
- std::set<std::string> Message::to() const
- {
- std::set<std::string> collection;
- for (auto sig : m_signals)
- {
- auto toList = sig.to();
- collection.insert(toList.begin(), toList.end());
- }
-
- return collection;
- }
-
- } // namespace dbcc
- } // namespace ad
|